您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關利用php怎么實現一個微信公眾號無限群發功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
sendAllMsg.php
?<?php interface iSendAllMsg{ function getData($url); //curl 發送get請求 function postData($url,$data); //curl 發送post請求 function getAccessToken(); //在構造方法中已調用該方法來獲取access_token,注意它在wx服務器的保存時間7200s function sendMsgToAll(); //群發消息方法,發送的消息$data 可自行修改 } class SendAllMsg implements iSendAllMsg{ private $appId; private $appSecret; private $access_token; // public function __construct($appId, $appSecret) { $this->appId = $appId; $this->appSecret = $appSecret; $this->access_token = $this->getAccessToken(); } // function getData($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $data = curl_exec($ch); curl_close($ch); return $data; } // function postData($url,$data){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch); if (curl_errno($ch)) { return curl_error($ch); } curl_close($ch); return $tmpInfo; } // function getAccessToken(){ $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appId."&secret=".$this->appSecret; $res = $this->getData($url); $jres = json_decode($res,true); $access_token = $jres['access_token']; return $access_token; } // private function getUserInfo(){ $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$this->access_token; $res = $this->getData($url); $jres = json_decode($res,true); //print_r($jres); $userInfoList = $jres['data']['openid']; return $userInfoList; } function sendMsgToAll(){ $userInfoList = $this->getUserInfo(); $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$this->access_token; foreach($userInfoList as $val){ $data = '{ "touser":"'.$val.'", "msgtype":"text", "text": { "content":"測試一下,抱歉打擾各位" } }'; $this->postData($url,$data); } } } $test = new SendAllMsg("YOURappId","YOURappSecret"); $test->sendMsgToall(); ?>
看完上述內容,你們對利用php怎么實現一個微信公眾號無限群發功能有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。