先把源码类发出来

  1. <?php
  2. /**
  3. 自己封装 微信 开发api
  4. */
  5. header('Content-type: text/html; charset=utf-8');#设置头信息
  6. class zhphpWeixinApi{
  7. //定义属性
  8. private $userPostData; #微信反馈给平台的数据集
  9. private $fromUserName; #发微信用户姓名
  10. private $toUserName; #接受微信用户姓名
  11. private $keyword; #接受用户发的微信信息
  12. private $createTime; #创建时间
  13. private $requestId;#获取接收消息编号
  14. private $msgType; #用户发的微信的类型
  15.  
  16. public $token; #api token
  17. private $appid;#开发者 id
  18. private $appSecret;# 开发者的应用密钥
  19.  
  20. private $access_token;#微信平台返回的access_token
  21. private $expires_in=0;#权限的期限
  22.  
  23. public $weixinConfig=array();#微信全局配置
  24. public $debug=false;
  25. private $saveFilePath; //缓存文件保存路径
  26.  
  27. public $oauthAccessToken; ##第三方网页授权accecctoken
  28. public $oauthOpenId;##授权后的用户id
  29.  
  30. /**
  31. $wx_msgType为数组,可以依据账号的权限补充
  32. */
  33. private $wx_msgType=array(
  34. 'text',#文本消息内容类型
  35. 'image',#图片消息内容类型
  36. 'voice',#语音消息内容类型
  37. 'video',#视频消息内容类型
  38. 'link',#链接消息内容类型
  39. 'location',#本地地理位置消息内容类型
  40. 'event',#事件消息内容类型
  41. 'subscribe',#是否为普通关注事件
  42. 'unsubscribe',#是否为取消关注事件
  43. 'music',#音乐消息内容类型
  44. 'news',#新闻消息内容
  45. );
  46.  
  47. /**
  48. 配置文件
  49. $config=array(
  50. 'token'=>'',
  51. 'appid'=>'开发者 id ',
  52. 'appSecret'=>'应用密钥'
  53. )
  54. */
  55. public function setConfig($config){
  56. if( ! empty( $config ) ){
  57. $this->weixinConfig=$config;
  58. }elseif( empty($config) && ! empty($this->weixinConfig) ){
  59. $config=$this->weixinConfig;
  60. }
  61. #配置参数属性,这里使用 isset进行了判断,目的是为后续程序判断提供数据
  62. $this->token=isset($config['token'])?$config['token']:null;
  63. $this->appid=isset($config['appid'])?$config['appid']:null;
  64. $this->appSecret=isset($config['appSecret'])?$config['appSecret']:null;
  65. }
  66. /**
  67. 获取config
  68. */
  69. public function getConfig(){
  70. return $this->weixinConfig;
  71. }
  72. /**
  73. 检验 token
  74. */
  75. public function validToken(){
  76. if(empty($this->token)){ //如果 不存在 token 就抛出异常
  77. return false;
  78. }else{
  79. if($this->checkSignature()){//检查签名,签名通过之后,就需要处理用户请求的数据
  80. return true;
  81. }else{
  82. return false;
  83. }
  84. }
  85. }
  86. /**
  87. 检查签名
  88. */
  89. private function checkSignature(){
  90. try{ # try{.....}catch{.....} 捕捉语句异常
  91. $signature = isset($_GET["signature"])?$_GET["signature"]:null;//判断腾讯微信返回的参数 是否存在
  92. $timestamp = isset($_GET["timestamp"])?$_GET["timestamp"]:null;//如果存在 就返回 否则 就 返回 null
  93. $nonce = isset($_GET["nonce"])?$_GET["nonce"]:null;
  94. ######下面的代码是--微信官方提供代码
  95. $tmpArr = array($this->token, $timestamp, $nonce);
  96. sort($tmpArr, SORT_STRING);
  97. $tmpStr = implode( $tmpArr );
  98. $tmpStr = sha1( $tmpStr );
  99. if( $tmpStr == $signature ){
  100. return true;
  101. }else{
  102. return false;
  103. }
  104. ######上面的代码是--微信官方提供代码
  105. }catch(Exception $e){
  106. echo $e->getMessage();
  107. exit();
  108. }
  109. }
  110. /**
  111. 处理用户的请求
  112. */
  113. private function handleUserRequest(){
  114. if(isset($_GET['echostr'])){ //腾讯微信官方返回的字符串 如果是存在 echostr 变量 就表明 是微信的返回 我们直接输出就可以了
  115. $echoStr = $_GET["echostr"];
  116. echo $echoStr;
  117. exit;
  118. }else{//否则 就是用户自己回复 的
  119. $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];//用户所有的回复,腾讯微信都是放在这个变量的
  120. if (!empty($postStr)){
  121. libxml_disable_entity_loader(true); //由于微信返回的数据 都是以xml 的格式,所以需要将xml 格式数据转换成 对象操作
  122. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  123. $this->fromUserName=$postObj->FromUserName; //得到发送者 姓名 一般为微信人的账号
  124. $this->toUserName=$postObj->ToUserName;//得到 接受者的 姓名 获取请求中的收信人OpenId,一般为公众账号自身
  125. $this->msgType=trim($postObj->MsgType); //得到 用户发的数据的类型
  126. $this->keyword=addslashes(trim($postObj->Content));//得到 发送者 发送的内容
  127. $this->createTime=date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']);//当前的时间,我们这里是服务器的时间
  128. $this->requestId=$postObj->MsgId;//MsgId 获取接收消息编号
  129. $this->userPostData=$postObj;
  130. //$this->responseMessage('text','返回:'.$this->msgType);
  131. }
  132. }
  133. }
  134. /**
  135. 获取用户的数据对象集
  136. */
  137. public function getUserPostData(){
  138. return $this->userPostData;
  139. }
  140. /**
  141. 检查类型 方法
  142. 依据不同的数据类型调用不同的模板
  143. 判断一下 微信反馈回来的数据类型 是否存在于 wx_msgType 数组中
  144. */
  145. private function isWeixinMsgType(){
  146. if(in_array($this->msgType,$this->wx_msgType)){
  147. return true;
  148. }else{
  149. return false;
  150. }
  151. }
  152.  
  153. /**
  154. 文本会话
  155. */
  156. private function textMessage($callData){
  157. if(is_null($callData)){
  158. return 'null';
  159. }
  160. $textTpl = "<xml>
  161. <ToUserName><![CDATA[%s]]></ToUserName>
  162. <FromUserName><![CDATA[%s]]></FromUserName>
  163. <CreateTime>%s</CreateTime>
  164. <MsgType><![CDATA[%s]]></MsgType>
  165. <Content><![CDATA[%s]]></Content>
  166. <FuncFlag>5</FuncFlag>
  167. </xml>";
  168. if(is_string($callData)){
  169. $resultStr = sprintf($textTpl,$this->fromUserName,$this->toUserName,$this->createTime,'text',$callData);
  170. }else if(is_array($callData)){
  171. $content='';
  172. foreach($callData as $key => $value){
  173. $content.=$value;
  174. }
  175. $resultStr= sprintf($textTpl,$this->fromUserName,$this->toUserName,$this->createTime,'text',$content);
  176. }
  177. return $resultStr;
  178. }
  179. /**
  180. 图片会话
  181. */
  182. private function imageMessage($callData){
  183. if(is_null($callData)){
  184. return 'null';
  185. }
  186. $textTpl = "<xml>
  187. <ToUserName><![CDATA[%s]]></ToUserName>
  188. <FromUserName><![CDATA[%s]]></FromUserName>
  189. <CreateTime>%s</CreateTime>
  190. <MsgType><![CDATA[%s]]></MsgType>
  191. <Image>
  192. <MediaId><![CDATA[%s]]></MediaId>
  193. </Image>
  194. </xml>";
  195. $resultStr = sprintf($textTpl,$this->fromUserName,$this->toUserName,$this->createTime,'image', $callData);
  196. return $resultStr;
  197. }
  198. /**
  199. 语音会话
  200. */
  201. private function voiceMessage($callData){
  202. if(is_null($callData)){
  203. return 'null';
  204. }
  205. $textTpl = "<xml>
  206. <ToUserName><![CDATA[%s]]></ToUserName>
  207. <FromUserName><![CDATA[%s]]></FromUserName>
  208. <CreateTime>%s</CreateTime>
  209. <MsgType><![CDATA[%s]]></MsgType>
  210. <Voice>
  211. <MediaId><![CDATA[%s]]></MediaId>
  212. </Voice>
  213. </xml>";
  214. $resultStr = sprintf($textTpl,$this->fromUserName,$this->toUserName,$this->createTime,'voice',$callData['MediaId']);
  215. return $resultStr;
  216. }
  217. /**
  218. 视频会话
  219. */
  220. private function videoMessage($callData){
  221. if(is_null($callData)){
  222. return 'null';
  223. }
  224. $textTpl = "<xml>
  225. <ToUserName><![CDATA[%s]]></ToUserName>
  226. <FromUserName><![CDATA[%s]]></FromUserName>
  227. <CreateTime>%s</CreateTime>
  228. <MsgType><![CDATA[%s]]></MsgType>
  229. <Video>
  230. <MediaId><![CDATA[%s]]></MediaId>
  231. <ThumbMediaId><![CDATA[%s]]></ThumbMediaId>
  232. <Title><![CDATA[%s]]></Title>
  233. <Description><![CDATA[%s]]></Description>
  234. </Video>
  235. </xml>";
  236. $resultStr = sprintf($textTpl,$this->fromUserName,$this->toUserName,$this->createTime,'video',$callData['MediaId'],$callData['ThumbMediaId'],$callData['Title'],$callData['Description']);
  237. return $resultStr;
  238. }
  239. /**
  240. 音乐会话
  241. */
  242. private function musicMessage($callData){ //依据文本 直接调用
  243. if(is_null($callData)){
  244. return 'null';
  245. }
  246. $textTpl = '<xml>
  247. <ToUserName><![CDATA[%s]]></ToUserName>
  248. <FromUserName><![CDATA[%s]]></FromUserName>
  249. <CreateTime>%s</CreateTime>
  250. <MsgType><![CDATA[%s]]></MsgType>
  251. <Music>
  252. <Title><![CDATA[%s]]></Title>
  253. <Description><![CDATA[%s]]></Description>
  254. <MusicUrl><![CDATA[%s]]></MusicUrl>
  255. <HQMusicUrl><![CDATA[%s]]></HQMusicUrl>
  256. </Music>
  257. </xml>';
  258. $resultStr = sprintf($textTpl,$this->fromUserName,$this->toUserName,$this->createTime,'music',$callData['Title'],$callData['Description'],$callData['MusicUrl'],$callData['HQMusicUrl']);
  259. return $resultStr;
  260. }
  261. /**
  262. 回复图文消息
  263. $items 必须是数组 必须是二维数组
  264. $items=array(
  265. array('Title'=>'','Description'=>'','PicUrl'=>'','Url'=>'')
  266.  
  267. )
  268. */
  269. private function newsMessage($items){
  270. if(is_null($items)){
  271. return 'null';
  272. }
  273. //##公共部分 图文公共部分
  274. $textTpl = '<xml>
  275. <ToUserName><![CDATA[%s]]></ToUserName>
  276. <FromUserName><![CDATA[%s]]></FromUserName>
  277. <CreateTime>%s</CreateTime>
  278. <MsgType><![CDATA[%s]]></MsgType>
  279. <ArticleCount>%d</ArticleCount>
  280. <Articles>%s</Articles>
  281. </xml>';
  282. //##新闻列表部分模板
  283. $itemTpl = '<item>
  284. <Title><![CDATA[%s]]></Title>
  285. <Description><![CDATA[%s]]></Description>
  286. <PicUrl><![CDATA[%s]]></PicUrl>
  287. <Url><![CDATA[%s]]></Url>
  288. </item>';
  289. $articles = '';
  290. $count=0;
  291. if(is_array($items)){
  292. $level=$this->arrayLevel($items);//判断数组的维度
  293. if($level == 1){ //是一维数组的情况下
  294. $articles= sprintf($itemTpl, $items['Title'], $items['Description'], $items['PicUrl'], $items['Url']);
  295. $count=1;
  296. }else{
  297. foreach($items as $key=>$item){
  298. if(is_array($item)){
  299. $articles.= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);
  300. }
  301. }
  302. }
  303. $count=count($items);
  304. }
  305. $resultStr = sprintf($textTpl,$this->fromUserName,$this->toUserName,$this->createTime,'news',$count, $articles);
  306. return $resultStr;
  307. }
  308.  
  309. /**
  310. debug调试
  311. */
  312. public function debug($data){
  313. echo '<pre>';
  314. print_r($data);
  315. echo '</pre>';
  316. }
  317. /**
  318. 得到数组的维度
  319. */
  320. private function arrayLevel($vDim){
  321. if(!is_array($vDim)){
  322. return 0;
  323. }else{
  324. $max1 = 0;
  325. foreach($vDim as $item1){
  326. $t1 = $this->arrayLevel($item1);
  327. if( $t1 > $max1) {
  328. $max1 = $t1;
  329. }
  330. }
  331. return $max1 + 1;
  332. }
  333. }
  334.  
  335. /**
  336. 订阅号需要初始化
  337. */
  338. public function weixinBaseApiMessage($args=array()){
  339. $this->setConfig($args);
  340. //检查配置文件
  341. if(empty($this->weixinConfig)){
  342. return false;
  343. }
  344. $this->handleUserRequest(); //处理用户 请求
  345. return true;
  346. }
  347. public function weixinHighApiMessage($args=array()){
  348. $this->setConfig($args);
  349. //检查配置文件
  350. if(empty($this->weixinConfig)){
  351. return false;
  352. }
  353. return true;
  354.  
  355. }
  356. /**
  357. 通过同的类型调用不同的微信模板
  358. 回复微信内容信息
  359. $wxmsgType 参数是 数据类型 微信规定的类型
  360. $callData 参数是 数据库查询出来的数据或者指定数据
  361. 小机器人 被动回复
  362. */
  363. public function responseMessage($wxmsgType,$callData=''){
  364. // if($this->isWeixinMsgType()){
  365. $method=$wxmsgType.'Message';//类型方法组装
  366. $CallResultData=$this->$method($callData);//把程序的数据传递给模板,并返回数据格式
  367. if (!headers_sent()){//判断是否有发送过头信息,如果没有就发送,并输出内容
  368. header('Content-Type: application/xml; charset=utf-8');
  369. echo $CallResultData;
  370. exit;
  371. }
  372. //}
  373. }
  374. /**
  375. 事件消息内容类型
  376. */
  377. public function responseEventMessage($message=''){
  378. $content = "";
  379. $event=$this->userPostData->Event;
  380. if($event == 'subscribe'){
  381. return $content = $message;
  382. }elseif($event == 'unsubscribe'){
  383. return $content = "取消关注";
  384. }elseif($event == 'scan' || $event=='SCAN'){
  385. return $this->getUserEventScanRequest();
  386. }elseif($event == 'click' || $event == 'CLICK'){
  387. switch ($this->userPostData->EventKey)
  388. {
  389. case "company":
  390. $content =$message.'为你提供服务!';
  391. break;
  392. default:
  393. $content =$this->getUsertEventClickRequest();//返回点击的字符串
  394. break;
  395. }
  396. return $content;
  397. }elseif($event == 'location' || $event=='LOCATION'){
  398. return $this->getUserLocationRequest();//本地地理位置分享后 返回x 、y坐标,并返回经度和维度
  399. }elseif($event == 'view' || $event == 'VIEW'){
  400. return $this->userPostData->EventKey; //返回跳转的链接
  401. }elseif($event == 'masssendjobfinish' || $event == 'MASSSENDJOBFINISH'){
  402. return $this->getUserMessageInfo();//返回会话的所有信息
  403. }else{
  404. return "receive a new event: ".$$this->userPostData->Event;
  405. }
  406. return false;
  407. }
  408.  
  409. /**
  410. 获取微信端 返回的数据类型
  411. */
  412. public function getUserMsgType(){
  413. return strval($this->msgType);
  414. }
  415.  
  416. /**
  417. 获取用户发送信息的时间
  418. */
  419. public function getUserSendTime(){
  420. return $this->createTime;
  421. }
  422. /**
  423. 获取用户的微信id
  424. */
  425. public function getUserWxId(){
  426. return strval($this->fromUserName);
  427. }
  428. /**
  429. 获取到平台的微信id
  430. */
  431. public function getPlatformId(){
  432. return strval($this->toUserName);
  433. }
  434. /**
  435. 获取用户在客户端返回的数据,文本数据
  436. */
  437. public function getUserTextRequest(){
  438. return empty($this->keyword)?null:strval($this->keyword);
  439. }
  440. /**
  441. 获取接收消息编号,微信平台接收的第几条信息
  442. */
  443. public function getUserRequestId(){
  444. return strval($this->requestId);
  445. }
  446. /**
  447. 获取图片信息的内容
  448. */
  449. public function getUserImageRequest(){
  450. $image = array();
  451. $image['PicUrl'] = strval($this->userPostData->PicUrl);//图片url地址
  452. $image['MediaId'] = strval($this->userPostData->MediaId);//图片在微信公众平台下的id号
  453. return $image;
  454. }
  455. /**
  456. 获取语音信息的内容
  457. */
  458. public function getUserVoiceRequest(){
  459. $voice = array();
  460. $voice['MediaId'] = $this->userPostData->MediaId;//语音ID
  461. $voice['Format'] = $this->userPostData->Format;//语音格式
  462. $voice['MsgId']=$this->userPostData->MsgId;//id
  463. if (isset($this->userPostData->Recognition) && !empty($this->userPostData->Recognition)){
  464. $voice['Recognition'] = $this->userPostData->Recognition;//语音的内容;;你刚才说的是: xxxxxxxx
  465. }
  466. return $voice;
  467. }
  468. /**
  469. 获取视频信息的内容
  470. */
  471. public function getUserVideoRequest(){
  472. $video = array();
  473. $video['MediaId'] =$this->userPostData->MediaId;
  474. $video['ThumbMediaId'] = $this->userPostData->ThumbMediaId;
  475. return $video;
  476. }
  477. /**
  478. 获取音乐消息内容
  479. */
  480. public function getUserMusicRequest(){
  481. $music=array();
  482. $music['Title'] =$this->userPostData->Title;//标题
  483. $music['Description']=$this->userPostData->Description;//简介
  484. $music['MusicUrl']=$this->userPostData->MusicUrl;//音乐地址
  485. $music['HQMusicUrl']=$this->userPostData->HQMusicUrl;//高品质音乐地址
  486. return $music;
  487. }
  488.  
  489. /**
  490. 获取本地地理位置信息内容
  491. */
  492. public function getUserLocationRequest(){
  493. $location = array();
  494. $location['Location_X'] = strval($this->userPostData->Location_X);//本地地理位置 x坐标
  495. $location['Location_Y'] = strval($this->userPostData->Location_Y);//本地地理位置 Y 坐标
  496. $location['Scale'] = strval($this->userPostData->Scale);//缩放级别为
  497. $location['Label'] = strval($this->userPostData->Label);//位置为
  498. $location['Latitude']=$this->userPostData->Latitude;//维度
  499. $location['Longitude']=$this->userPostData->Longitude;//经度
  500. return $location;
  501. }
  502. /**
  503. 获取链接信息的内容
  504. */
  505. public function getUserLinkRequest(){ //数据以文本方式返回 在程序调用端 调用 text格式输出
  506. $link = array();
  507. $link['Title'] = strval($this->userPostData->Title);//标题
  508. $link['Description'] = strval($this->userPostData->Description);//简介
  509. $link['Url'] = strval($this->userPostData->Url);//链接地址
  510. return $link;
  511. }
  512. /**
  513. 二维码扫描事件内容
  514. */
  515. public function getUserEventScanRequest(){
  516. $info = array();
  517. $info['EventKey'] = $this->userPostData->EventKey;
  518. $info['Ticket'] = $this->userPostData->Ticket;
  519. $info['Scene_Id'] = str_replace('qrscene_', '', $this->userPostData->EventKey);
  520. return $info;
  521. }
  522. /**
  523. 上报地理位置事件内容
  524. */
  525. public function getUserEventLocationRequest(){
  526. $location = array();
  527. $location['Latitude'] = $this->userPostData->Latitude;
  528. $location['Longitude'] =$this->userPostData->Longitude;
  529. return $location;
  530. }
  531. /**
  532. 获取菜单点击事件内容
  533. */
  534. public function getUsertEventClickRequest(){
  535. return strval($this->userPostData->EventKey);
  536. }
  537. /**
  538. 获取微信会话状态info
  539. */
  540. public function getUserMessageInfo(){
  541. $info=array();
  542. $info['MsgID']=$this->userPostData->MsgID;//消息id
  543. $info['Status']=$this->userPostData->Status;//消息结果状态
  544. $info['TotalCount']=$this->userPostData->TotalCount;//平台的粉丝数量
  545. $info['FilterCount']=$this->userPostData->FilterCount;//过滤
  546. $info['SentCount']=$this->userPostData->SentCount;//发送成功信息
  547. $info['ErrorCount']=$this->userPostData->ErrorCount;//发送错误信息
  548. return $info;
  549. }
  550. /**
  551. 向第三方请求数据,并返回结果
  552. */
  553. public function relayPart3($url, $rawData){
  554. $headers = array("Content-Type: text/xml; charset=utf-8");
  555. $ch = curl_init();
  556. curl_setopt($ch, CURLOPT_URL, $url);
  557. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  558. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  559. curl_setopt($ch, CURLOPT_POST, 1);
  560. curl_setopt($ch, CURLOPT_POSTFIELDS, $rawData);
  561. $output = curl_exec($ch);
  562. curl_close($ch);
  563. return $output;
  564. }
  565. /**
  566. 字节转Emoji表情
  567. "中国:".$this->bytes_to_emoji(0x1F1E8).$this->bytes_to_emoji(0x1F1F3)."\n仙人掌:".$this->bytes_to_emoji(0x1F335);
  568. */
  569. public function bytes_to_emoji($cp){
  570. if ($cp > 0x10000){ # 4 bytes
  571. return chr(0xF0 | (($cp & 0x1C0000) >> 18)).chr(0x80 | (($cp & 0x3F000) >> 12)).chr(0x80 | (($cp & 0xFC0) >> 6)).chr(0x80 | ($cp & 0x3F));
  572. }else if ($cp > 0x800){ # 3 bytes
  573. return chr(0xE0 | (($cp & 0xF000) >> 12)).chr(0x80 | (($cp & 0xFC0) >> 6)).chr(0x80 | ($cp & 0x3F));
  574. }else if ($cp > 0x80){ # 2 bytes
  575. return chr(0xC0 | (($cp & 0x7C0) >> 6)).chr(0x80 | ($cp & 0x3F));
  576. }else{ # 1 byte
  577. return chr($cp);
  578. }
  579. }
  580.  
  581. #############################################################高级接口################################
  582. /**
  583. 微信api 接口地址
  584. */
  585. private $weixinApiLinks = array(
  586. 'message' => "https://api.weixin.qq.com/cgi-bin/message/custom/send?",##发送客服消息
  587. 'group_create' => "https://api.weixin.qq.com/cgi-bin/groups/create?",##创建分组
  588. 'group_get' => "https://api.weixin.qq.com/cgi-bin/groups/get?",##查询分组
  589. 'group_getid' => "https://api.weixin.qq.com/cgi-bin/groups/getid?",##查询某个用户在某个分组里面
  590. 'group_rename' => "https://api.weixin.qq.com/cgi-bin/groups/update?",##修改分组名
  591. 'group_move' => "https://api.weixin.qq.com/cgi-bin/groups/members/update?",## 移动用户分组
  592. 'user_info' => "https://api.weixin.qq.com/cgi-bin/user/info?",###获取用户基本信息
  593. 'user_get' => 'https://api.weixin.qq.com/cgi-bin/user/get?',##获取关注者列表
  594. 'menu_create' => 'https://api.weixin.qq.com/cgi-bin/menu/create?',##自定义菜单创建
  595. 'menu_get' => 'https://api.weixin.qq.com/cgi-bin/menu/get?',##自定义菜单查询
  596. 'menu_delete' => 'https://api.weixin.qq.com/cgi-bin/menu/delete?',##自定义菜单删除
  597. 'qrcode' => 'https://api.weixin.qq.com/cgi-bin/qrcode/create?',##创建二维码ticket
  598. 'showqrcode' => 'https://mp.weixin.qq.com/cgi-bin/showqrcode?',##通过ticket换取二维码
  599. 'media_download' => 'http://file.api.weixin.qq.com/cgi-bin/media/get?',
  600. 'media_upload' => 'http://file.api.weixin.qq.com/cgi-bin/media/upload?',##上传媒体接口
  601. 'oauth_code' => 'https://open.weixin.qq.com/connect/oauth2/authorize?',##微信oauth登陆获取code
  602. 'oauth_access_token' => 'https://api.weixin.qq.com/sns/oauth2/access_token?',##微信oauth登陆通过code换取网页授权access_token
  603. 'oauth_refresh' => 'https://api.weixin.qq.com/sns/oauth2/refresh_token?',##微信oauth登陆刷新access_token(如果需要)
  604. 'oauth_userinfo' => 'https://api.weixin.qq.com/sns/userinfo?',##微信oauth登陆拉取用户信息(需scope snsapi_userinfo)
  605. 'api_prefix'=>'https://api.weixin.qq.com/cgi-bin?',##请求api前缀
  606. 'message_template'=>'https://api.weixin.qq.com/cgi-bin/message/template/send?',##模板发送消息接口
  607. 'message_mass'=>'https://api.weixin.qq.com/cgi-bin/message/mass/send?',##群发消息
  608. 'upload_news'=>'https://api.weixin.qq.com/cgi-bin/media/uploadnews?',##上传图片素材
  609. );
  610. /**
  611. curl 数据提交
  612. */
  613. public function curl_post_https($url='', $postdata='',$options=FALSE){
  614. $curl = curl_init();// 启动一个CURL会话
  615. curl_setopt($curl, CURLOPT_URL, $url);//要访问的地址
  616. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);//对认证证书来源的检查
  617. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);//从证书中检查SSL加密算法是否存在
  618. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);//模拟用户使用的浏览器
  619. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);//使用自动跳转
  620. curl_setopt($curl, CURLOPT_AUTOREFERER, 1);//自动设置Referer
  621. if(!empty($postdata)){
  622. curl_setopt($curl, CURLOPT_POST, 1);//发送一个常规的Post请求
  623. if(is_array($postdata)){
  624. curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($postdata,JSON_UNESCAPED_UNICODE));//Post提交的数据包
  625. }else{
  626. curl_setopt($curl, CURLOPT_POSTFIELDS,$postdata);//Post提交的数据包
  627. }
  628. }
  629. //curl_setopt($curl, CURLOPT_COOKIEFILE, './cookie.txt'); //读取上面所储存的Cookie信息
  630. // curl_setopt($curl, CURLOPT_TIMEOUT, 30);//设置超时限制防止死循环
  631. curl_setopt($curl, CURLOPT_HEADER, $options);//显示返回的Header区域内容 可以是这样的字符串 "Content-Type: text/xml; charset=utf-8"
  632. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//获取的信息以文件流的形式返回
  633. $output = curl_exec($curl);//执行操作
  634. if(curl_errno($curl)){
  635. if($this->debug == true){
  636. $errorInfo='Errno'.curl_error($curl);
  637. $this->responseMessage('text',$errorInfo);//将错误返回给微信端
  638. }
  639. }
  640. curl_close($curl);//关键CURL会话
  641. return $output;//返回数据
  642. }
  643. /**
  644. 本地缓存token
  645. */
  646. private function setFileCacheToken($cacheId,$data,$savePath='/'){
  647. $cache=array();
  648. $cache[$cacheId]=$data;
  649. $this->saveFilePath=$_SERVER['DOCUMENT_ROOT'].$savePath.'token.cache';
  650. file_exists($this->saveFilePath)?chmod($this->saveFilePath,0775):chmod($this->saveFilePath,0775);//给文件覆权限
  651. file_put_contents($this->saveFilePath,serialize($cache));
  652.  
  653. }
  654.  
  655. /**
  656. 本地读取缓存
  657. */
  658. private function getFileCacheToken($cacheId){
  659. $fileDataInfo=file_get_contents($_SERVER['DOCUMENT_ROOT'].'/token.cache');
  660. $token=unserialize($fileDataInfo);
  661. if(isset($token[$cacheId])){
  662. return $token[$cacheId];
  663. }
  664. }
  665.  
  666. /**
  667. 检查高级接口权限 tokenc
  668. */
  669. public function checkAccessToken(){
  670. if($this->appid && $this->appSecret){
  671. $access=$this->getFileCacheToken('access');
  672. if(isset($access['expires_in'])){
  673. $this->expires_in= $access['expires_in'];
  674. }
  675. if( ( $this->expires_in - time() ) < 0 ){//表明已经过期
  676. $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appid}&secret={$this->appSecret}";
  677. $access = json_decode($this->curl_post_https($url));
  678. if(isset($access->access_token) && isset($access->expires_in)){
  679. $this->access_token = $access->access_token;##得到微信平台返回得到token
  680. $this->expires_in=time()+$access->expires_in;##得到微信平台返回的过期时间
  681. $this->setFileCacheToken('access',array('token'=>$this->access_token,'expires_in'=>$this->expires_in));##加入缓存access_token
  682. return true;
  683. }
  684. }else{
  685. $access=$this->getFileCacheToken('access');
  686. $this->access_token=$access['token'];
  687. return true;
  688. }
  689. }
  690. return false;
  691. }
  692. /**
  693. 获取access_token
  694. */
  695. public function getAccessToken(){
  696. return strval($this->access_token);
  697. }
  698. /**
  699. 得到时间
  700. */
  701. public function getExpiresTime(){
  702. return $this->expires_in;
  703. }
  704. /**
  705. 获取用户列表
  706. $next_openid 表示从第几个开始,如果为空 默认从第一个用户开始拉取
  707. */
  708. public function getUserList($next_openid=null){
  709. $url=$this->weixinApiLinks['user_get']."access_token={$this->access_token}&next_openid={$next_openid}";
  710. $resultData=$this->curl_post_https($url);
  711. return json_decode($resultData,true);
  712. }
  713. /**
  714. 获取用户的详细信息
  715. */
  716. public function getUserInfo($openid){
  717. $url=$this->weixinApiLinks['user_info']."access_token=".$this->access_token."&openid=".$openid."&lang=zh_CN";
  718. $resultData=$this->curl_post_https($url);
  719. return json_decode($resultData,true);
  720. }
  721. /**
  722. 创建用户分组
  723. */
  724. public function createUsersGroup($groupName){
  725. $data = '{"group": {"name": "'.$groupName.'"}}';
  726. $url=$this->weixinApiLinks['group_create']."access_token=".$this->access_token;
  727. $resultData=$this->curl_post_https($url,$data);
  728. return json_decode($resultData,true);
  729. }
  730. /**
  731. 移动用户分组
  732. */
  733. public function moveUserGroup($toGroupid,$openid){
  734. $data = '{"openid":"'.$openid.'","to_groupid":'.$toGroupid.'}';
  735. $url=$this->weixinApiLinks['group_move']."access_token=".$this->access_token;
  736. $resultData=$this->curl_post_https($url,$data);
  737. return json_decode($resultData,true);
  738. }
  739. /**
  740. 查询所有分组
  741. */
  742. public function getUsersGroups(){
  743. $url=$this->weixinApiLinks['group_get']."access_token=".$this->access_token;
  744. $resultData=$this->curl_post_https($url);
  745. return json_decode($resultData,true);
  746. }
  747. /**
  748. 查询用户所在分组
  749. */
  750. public function getUserGroup($openid){
  751. $data='{"openid":"'.$openid.'"}';
  752. $url=$this->weixinApiLinks['group_getid']."access_token=".$this->access_token;
  753. $resultData=$this->curl_post_https($url,$data);
  754. return json_decode($resultData,true);
  755. }
  756. /**
  757. 修改分组名
  758. */
  759. public function updateUserGroup($groupId,$groupName){
  760. $data='{"group":{"id":'.$groupId.',"name":"'.$groupName.'"}}';
  761. $url=$this->weixinApiLinks['group_rename']."access_token=".$this->access_token;
  762. $resultData=$this->curl_post_https($url,$data);
  763. return json_decode($resultData,true);
  764. }
  765. /**
  766. 生成二维码
  767. */
  768. public function createQrcode($scene_id=0,$qrcodeType=1,$expire_seconds=1800){
  769. $scene_id=($scene_id == 0)?rand(1,9999):$scene_id;
  770. if($qrcodeType == 1){
  771. $action_name='QR_SCENE';##表示临时二维码
  772. $data='{"expire_seconds":'.$expire_seconds.',"action_name": "QR_SCENE","action_info":{"scene":{"scene_id": '.$scene_id.'}}}';
  773. }else{
  774. $action_name='QR_LIMIT_SCENE';
  775. $data='{"action_name": "QR_LIMIT_SCENE", "action_info":{"scene":{"scene_id": '.$scene_id.'}}}';
  776. }
  777. $url=$this->weixinApiLinks['qrcode']."access_token=".$this->access_token;
  778. $resultData=$this->curl_post_https($url,$data);
  779. $result=json_decode($resultData,true);
  780. return $this->weixinApiLinks['showqrcode']."ticket=".urlencode($result["ticket"]);
  781. }
  782. /**
  783. 上传多媒体文件
  784. type 分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
  785. */
  786. public function uploadMedia($type, $file){
  787. $data=array("media" => "@".dirname(__FILE__).'\\'.$file);
  788. $url=$this->weixinApiLinks['media_upload']."access_token=".$this->access_token."&type=".$type;
  789. $resultData=$this->curl_post_https($url, $data);
  790. return json_decode($resultData, true);
  791. }
  792. /**
  793. 创建菜单
  794. */
  795. public function createMenu($menuListdata){
  796. $url =$this->weixinApiLinks['menu_create']."access_token=".$this->access_token;
  797. $resultData = $this->curl_post_https($url, $menuListdata);
  798. $callData=json_decode($resultData, true);
  799. if($callData['errcode'] > 0){#表示菜单创建失败
  800. return $callData;
  801. }
  802. return true;
  803. }
  804. /**
  805. 查询菜单
  806. */
  807. public function queryMenu(){
  808. $url = $this->weixinApiLinks['menu_get']."access_token=".$this->access_token;
  809. $resultData = $this->curl_post_https($url);
  810. return json_decode($resultData, true);
  811. }
  812. /**
  813. 删除菜单
  814. */
  815. public function deleteMenu(){
  816. $url = $this->weixinApiLinks['menu_delete']."access_token=".$this->access_token;
  817. $resultData = $this->curl_post_https($url);
  818. return json_decode($resultData, true);
  819. }
  820. /**
  821. 给某个人发送文本内容
  822. */
  823. public function sendMessage($touser, $data, $msgType = 'text'){
  824. $message = array();
  825. $message['touser'] = $touser;
  826. $message['msgtype'] = $msgType;
  827. switch ($msgType){
  828. case 'text': $message['text']['content']=$data; break;
  829. case 'image': $message['image']['media_id']=$data; break;
  830. case 'voice': $message['voice']['media_id']=$data; break;
  831. case 'video':
  832. $message['video']['media_id']=$data['media_id'];
  833. $message['video']['thumb_media_id']=$data['thumb_media_id'];
  834. break;
  835. case 'music':
  836. $message['music']['title'] = $data['title'];// 音乐标题
  837. $message['music']['description'] = $data['description'];// 音乐描述
  838. $message['music']['musicurl'] = $data['musicurl'];// 音乐链接
  839. $message['music']['hqmusicurl'] = $data['hqmusicurl'];// 高品质音乐链接,wifi环境优先使用该链接播放音乐
  840. $message['music']['thumb_media_id'] = $data['title'];// 缩略图的媒体ID
  841. break;
  842. case 'news':
  843. $message['news']['articles'] = $data; // title、description、url、picurl
  844. break;
  845. }
  846. $url=$this->weixinApiLinks['message']."access_token={$this->access_token}";
  847. $calldata=json_decode($this->curl_post_https($url,$message),true);
  848. if(!$calldata || $calldata['errcode'] > 0){
  849. return false;
  850. }
  851. return true;
  852. }
  853.  
  854. /**
  855. * 群发
  856. * */
  857.  
  858. public function sendMassMessage($sendType,$touser=array(),$data){
  859. $massArrayData=array();
  860. switch($sendType){
  861. case 'text':##文本
  862. $massArrayData=array(
  863. "touser"=>$touser,
  864. "msgtype"=>'text',
  865. "text"=>array('content'=>$data),
  866. );
  867. break;
  868. case 'news':##图文
  869. $massArrayData=array(
  870. "touser"=>$touser,
  871. "msgtype"=>'mpnews',
  872. "mpnews"=>array('media_id'=>$data),
  873. );
  874. break;
  875. case 'voice':##语音
  876. $massArrayData=array(
  877. "touser"=>$touser,
  878. "msgtype"=>'voice',
  879. "voice"=>array('media_id'=>$data),
  880. );
  881. break;
  882. case 'image':##图片
  883. $massArrayData=array(
  884. "touser"=>$touser,
  885. "msgtype"=>'image',
  886. "media_id"=>array('media_id'=>$data),
  887. );
  888. break;
  889. case 'wxcard': ##卡卷
  890. $massArrayData=array(
  891. "touser"=>$touser,
  892. "msgtype"=>'wxcard',
  893. "wxcard"=>array('card_id'=>$data),
  894. );
  895. break;
  896. }
  897. $url=$this->weixinApiLinks['message_mass']."access_token={$this->access_token}";
  898. $calldata=json_decode($this->curl_post_https($url,$massArrayData),true);
  899. return $calldata;
  900. }
  901. /**
  902. 发送模板消息
  903. */
  904. public function sendTemplateMessage($touser,$template_id,$url,$topColor,$data){
  905. $templateData=array(
  906. 'touser'=>$touser,
  907. 'template_id'=>$template_id,
  908. 'url'=>$url,
  909. 'topcolor'=>$topColor,
  910. 'data'=>$data,
  911. );
  912. $url=$this->weixinApiLinks['message_template']."access_token={$this->access_token}";
  913. $calldata=json_decode($this->curl_post_https($url,urldecode(json_encode($templateData))),true);
  914. return $calldata;
  915. }
  916.  
  917. /**
  918. * @param $type
  919. * @param $filePath 文件根路径
  920. */
  921. public function mediaUpload($type,$filePath){
  922. $url=$this->weixinApiLinks['media_upload']."access_token={$this->access_token}&type=".$type;
  923. $postData=array('media'=>'@'.$filePath);
  924. $calldata=json_decode($this->https_request($url,$postData),true);
  925. return $calldata;
  926. }
  927.  
  928. /**
  929. * @param $data
  930. * @return mixed
  931. * 上传图片资源
  932. */
  933. public function newsUpload($data){
  934. $articles=array( 'articles'=>$data );
  935. $url=$this->weixinApiLinks['upload_news']."access_token={$this->access_token}";
  936. $calldata=json_decode($this->curl_post_https($url,$articles),true);
  937. return $calldata;
  938. }
  939. /**
  940. * 获取微信授权链接
  941. *
  942. * @param string $redirect_uri 跳转地址
  943. * @param mixed $state 参数
  944. */
  945. public function getOauthorizeUrl($redirect_uri = '', $state = '',$scope='snsapi_userinfo'){
  946. $redirect_uri = urlencode($redirect_uri);
  947. $state=empty($state)?'1':$state;
  948. $url=$this->weixinApiLinks['oauth_code']."appid={$this->appid}&redirect_uri={$redirect_uri}&response_type=code&scope={$scope}&state={$state}#wechat_redirect";
  949. return $url;
  950. }
  951. /**
  952. * 获取授权token
  953. *
  954. * @param string $code 通过get_authorize_url获取到的code
  955. */
  956. public function getOauthAccessToken(){
  957. $code = isset($_GET['code'])?$_GET['code']:'';
  958. if (!$code) return false;
  959. $url=$this->weixinApiLinks['oauth_access_token']."appid={$this->appid}&secret={$this->appSecret}&code={$code}&grant_type=authorization_code";
  960. $token_data=json_decode($this->curl_post_https($url),true);
  961. $this->oauthAccessToken=$token_data['access_token'];
  962. return $token_data;
  963. }
  964.  
  965. /**
  966. * 刷新access token并续期
  967. */
  968. public function getOauthRefreshToken($refresh_token){
  969. $url=$this->weixinApiLinks['oauth_refresh']."appid={$this->appid}&grant_type=refresh_token&refresh_token={$refresh_token}";
  970. $token_data=json_decode($this->curl_post_https($url),true);
  971. $this->oauthAccessToken=$token_data['access_token'];
  972. return $token_data;
  973. }
  974. /**
  975. * 获取授权后的微信用户信息
  976. *
  977. * @param string $access_token
  978. * @param string $open_id 用户id
  979. */
  980. public function getOauthUserInfo($access_token='', $open_id = ''){
  981. $url=$this->weixinApiLinks['oauth_userinfo']."access_token={$access_token}&openid={$open_id}&lang=zh_CN";
  982. $info_data=json_decode($this->curl_post_https($url),true);
  983. return $info_data;
  984. }
  985. /**
  986. * 登出当前登陆用户
  987. */
  988. public function logout($openid='',$uid=''){
  989. $url = 'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxlogout?redirect=1&type=1';
  990. $data=array('uin'=>$uid,'sid'=>$openid);
  991. $this->curl_post_https($url,$data);
  992. return true;
  993. }
  994. public function https_request($url, $data = null){
  995. $curl = curl_init();
  996. curl_setopt($curl, CURLOPT_URL, $url);
  997. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  998. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  999. if (!empty($data)){
  1000. curl_setopt($curl, CURLOPT_POST, 1);
  1001. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  1002. }
  1003. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  1004. $output = curl_exec($curl);
  1005. curl_close($curl);
  1006. return $output;
  1007. }
  1008.  
  1009. }
  1010.  
  1011. 告知义务:
  1012. 1. api提供订阅号基本服务以及公众号常用服务;
  1013.  
  1014. 2. api如不能满足您的需求,请阅读微信公众平台说明文档
  1015.  
  1016. 使用说明:
  1017. header('Content-type: text/html; charset=utf-8');#设置头信息
  1018. require_once('zhphpWeixinApi.class.php');#加载微信接口类文件
  1019. $zhwx=new zhphpWeixinApi();//实例化
  1020.  
  1021. 配置:
  1022. 第一种方式:
  1023. $zhwx->weixinConfig=array(
  1024. 'token'=>'weixintest',
  1025. 'appid'=>'wx7b4b6ad5c7bfaae1',
  1026. 'appSecret'=>'faaa6a1e840fa40527934a293fabfbd1',
  1027. 'myweixinId'=>'gh_746ed5c6a58b'
  1028. );
  1029.  
  1030. 第二种方式:
  1031. $configArr=array(
  1032. 'token'=>'weixintest',
  1033. 'appid'=>'wx7b4b6ad5c7bfaae1',
  1034. 'appSecret'=>'faaa6a1e840fa40527934a293fabfbd1',
  1035. 'myweixinId'=>'gh_746ed5c6a58b'
  1036. );
  1037. $zhwx->setConfig($configArr);
  1038.  
  1039. 第三种方式:
  1040. $zhwx->weixinBaseApiMessage($configArr); ##订阅号使用
  1041.  
  1042. $zhwx->weixinHighApiMessage($configArr);## 服务号使用
  1043.  
  1044. 官方建议使用 第二种方式
  1045.  
  1046. 订阅号基本功能调用
  1047. $zhwx->weixinBaseApiMessage(); #订阅号接口入口 返回 true false
  1048.  
  1049. 下面是调用案例
  1050. if($zhwx->weixinBaseApiMessage()){ //基本微信接口会话 必须
  1051. $keyword=$zhwx->getUserTextRequest();//得到用户发的微信内容, 这里可以写你的业务逻辑
  1052. $msgtype=$zhwx->getUserMsgType();//得到用户发的微信数据类型, 这里可以写你的业务逻辑
  1053. $SendTime=$zhwx->getUserSendTime();//得到用户发送的时间
  1054. $fromUserName=$zhwx->getUserWxId();//用户微信id
  1055. $pingtaiId=$zhwx->getPlatformId();//平台微信id
  1056. $requestId=$zhwx->getUserRequestId(); //获取微信公众平台消息ID
  1057. $userPostData=$zhwx->getUserPostData();//获取用户提交的post 数据对象集
  1058. if( $msgtype == 'text' ){ //如果是文本类型
  1059. if($keyword == 'news'){ //新闻类别请求
  1060. $callData=array(
  1061. array('Title'=>'第一条新闻的标题','Description'=>'第一条新闻的简介','PicUrl'=>'http://t12.baidu.com/it/u=1040955509,77044968&fm=76','Url'=>'http://wxphptest1.applinzi.com/'),
  1062. array('Title'=>'第二条新闻的标题','Description'=>'第一条新闻的简介','PicUrl'=>'https://images0.cnblogs.com/blog2015/340216/201505/051316468603876.png','Url'=>'http://wxphptest1.applinzi.com/'),
  1063. array('Title'=>'第三条新闻的标题','Description'=>'第一条新闻的简介','PicUrl'=>'http://dimgcn2.s-msn.com/imageadapter/w60h60q85/stimgcn3.s-msn.com/msnportal/hp/2016/01/21/3e3ef7f07361b5211e2b155bb66fa6a9.jpg','Url'=>'http://wxphptest1.applinzi.com/'),
  1064. );
  1065. $zhwx->responseMessage('news',$callData);
  1066. }elseif($keyword == 'music'){ //音乐请求
  1067. $music=array(
  1068. "Title"=>"最炫民族风",
  1069. "Description"=>"歌手:凤凰传奇",
  1070. "MusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3",
  1071. "HQMusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3"
  1072. );
  1073. $zhwx->responseMessage('music',$music);
  1074. }else{
  1075. $callData='这是zhphp 官方对你的回复:
  1076. 你输入的内容是'.$keyword.'
  1077. 你发数据类型是:'.$msgtype.'
  1078. 你发的数据时间是:'.$SendTime.'
  1079. 你的微信ID是:'.$fromUserName.'
  1080. 平台的微信Id是:'.$pingtaiId.'
  1081. zhphp官方接收的ID是:'.$requestId;
  1082. $zhwx->responseMessage('text',$callData);
  1083. }
  1084. }else if($msgtype == 'image'){ //如果是图片类型
  1085. $image=$zhwx->getUserImageRequest();//如果用户发的是图片信息,就去得到用户的图形 信息
  1086. $callData=$image['MediaId'];//mediaID 是微信公众平台返回的图片的id,微信公众平台是依据该ID来调用用户所发的图片
  1087. $zhwx->responseMessage('image',$callData);
  1088.  
  1089. }else if($msgtype == 'voice'){ //如果是语音消息,用于语音交流
  1090. $callData=$zhwx->getUserVoiceRequest(); //返回数组
  1091. $zhwx->responseMessage('voice',$callData);
  1092. }elseif($msgtype == 'event'){//事件,由系统自动检验类型
  1093. $content='感谢你关注zhphp官方平台';//给数据为数据库查询出来的
  1094. $callData=$zhwx->responseEventMessage($content);//把数据放进去,由系统自动检验类型,并返回字符串或者数组的结果
  1095. $zhwx->responseMessage('text',$callData); //使用数据
  1096. }else{
  1097. $callData='这是zhphp 官方对你的回复:
  1098. 你发数据类型是:'.$msgtype.'
  1099. 你发的数据时间是:'.$SendTime.'
  1100. zhphp官方接收的ID是:'.$requestId;
  1101. $zhwx->responseMessage('text',$callData);
  1102. }
  1103. }
  1104. ##########################################
  1105. 订阅号提供基本接口
  1106. validToken() 平台与微信公众号握手
  1107. getAccessToken() 获取accessToken
  1108. getExpiresTime() 获取accessToken 过期时间
  1109. CheckAccessToken() 检查高级接口权限
  1110. bytes_to_emoji($cp) 字节转表情
  1111. getUserMessageInfo() 获取用户的所有会话状态信息
  1112. getUsertEventClickRequest() 获取用户点击菜单信息
  1113. getUserEventLocationRequest() 上报地理位置事件
  1114. getUserEventScanRequest() 二维码扫描类容
  1115. getUserLinkRequest() 获取用户链接信息
  1116. getUserLocationRequest() 获取用户本地位置信息
  1117. getUserMusicRequest() 获取音乐内容
  1118. getUserVideoRequest() 获取视频内容
  1119. getUserVoiceRequest() 获取语音消息
  1120. getUserImageRequest() 获取图片消息
  1121. getUserRequestId() 返回微信平台的当条微信id
  1122. getUserTextRequest() 获取用户输入的信息
  1123. getPlatformId() 获取当前平台的id
  1124. getUserWxId() 获取当前用户的id
  1125. getUserSendTime() 获取用户发送微信的时间
  1126. getUserMsgType() 获取当前的会话类型
  1127. isWeixinMsgType() 检查用户发的微信类型
  1128. getUserPostData() 获取用户发送信息的数据对象集
  1129. getConfig() 获取配置信息
  1130. responseMessage($wxmsgType,$callData='') 微信平台回复用户信息统一入口
  1131.  
  1132. #####################################################
  1133. 服务号基本功能调用
  1134. $zhwx->weixinHighApiMessage(); #服务号接口入口 返回 true false
  1135. $zhwx->CheckAccessToken(); #检查access权限
  1136.  
  1137. 下面是调用案例
  1138. if($zhwx->weixinHighApiMessage()){// 检查配置统一入口
  1139. if($zhwx->CheckAccessToken()){ //检查accessToken 为必须
  1140. $arrayData=$zhwx->getUserList(); ##测试用户列表
  1141. echo '<pre>';
  1142. rint_r($arrayData);
  1143. echo '</pre>';*/
  1144. }
  1145. }
  1146.  
  1147. ######################################################
  1148. 服务号提供的接口:
  1149. getUserList($next_openid=null) 获取用户列表
  1150. getUserInfo($openid) 获取用户详细信息
  1151. createUsersGroup($groupName) 创建分组
  1152. moveUserGroup($toGroupid,$openid) 移动用户到组
  1153. getUsersGroups() 获取所有分组
  1154. getUserGroup($openid) 获取用户所在的组
  1155. updateUserGroup($groupId,$groupName) 修改组名
  1156. createQrcode($scene_id,$qrcodeType=1,$expire_seconds=1800) 生成二维码
  1157. uploadMedia($type, $file) 上传文件
  1158. createMenu($menuListdata) 创建菜单
  1159. queryMenu() 查询菜单
  1160. deleteMenu() 删除菜单
  1161. sendMessage($touser, $data, $msgType = 'text') 主动某个用户发送数据
  1162. newsUpload($data) 上传图文素材 按接口规定 $data 必须是二维数组
  1163. mediaUpload($type,$filePath) 上传媒体文件 filePath 必须是文件绝对路径
  1164. sendTemplateMessage($touser,$template_id,$url,$topColor,$data) 发送模板消息 通常为通知接口
  1165. sendMassMessage($sendType,$touser=array(),$data) 群发消息
  1166.  
  1167. header('Content-type: text/html; charset=utf-8');#设置头信息
  1168. // 微信类 调用
  1169. require_once('zhphpWeixinApi.class.php');
  1170. echo 'helloword';
  1171. exit;
  1172. $zhwx=new zhphpWeixinApi();//实例化
  1173. $zhwx->weixinConfig=array('token'=>'weixintest','appid'=>'wx7b4b6ad5c7bfaae1','appSecret'=>'faaa6a1e840fa40527934a293fabfbd1','myweixinId'=>'gh_746ed5c6a58b');//参数配置
  1174. /*$configArr=array(
  1175. 'token'=>'weixintest',
  1176. 'appid'=>'wx7b4b6ad5c7bfaae1',
  1177. 'appSecret'=>'faaa6a1e840fa40527934a293fabfbd1',
  1178. 'myweixinId'=>'gh_746ed5c6a58b'
  1179. );
  1180. $zhwx->setConfig($configArr);
  1181. */
  1182. #################################应用程序逻辑# 订阅号测试 start #####################################
  1183. if($zhwx->weixinBaseApiMessage()){ //基本微信接口会话 必须
  1184. $keyword=$zhwx->getUserTextRequest();//得到用户发的微信内容, 这里可以写你的业务逻辑
  1185. $msgtype=$zhwx->getUserMsgType();//得到用户发的微信数据类型, 这里可以写你的业务逻辑
  1186. $SendTime=$zhwx->getUserSendTime();//得到用户发送的时间
  1187. $fromUserName=$zhwx->getUserWxId();//用户微信id
  1188. $pingtaiId=$zhwx->getPlatformId();//平台微信id
  1189. $requestId=$zhwx->getUserRequestId(); //获取微信公众平台消息ID
  1190. $userPostData=$zhwx->getUserPostData();//获取用户提交的post 数据对象集
  1191. if( $msgtype == 'text' ){ //如果是文本类型
  1192. if($keyword == 'news'){ //新闻类别请求
  1193. $callData=array(
  1194. array('Title'=>'第一条新闻的标题','Description'=>'第一条新闻的简介','PicUrl'=>'http://t12.baidu.com/it/u=1040955509,77044968&fm=76','Url'=>'http://wxphptest1.applinzi.com/'),
  1195. array('Title'=>'第二条新闻的标题','Description'=>'第一条新闻的简介','PicUrl'=>'https://images0.cnblogs.com/blog2015/340216/201505/051316468603876.png','Url'=>'http://wxphptest1.applinzi.com/'),
  1196. array('Title'=>'第三条新闻的标题','Description'=>'第一条新闻的简介','PicUrl'=>'http://dimgcn2.s-msn.com/imageadapter/w60h60q85/stimgcn3.s-msn.com/msnportal/hp/2016/01/21/3e3ef7f07361b5211e2b155bb66fa6a9.jpg','Url'=>'http://wxphptest1.applinzi.com/'),
  1197. );
  1198. $zhwx->responseMessage('news',$callData);
  1199. }elseif($keyword == 'music'){ //音乐请求
  1200. $music=array(
  1201. "Title"=>"最炫民族风",
  1202. "Description"=>"歌手:凤凰传奇",
  1203. "MusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3",
  1204. "HQMusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3"
  1205. );
  1206. $zhwx->responseMessage('music',$music);
  1207. }else{
  1208. $callData='这是zhphp 官方对你的回复:
  1209. 你输入的内容是'.$keyword.'
  1210. 你发数据类型是:'.$msgtype.'
  1211. 你发的数据时间是:'.$SendTime.'
  1212. 你的微信ID是:'.$fromUserName.'
  1213. 平台的微信Id是:'.$pingtaiId.'
  1214. zhphp官方接收的ID是:'.$requestId;
  1215. $zhwx->responseMessage('text',$callData);
  1216. }
  1217. }else if($msgtype == 'image'){ //如果是图片类型
  1218. $image=$zhwx->getUserImageRequest();//如果用户发的是图片信息,就去得到用户的图形 信息
  1219. $callData=$image['MediaId'];//mediaID 是微信公众平台返回的图片的id,微信公众平台是依据该ID来调用用户所发的图片
  1220. $zhwx->responseMessage('image',$callData);
  1221.  
  1222. }else if($msgtype == 'voice'){ //如果是语音消息,用于语音交流
  1223. $callData=$zhwx->getUserVoiceRequest(); //返回数组
  1224. $zhwx->responseMessage('voice',$callData);
  1225. }elseif($msgtype == 'video'){//视频请求未测试成功
  1226. $video=$zhwx->getUserVideoRequest();//得到用户视频内容信息
  1227. $callData['Title']='这是是视频的标题';//参数为必须
  1228. $callData['Description']='这是视频的简介';//参数为必须
  1229. $callData['MediaId']=$video['MediaId'];//得到数组中的其中的一个id
  1230. $callData['ThumbMediaId']=$video['ThumbMediaId'];//视频的缩略图id
  1231. $zhwx->responseMessage('video',$callData); //把数据传递到平台接口 api 类 操作并返回数据给微信平台
  1232. }elseif($msgtype == 'link'){
  1233. $link=$zhwx->getUserLinkRequest();
  1234. $callData='这是zhphp 官方对你的回复:
  1235. 你输入的内容是'.$keyword.'
  1236. 你发数据类型是:'.$msgtype.'
  1237. 你发的数据时间是:'.$SendTime.'
  1238. zhphp官方接收的ID是:'.$requestId;
  1239. $zhwx->responseMessage('text',$callData);
  1240. }elseif($msgtype == 'event'){//事件,由系统自动检验类型
  1241. $content='感谢你关注zhphp官方平台';//给数据为数据库查询出来的
  1242. $callData=$zhwx->responseEventMessage($content);//把数据放进去,由系统自动检验类型,并返回字符串或者数组的结果
  1243. $zhwx->responseMessage('text',$callData); //使用数据
  1244. }else{
  1245. $callData='这是zhphp 官方对你的回复:
  1246. 你发数据类型是:'.$msgtype.'
  1247. 你发的数据时间是:'.$SendTime.'
  1248. zhphp官方接收的ID是:'.$requestId;
  1249. $zhwx->responseMessage('text',$callData);
  1250. }
  1251. }
  1252.  
  1253. ###################################服务号测试 start ############
  1254. /*if($zhwx->weixinHighApiMessage()){// 检查配置统一入口
  1255. $zhwx->checkAccessToken();
  1256. //if($zhwx->checkAccessToken()){ //检查accessToken 为必须
  1257. //$arrayData=$zhwx->getUserList(); ##测试用户列表
  1258. /*$openid='oQucos17KaXpwPfwp39FwzfzrfNA'; ###测试获取个人信息
  1259. $arrayData=$zhwx->getUserInfo($openid);
  1260. echo '<pre>';
  1261. print_r($arrayData);
  1262. echo '</pre>';*/
  1263. ###测试二维码
  1264. //$qrcodeImgsrc=$zhwx->createQrcode(100);
  1265. //echo '<img src="'.$qrcodeImgsrc.'">';
  1266. ###创建一个一级菜单 type 点击类型 name 菜单名称 key 菜单说明
  1267. /*$menuListData=array(
  1268. 'button'=>array(
  1269. array('type'=>'click','name'=>'投票活动','key'=>'tphd',),
  1270. array('type'=>'view','name'=>'查看结果','key'=>'ckjg','url'=>''),
  1271. )
  1272. );
  1273. $list=$zhwx->createMenu($menuListData);
  1274. var_dump($list);
  1275.  
  1276. //}
  1277. }*/
  1278.  
  1279. ###############################模板消息################
  1280. if($zhwx->weixinBaseApiMessage()){
  1281. if($msgtype == 'text'){
  1282. $location=urlencode($keyword);
  1283. $url='http://api.map.baidu.com/telematics/v3/weather?location='.$location.'&output=json&ak=C845576f91f52f4e62bf8d9153644cb8';
  1284. $jsonData=$zhwx->curl_post_https($url);
  1285. $data=json_decode($jsonData,true);
  1286. $weth=$data['results'][0];
  1287. /*$content='你查询的是:'.$weth['currentCity'].'的天气情况';
  1288. $content.='pm2.5='.$weth['pm25'];
  1289. $content.='今天的天气是:'.$weth['weather_data'][0]['date'];
  1290. $zhwx->responseMessage('text',$content);*/
  1291. // $userlist=$zhwx->getUserList();
  1292. // $zhwx->responseMessage('text',json_encode($userlist));
  1293. $touser= $fromUserName;
  1294. $tpl_id='eSYzsYE3rCupK8_boCnfMcayi0cUXwPB6W7Lrz4TrdA';
  1295. $url='http://www.baidu.com/';
  1296. $topcolor="#52654D";
  1297. $wdata=array(
  1298. 'first'=>array('value'=>urlencode('欢迎使用天气查询系统'),'color'=>'#12581F'),
  1299. 'city'=>array('value'=>urlencode($weth['currentCity']),'color'=>'#56751F'),
  1300. 'pm'=>array('value'=>urlencode($weth['pm25']),'color'=>'#15751F'),
  1301. );
  1302. $zhwx->checkAccessToken();
  1303. $cc=$zhwx->sendTemplateMessage($touser,$tpl_id,$url,$topcolor,$wdata);
  1304. }
  1305. }
  1306.  
  1307. ###########################################新增群发消息
  1308. <?php
  1309. header('Content-type: text/html; charset=utf-8');#设置头信息
  1310. require_once('zhphpWeixinApi.class.php');
  1311. $zhwx=new zhphpWeixinApi();//实例化
  1312. $configArr=array(
  1313. 'token'=>'weixintest',
  1314. 'appid'=>'wx7b4b6ad5c7bfaae1',
  1315. 'appSecret'=>'faaa6a1e840fa40527934a293fabfbd1',
  1316. 'myweixinId'=>'gh_746ed5c6a58b'
  1317. );
  1318. $zhwx->setConfig($configArr);
  1319. $zhwx->checkAccessToken();
  1320. $userlist=$zhwx->getUserList();
  1321.  
  1322. if(isset($_POST['sub'])){
  1323. $touser=$_POST['userOpenId'];
  1324. //开始群发
  1325. $content='这是群发的文本';
  1326. $data= $zhwx->sendMassMessage('text',$touser,$content);
  1327. echo '<pre>';
  1328. print_r($data);
  1329. echo '</pre>';
  1330. exit;
  1331. }
  1332. ?>
  1333. <!DOCTYPE html>
  1334. <html>
  1335. <head>
  1336. <title>微信群发信息</title>
  1337. <style type="text/css">
  1338. .userlistBox{
  1339. width: 1000px;
  1340. height: 300px;
  1341. border: 1px solid red;
  1342. }
  1343. td{ text-align: center; border: 1px solid black;}
  1344.  
  1345. </style>
  1346. </head>
  1347. <body>
  1348.  
  1349. <?php
  1350. $userinfos=array();
  1351. foreach($userlist['data'] as $key=>$user){
  1352. foreach($user as $kk=>$list){
  1353. $userinfos[]=$zhwx->getUserInfo($list);
  1354. }
  1355. }
  1356. ?>
  1357. <form action="wx.php?act=send" method="post">
  1358. <div class="userlistBox">
  1359. <h2>请选择用户</h2>
  1360. <table >
  1361. <tr>
  1362. <th style="width: 10%;">编号</th>
  1363. <th style="width: 15%;">关注事件类型</th>
  1364. <th style="width: 15%;">用户姓名</th>
  1365. <th style="width: 10%;">性别</th>
  1366. <th style="width: 15%;">头像</th>
  1367. <th style="width: 15%;">所在地</th>
  1368. <th style="width: 15%;">所在组</th>
  1369. <th style="width: 5%;">操作</th>
  1370. </tr>
  1371. <?php
  1372. foreach($userinfos as $key=>$userinfo){
  1373. ?>
  1374. <tr>
  1375. <td><?php echo $key+1;?></td>
  1376. <td><?php
  1377. if($userinfo['subscribe'] == 1){
  1378. echo '普通关注事件';
  1379. }
  1380. ?></td>
  1381. <td> <?php echo $userinfo['nickname']; ?></td>
  1382. <td> <?php echo $userinfo['sex']==1?'男':'女'; ?></td>
  1383. <td> <?php
  1384. if(empty($userinfo['headimgurl'])){
  1385. echo '没有头像';
  1386. }else{
  1387. echo '<img width="50px" height="50px" src="'.$userinfo['headimgurl'].'">';
  1388. }
  1389. ?></td>
  1390. <td><?php echo $userinfo['country'].'-'.$userinfo['province'].'-'.$userinfo['city']; ?></td>
  1391. <td><?php
  1392. if($userinfo['groupid'] == 0){
  1393. echo '没有分组';
  1394. }else{
  1395. echo '还有完善功能';
  1396. }
  1397. ?>
  1398. </td>
  1399. <td><input type="checkbox" value="<?php echo $userinfo['openid'];?>" name="userOpenId[]" id="m_<?php echo $key+1; ?>" /></td>
  1400. </tr>
  1401. <?php
  1402. }
  1403. ?>
  1404. </table>
  1405. <input type="submit" name="sub" value="发送" />
  1406. </div>
  1407. </form>
  1408. </body>
  1409. </html>
  1410. #######################################图文发送案例调用
  1411. <?php
  1412. header('Content-type: text/html; charset=utf-8');#设置头信息
  1413. require_once('dodiWeixinApi.class.php');
  1414. $zhwx=new dodiWeixinApi();//实例化
  1415. $configArr=array(
  1416. 'token'=>'weixintest',
  1417. 'appid'=>'wx7b4b6ad5c7bfaae1',
  1418. 'appSecret'=>'faaa6a1e840fa40527934a293fabfbd1',
  1419. 'myweixinId'=>'gh_746ed5c6a58b'
  1420. );
  1421. $zhwx->setConfig($configArr);##配置参数
  1422. $zhwx->checkAccessToken();##检查token
  1423. $userlist=$zhwx->getUserList();##获取用户列表
  1424. //var_dump($userlist);
  1425. //$callData=$zhwx->mediaUpload('image','a.jpg');## 上传图片到微信 得到 media id
  1426. //CQKrXGNiJWiKutD17CWhoqlqW_80IByyFpLWa-dnPzhl7jPpQFiBbXhsAQVwId-q
  1427. $data=array(
  1428. array(
  1429. "thumb_media_id"=>"CQKrXGNiJWiKutD17CWhoqlqW_80IByyFpLWa-dnPzhl7jPpQFiBbXhsAQVwId-q",
  1430. "author"=>"xxx",
  1431. "title"=>"Happy Day",
  1432. "content_source_url"=>"www.qq.com",
  1433. "content"=>"<div style='width: 100%; height: 50px; background-color: red;'>文章内容</div>",
  1434. "diges"=>"digest"
  1435. ),
  1436. );
  1437. //$aa=$zhwx->newsUpload($data);//上传图文素材[ media_id] => 2n32OjOIdP7jewG0d55bKvuJYcH6XpWTeg8ViHCfzHGgKBZxmE72s3T2LY-3Q8LO
  1438.  
  1439. if(isset($_POST['sub'])){
  1440. $touser=$_POST['userOpenId'];
  1441. //开始群发
  1442. $content='
  1443. <div><img src="http://d005151912.0502.dodi.cn/a.jpg" style="width:100%; height:50px;"></div>
  1444. <div> 这是商品说明</div>
  1445. ';
  1446. $content.='查看详情: <a href="http://msn.huanqiu.com/china/article/2016-01/8473360.html">国家统计局局长王保安涉嫌严重违纪被免职</a>';
  1447. // $data= $zhwx->sendMassMessage('text',$touser,$content);
  1448. $data=$zhwx->sendMassMessage('news',$touser,'2n32OjOIdP7jewG0d55bKvuJYcH6XpWTeg8ViHCfzHGgKBZxmE72s3T2LY-3Q8LO'); ##主动发送图文消息
  1449. echo '<pre>';
  1450. print_r($data);
  1451. echo '</pre>';
  1452. exit;
  1453. }
  1454. ?>

