澳门游戏平台大全 澳门游戏平台大全 php达成Wechat公众号Infiniti群发_php才干_脚本之家

php达成Wechat公众号Infiniti群发_php才干_脚本之家

以上就是本文的全部内容了,希望大家能够喜欢。

利用微信客服接口进行各类消息的无限群发

sendMsgToAll(); //调用群发方法 注:1.使用条件:认证号或测试号 2.群发消息内容可为图文、文本、音乐等,$data具体内容参照微信开发文档/客服接口 3.若用户量过万,需修改getUserInfo(),具体参照信开发文档/获取关注者列表 新手上路,大神们多多指点,谢谢 */ interface iSendAllMsg{ function getData; //curl 发送get请求 function postData; //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 { $this->appId = $appId; $this->appSecret = $appSecret; $this->access_token = $this->getAccessToken(); } // function getData{ $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; return $data; } // function postData{ $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; if  { return curl_error; } curl_close; return $tmpInfo; } // function getAccessToken(){ $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&app&secret=".$this->appSecret; $res = $this->getData; $jres = json_decode; $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; $jres = json_decode; //print_r; $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; } } } $test = new SendAllMsg("YOURappId","YOURappSecret"); $test->sendMsgToall(); ?>

sendAllMsg.php

标签:, , , ,

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图