麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > PHP > 正文

php實(shí)現(xiàn)微信公眾號無限群發(fā)

2024-05-04 23:39:33
字體:
供稿:網(wǎng)友

本文給大家分享的是php實(shí)現(xiàn)的利用微信的客服接口進(jìn)行各類消息的無限群發(fā),思路非常巧妙,有需要的小伙伴可以參考下

利用微信客服接口進(jìn)行各類消息的無限群發(fā)

sendAllMsg.php

 

 
  1. ?<?php 
  2. /* 
  3. Author:yf 
  4. 使用說明:微信公眾號無限群發(fā)接口,使用實(shí)例:  
  5. $test = new SendAllMsg("你的appId","你的appSecret"); 
  6. $test->sendMsgToAll(); //調(diào)用群發(fā)方法 
  7. 注:1.使用條件:認(rèn)證號或測試號 
  8. 2.群發(fā)消息內(nèi)容可為圖文、文本、音樂等,$data具體內(nèi)容參照微信開發(fā)文檔/客服接口 
  9. 3.若用戶量過萬,需修改getUserInfo(),具體參照信開發(fā)文檔/獲取關(guān)注者列表 
  10.  
  11. 新手上路,大神們多多指點(diǎn),謝謝 
  12. */ 
  13. interface iSendAllMsg{ 
  14. function getData($url); //curl 發(fā)送get請求 
  15. function postData($url,$data); //curl 發(fā)送post請求 
  16. function getAccessToken(); //在構(gòu)造方法中已調(diào)用該方法來獲取access_token,注意它在wx服務(wù)器的保存時(shí)間7200s 
  17. function sendMsgToAll(); //群發(fā)消息方法,發(fā)送的消息$data 可自行修改 
  18. class SendAllMsg implements iSendAllMsg{ 
  19. private $appId;  
  20. private $appSecret; 
  21. private $access_token; 
  22. // 
  23. public function __construct($appId, $appSecret) { 
  24. $this->appId = $appId; 
  25. $this->appSecret = $appSecret; 
  26. $this->access_token = $this->getAccessToken(); 
  27. // 
  28. function getData($url){ 
  29. $ch = curl_init(); 
  30. curl_setopt($ch, CURLOPT_URL, $url); 
  31. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  32. curl_setopt($ch, CURLOPT_HEADER, 0); 
  33. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); 
  34. curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); 
  35. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
  36. $data = curl_exec($ch); 
  37. curl_close($ch); 
  38. return $data; 
  39. // 
  40. function postData($url,$data){ 
  41. $ch = curl_init(); 
  42. curl_setopt($ch, CURLOPT_URL, $url); 
  43. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
  44. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
  45. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
  46. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); 
  47. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
  48. curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 
  49. curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
  50. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
  51. $tmpInfo = curl_exec($ch); 
  52. if (curl_errno($ch)) { 
  53. return curl_error($ch); 
  54. curl_close($ch); 
  55. return $tmpInfo; 
  56. // 
  57. function getAccessToken(){ 
  58. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appId."&secret=".$this->appSecret; 
  59. $res = $this->getData($url); 
  60. $jres = json_decode($res,true); 
  61. $access_token = $jres['access_token']; 
  62. return $access_token; 
  63. // 
  64. private function getUserInfo(){ 
  65. $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$this->access_token; 
  66. $res = $this->getData($url); 
  67. $jres = json_decode($res,true); 
  68. //print_r($jres); 
  69. $userInfoList = $jres['data']['openid']; 
  70. return $userInfoList; 
  71. function sendMsgToAll(){ 
  72. $userInfoList = $this->getUserInfo(); 
  73. $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$this->access_token; 
  74. foreach($userInfoList as $val){ 
  75. $data = '{ 
  76. "touser":"'.$val.'"
  77. "msgtype":"text"
  78. "text"
  79. "content":"測試一下,抱歉打擾各位" 
  80. }'; 
  81. $this->postData($url,$data); 
  82. $test = new SendAllMsg("YOURappId","YOURappSecret"); 
  83. $test->sendMsgToall(); 
  84.  
  85. ?> 

以上就是本文的全部內(nèi)容了,希望大家能夠喜歡。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 禁漫天堂久久久久久久久久 | 久久精品亚洲国产奇米99 | 国产大片中文字幕在线观看 | 久久久婷婷一区二区三区不卡 | 色诱亚洲精品久久久久久 | 羞羞视频在线免费 | 久久蜜桃香蕉精品一区二区三区 | 一级做人爱c黑人影片 | 久久精品观看 | 在线观看va | 欧美一级精品片在线看 | 国产精品久久久久久久av三级 | 国产一级毛片国产 | 亚洲精品在线观看网站 | 久久精品亚洲一区 | 51国产偷自视频区视频小蝌蚪 | 成人啪啪18免费网站 | 一本一本久久a久久精品综合小说 | 国产成人在线观看网站 | 久久久国产一区二区三区 | 最新一区二区三区 | 欧美黄色一级片视频 | 欧美特一级片 | 视频一区国产精品 | 亚洲第一男人天堂 | 日本成人在线免费 | 国产亚洲美女精品久久久2020 | 国产一国产一级毛片视频 | 男人天堂免费 | 欧美黄色免费视频 | 黄色片网站免费在线观看 | 水多视频在线观看 | 看国产精品 | 在线播放视频一区二区 | 日本一级黄色毛片 | 日韩深夜视频 | 二区视频 | 鲁丝一区二区三区不属 | 羞羞色在线观看 | 亚洲一区二区三区高清 | av色在线观看 |