下面是我的写法

1.首先是我的文件结构

2.文件偷偷打开来给你看看

  1. <?php
  2. header('Content-type: text/html; charset=utf-8');#设置头信息
  3. require_once('weixinapi.php');#加载微信接口类文件
  4. $zhwx=new zhphpWeixinApi();//实例化
  5.  
  6. $configArr=array(//自己修改
  7. 'token'=>'----------------',
  8. 'appid'=>'----------------------',
  9. 'appSecret'=>'--------------------',
  10. 'myweixinId'=>'--------------------'
  11. );
  12. $zhwx->setConfig($configArr);
  13.  
  14. if($zhwx->weixinBaseApiMessage()){ //基本微信接口会话 必须
  15. $keyword=$zhwx->getUserTextRequest();//得到用户发的微信内容, 这里可以写你的业务逻辑
  16. $msgtype=$zhwx->getUserMsgType();//得到用户发的微信数据类型, 这里可以写你的业务逻辑
  17. $SendTime=$zhwx->getUserSendTime();//得到用户发送的时间
  18. $fromUserName=$zhwx->getUserWxId();//用户微信id
  19. $pingtaiId=$zhwx->getPlatformId();//平台微信id
  20. $requestId=$zhwx->getUserRequestId(); //获取微信公众平台消息ID
  21. $userPostData=$zhwx->getUserPostData();//获取用户提交的post 数据对象集
  22. if( $msgtype == 'text' ){ //如果是文本类型
  23. if($keyword == 'news'){ //新闻类别请求
  24. $callData=array(
  25. array('Title'=>'第一条新闻','Description'=>'第一条新闻的简介','PicUrl'=>'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3246575267,854993829&fm=27&gp=0.jpg','Url'=>'https://mp.weixin.qq.com/s/ay8RRkElw2xUlffeDnhQLw'),
  26. array('Title'=>'第二条新闻的标题','Description'=>'第一条新闻的简介','PicUrl'=>'https://images0.cnblogs.com/blog2015/340216/201505/051316468603876.png','Url'=>'http://wxphptest1.applinzi.com/'),
  27. array('Title'=>'第三条新闻的标题','Description'=>'第一条新闻的简介','PicUrl'=>'http://dimgcn2.s-msn.com/imageadapter/w60h60q85/stimgcn3.s-msn.com/msnportal/hp/2016/01/21/3e3ef7f07361b5211e2b155bb66fa6a9.jpg','Url'=>'http://wxphptest1.applinzi.com/'),
  28. );
  29. $zhwx->responseMessage('news',$callData);
  30. }elseif($keyword == 'music'){ //音乐请求
  31. $music=array(
  32. "Title"=>"安眠曲",
  33. "Description"=>"谭嗣同",
  34. "MusicUrl"=>"https://www.xiami.com/song/xN1kyHa331d?spm=a1z1s.3521865.23309997.51.kf2b5r"
  35. // ,"HQMusicUrl"=>"http://www.kugou.com/song/#hash=3339B5F7024EC2ABB8954C0CC4983548&album_id=548709"
  36. );
  37. $zhwx->responseMessage('music',$music);
  38. }else{
  39. $callData='我轻轻的告诉你~
  40. 你输入的内容是:'.$keyword.'
  41. 你发数据类型是:'.$msgtype.'
  42. 你发的数据时间是:'.$SendTime.'
  43. ------------------------------------------'.'
  44. 输入 "news" "music"试试吧!';
  45. $zhwx->responseMessage('text',$callData);
  46. }
  47. }else if($msgtype == 'image'){ //如果是图片类型
  48. $image=$zhwx->getUserImageRequest();//如果用户发的是图片信息,就去得到用户的图形 信息
  49. $callData=$image['MediaId'];//mediaID 是微信公众平台返回的图片的id,微信公众平台是依据该ID来调用用户所发的图片
  50. $zhwx->responseMessage('image',$callData);
  51.  
  52. }else if($msgtype == 'voice'){ //如果是语音消息,用于语音交流
  53. $callData=$zhwx->getUserVoiceRequest(); //返回数组
  54. $zhwx->responseMessage('voice',$callData);
  55. }elseif($msgtype == 'event'){//事件,由系统自动检验类型
  56. $content='欢迎光临━(*`∀´*)ノ亻'.'
  57. 随意输入试试吧!';//给数据为数据库查询出来的
  58. $callData=$zhwx->responseEventMessage($content);//把数据放进去,由系统自动检验类型,并返回字符串或者数组的结果
  59. $zhwx->responseMessage('text',$callData); //使用数据
  60. }else{
  61. $callData='我听不清你在说什么:
  62. 你发数据类型是:'.$msgtype.'
  63. 你发的数据时间是:'.$SendTime.'
  64. 我接收的ID是:'.$requestId;
  65. $zhwx->responseMessage('text',$callData);
  66. }
  67. }

