正在显示
1 个修改的文件
包含
34 行增加
和
42 行删除
| @@ -94,54 +94,46 @@ class Index extends Api | @@ -94,54 +94,46 @@ class Index extends Api | ||
| 94 | * 公众号推送审核信息给经纪人 | 94 | * 公众号推送审核信息给经纪人 |
| 95 | */ | 95 | */ |
| 96 | public function senWxmsgToAgentUser($titdesc="", $remark="") | 96 | public function senWxmsgToAgentUser($titdesc="", $remark="") |
| 97 | - { | ||
| 98 | - | ||
| 99 | - $appid = 'wx58ceff4e93cfc523';//公众号的appid | ||
| 100 | - $secret = 'baf744d21875280a5e98611f66adaf91'; | 97 | + {$appId = 'wxb7dd0c03865a94e0'; |
| 98 | + $appSecret = '6af75a6fb8211da45631630e34769f82'; | ||
| 99 | + $openId = 'o5ABA4yWDTLRTf3LkBMMHoV7XOvQ'; | ||
| 100 | + $unionId = 'ojyUX6oNFoQMqoCd1JWtfwQs-CeA'; | ||
| 101 | // 获取token | 101 | // 获取token |
| 102 | $myurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret; | 102 | $myurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret; |
| 103 | $json_token = http_request($myurl); | 103 | $json_token = http_request($myurl); |
| 104 | $access_tokens = json_decode($json_token, true); | 104 | $access_tokens = json_decode($json_token, true); |
| 105 | - $token = $access_tokens['access_token']; | ||
| 106 | - $params = []; | ||
| 107 | - $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $token . "&openid=" . "o5ABA4yWDTLRTf3LkBMMHoV7XOvQ" . "&lang=zh_CN"; | ||
| 108 | - $userInfo = Http::sendRequest($url, $params, 'GET'); | ||
| 109 | - print_r($userInfo);return; | ||
| 110 | - //$url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=".$token; | ||
| 111 | - $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token; | ||
| 112 | - | ||
| 113 | - $data = [ | ||
| 114 | - "touser"=>"o5ABA4yWDTLRTf3LkBMMHoV7XOvQ", | ||
| 115 | - "appid"=>$appid,//公众号 | ||
| 116 | - //"template_id"=>"nVfy1Tz1EXQ3T2YcGkwgicAjrD0M3N1Ca-CHIJCwjQY",//模板id | ||
| 117 | - "template_id"=>"zQaLnhEOQxdGOKJlDUAfEoNY4NTmNWy9a9vYzkZjGn8",//模板id | ||
| 118 | - "url"=>"", | ||
| 119 | - "miniprogram"=>[ | ||
| 120 | - "appid"=>$appid,//小程序 | ||
| 121 | - //"pagepath"=>"/pagesIndex/house/billingDetails?type=3&house_user_id=" . $house_user_id . "&house_code_id=" . $house_code_id//pagesIndex/house/billingDetails 未收账单路径 index?foo=bar | ||
| 122 | - "pagepath"=>""//pagesIndex/house/billingDetails 未收账单路径 index?foo=bar | ||
| 123 | - ], | ||
| 124 | - "data"=>[ | ||
| 125 | - 'thing2' => array( | ||
| 126 | - 'value'=>"行程", | ||
| 127 | - 'color'=>'' | ||
| 128 | - ), | ||
| 129 | - 'time3'=>array( | ||
| 130 | - 'value'=>"2024-06-19", | ||
| 131 | - 'color'=>'' | ||
| 132 | - ), | 105 | + $accessToken = $access_tokens['access_token']; |
| 106 | +// 发送消息的接口地址 | ||
| 107 | + $sendMessageUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$accessToken}"; | ||
| 133 | 108 | ||
| 134 | - 'thing7'=>array( | ||
| 135 | - 'value'=>"出发地", | ||
| 136 | - 'color'=>'' | ||
| 137 | - ), | ||
| 138 | - 'phone_number5'=>array( | ||
| 139 | - 'value'=>"联系方式", | ||
| 140 | - 'color'=>'' | ||
| 141 | - ), | ||
| 142 | - ], | 109 | +// 构造要发送的消息数据 |
| 110 | + $data = [ | ||
| 111 | + 'touser' => $unionId, | ||
| 112 | + 'msgtype' => 'text', | ||
| 113 | + 'text' => [ | ||
| 114 | + 'content' => '你好,这是一个公众号消息' | ||
| 115 | + ] | ||
| 143 | ]; | 116 | ]; |
| 144 | - return $this->http_request($url,json_encode($data)); //发送请求 | 117 | + |
| 118 | +// 对数据进行JSON编码 | ||
| 119 | + $jsonData = json_encode($data, JSON_UNESCAPED_UNICODE); | ||
| 120 | + | ||
| 121 | +// 发送HTTP POST请求 | ||
| 122 | + $ch = curl_init(); | ||
| 123 | + curl_setopt($ch, CURLOPT_URL, $sendMessageUrl); | ||
| 124 | + curl_setopt($ch, CURLOPT_POST, true); | ||
| 125 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); | ||
| 126 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
| 127 | + $response = curl_exec($ch); | ||
| 128 | + curl_close($ch); | ||
| 129 | + | ||
| 130 | +// 处理响应结果 | ||
| 131 | + $result = json_decode($response, true); | ||
| 132 | + if ($result['errcode'] == 0) { | ||
| 133 | + echo "消息发送成功"; | ||
| 134 | + } else { | ||
| 135 | + echo "消息发送失败,错误代码:{$result['errcode']},错误信息:{$result['errmsg']}"; | ||
| 136 | + } | ||
| 145 | } | 137 | } |
| 146 | function http_request($url, $data = array()) | 138 | function http_request($url, $data = array()) |
| 147 | { | 139 | { |
-
请 注册 或 登录 后发表评论