wei.php

weixinapi.php

源码和weixinapi.php是不一样的,后者删减了部分,自己去对照。。

基本就这样了,可以去公众号上测试

PHP微信公众号开发之自动回复的更多相关文章

  1. Java微信公众号开发----关键字自动回复消息

    在配置好开发者配置后,本人第一个想要实现的是自动回复消息的功能,说明以下几点: 1. url 仍然不变,还是开发配置里的url 2. 微信采用 xml 格式传输数据 3.微信服务器传给我们的参数主要有 ...

  2. [.NET] 使用 Senparc.Weixin 接入微信公众号开发:简单实现自动回复

    使用 Senparc.Weixin 接入微信公众号开发:简单实现自动回复 目录 一.前提 二.基本配置信息简析 三.配置服务器地址(URL) 四.请求处理 一.前提 先申请微信公众号的授权,找到或配置 ...

  3. 线程安全使用(四) [.NET] 简单接入微信公众号开发:实现自动回复 [C#]C#中字符串的操作 自行实现比dotcore/dotnet更方便更高性能的对象二进制序列化 自已动手做高性能消息队列 自行实现高性能MVC WebAPI 面试题随笔 字符串反转

    线程安全使用(四)   这是时隔多年第四篇,主要是因为身在东软受内网限制,好多文章就只好发到东软内部网站,懒的发到外面,现在一点点把在东软写的文章给转移出来. 这里主要讲解下CancellationT ...

  4. 快递Api接口 & 微信公众号开发流程

    之前的文章,已经分析过快递Api接口可能被使用的需求及场景:今天呢,简单给大家介绍一下微信公众号中怎么来使用快递Api接口,来完成我们的需求和业务场景. 开发语言:Nodejs,其中用到了Neo4j图 ...

  5. .net微信公众号开发——消息与事件

    作者:王先荣    本文介绍如何处理微信公众号开发中的消息与事件,包括:(1)消息(事件)概况:(2)验证消息的真实性:(3)解析消息:(4)被动回复消息:(5)发送其他消息.    开源项目地址:h ...

  6. .net微信公众号开发——快速入门

    作者:王先荣 最近在学习微信公众号开发,将学习的成果做成了一个类库,方便重复使用. 现在微信公众号多如牛毛,开发微信的高手可以直接无视这个系列的文章了. 使用该类库的流程及寥寥数行代码得到的结果如下. ...

  7. C#微信公众号开发 -- (六)自定义菜单事件之CLICK

    微信公众号中当用户手动点击了按钮,微信公众号会被动的向用户发送文字消息或者图文消息. 通过C#微信公众号开发 -- (五)自定义菜单创建 我们知道了如何将CLICK类型的按钮添加到自己的微信公众平台上 ...

  8. 微信公众号开发被动回复用户消息,回复内容Content使用了"\n"换行符还是没有换行

    使用语言和框架:本人后端开发使用的Python的DRF(Django REST framework)框架 需求:在微信公众号开发时,需要实现自动回复,即被关注回复.收到消息回复.关键词回复 发现问题: ...

  9. python之微信公众号开发(基本配置和校验)

    前言 最近有微信公众号开发的业务,以前没有用python做过微信公众号开发,记录一下自己的学习和开发历程,共勉! 公众号类型 订阅号 普通订阅号 认证订阅号 服务号 普通服务号 认证服务号 服务方式 ...

随机推荐

  1. 让使用SQLite的.NET应用自适应32位/64位系统

    如果一个.NET应用要自适应32位/64位系统,只需要在项目的“目标平台”设置为“Any CPU”.但是如果应用中使用了SQLite,情况就不同了. SQLite的.NET开发包来自是System.D ...

  2. VS中实时获取SVN的版本号并写入到AssemblyInfo.cs中

    在开发项目时,需要知道当前发布的到底是哪个版本,比较好的方式就是获取SVN的版本来作为项目的版本.项目版本一般由主版本.次版本.内部版本.修改版本四个部分组成,我们获取的SVN版本就作为修改版本即可. ...

  3. BeanShell用法(摘抄至网络)

    说明:本文部分资料摘抄至 来源: http://www.cnblogs.com/puresoul/p/4915350.html 来源: http://www.cnblogs.com/puresoul/ ...

  4. 在free bsd上跑JMeter 的 plugin "PerfMon Server Agent"

    在free bsd上跑JMeter 的 plugin "PerfMon Server Agent" 目的: 在free bsd上跑JMeter 的 plugin "Per ...

  5. Redis set数据结构

    set里的数据不能重复 1. 增加set1,值为 a b c d 1 2 3 2. 返回集合元素的数量 3. 重命名set1为set100 4. 查看集合中的成员 5.sdiff set100 set ...

  6. Visual Studio: 一键卸载所有组件工具,彻底卸载干净。

    第一步.手动卸载VS主体 第二步.下载工具并解压 网盘下载地址:https://pan.baidu.com/s/1eSHRYxW 也可以在Github上下载最新版本:https://github.co ...

  7. 调试PHP错误

    error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', "On");

  8. win2008 server 多IP配置

    本人服务器环境   win8 + phpstudy   一个服务器多个IP 以前都是用linux,买了几套源码结果都是win8server 服务器+phpstudy. 渐渐也就随大流了.懒的去琢磨 一 ...

  9. 关键两招就解决Wampserver 打开localhost显示IIS7图片问题

    我们在安装集成环境Wampserver之后,有时会遇到一个问题, 打开localhost显示一张IIS7图片,这个问题该如何解决呢,我在网上找了一些说的都很乱,我在这里简单整理了一下解决方法   1  ...

  10. Ubuntu 14.10 下Eclipse操作HBase

    环境介绍 64位Ubuntu14.10,Hadoop 2.5.0 ,HBase 0.99.0 准备环境 1 安装Hadoop 2.5.0,可参考http://www.cnblogs.com/liuch ...