<?php
class?IndexAction?extends?Action?{
public?function?_construct(){
}
????public?function?index(){
???? $nonce=$_GET['nonce'];
???? $token='zhongmei';
???? $timestamp=$_GET['timestamp'];
$signature=$_GET['signature'];
???? $echostr=$_GET['echostr'];
???? $array=array();
???? $array=array($nonce,$timestamp,$token);
???? sort($array);
???? $str=sha1(implode($array));
???? if($str==$signature?&&?$echostr){
???? echo?$echostr;
???? exit;
???? }else?{
???? $this->reponseMsg();
???? }
????}
public?function?reponseMsg(){
?????//1.獲取到微信推送過來post數(shù)據(jù)(xml格式)
?????$postArr?=?$GLOBALS('HTTP_RAW_POST_DATA');
?????//2.處理消息類型,并設(shè)置回復(fù)類型和內(nèi)容
?????$postObj?=?simplexml_load_string($postArr);//轉(zhuǎn)化成對(duì)象
?????//$postObj->ToUserName='';
?????//$postObj->FromUserName='';
?????//$postObj->CreateTime?='';
?????//$postObj->MsgType='';
?????//$postObj->Event='';
?????//判斷該數(shù)據(jù)包是否是訂閱的時(shí)間推送
?????if(?strtolower(?$postObj->MsgType)?==?'event'){
?????????//如果是關(guān)注subscribe事件
?????????if(?strtolower($postObj->Event?==?'subscribe')?){
?????????????//回復(fù)用戶消息
????????? $toUser????=?$postObj->FromUserName;
????????? $fromUser??=?$postObj->toUserName;
????????? $time??????=?time();
????????? $msgType???=?'text';
????????? $content???=?'歡迎關(guān)注我們的微信公眾賬號(hào)';
????????? $template??=?"<xml>
??????????????????????????<ToUserName><![CDATA[%s]]></ToUserName>
??????????????????????????<FromUserName><![CDATA[%s]]></FromUserName>
??????????????????????????<CreateTime>%s</CreateTime>
??????????????????????????<MsgType><![CDATA[%s]]></MsgType>
??????????????????????????<Content><![CDATA[%s]]></Content>
??????????????????????????</xml>";
????????????$info??????=?sprintf($template,?$toUser,?$fromUser,?$time,?$msgType,?$content);
????????????echo?$info;
?????????}
?????}
?????if(?strtolower(?$postObj->MsgType)?==?'text'){
?????????if(?strtolower($postObj->Content?==?'zhongmei')?){
????????? $template??=?"<xml>
??????????????????????????<ToUserName><![CDATA[%s]]></ToUserName>
??????????????????????????<FromUserName><![CDATA[%s]]></FromUserName>
??????????????????????????<CreateTime>%s</CreateTime>
??????????????????????????<MsgType><![CDATA[%s]]></MsgType>
??????????????????????????<Content><![CDATA[%s]]></Content>
??????????????????????????</xml>";
????????????$fromUser=$postObj->ToUserName;
????????????$toUser=$postObj->FromUserName;
????????????$time=time();
????????????$content='zhongmei?is?good';
????????????$msgType='text';
????????????echo?sprintf($template,$toUser,$fromUser,$time,$msgType,$content);
?????????}
?????}
????}
}首先微信中服務(wù)器配置已經(jīng)更改為自己的了,token也改了。但在啟用服務(wù)器配置并訂閱后什么推送消息都沒有,輸入zhongmei后也沒有返回值,只返回該公眾號(hào)暫時(shí)無法提供服務(wù),請(qǐng)稍后再試。請(qǐng)幫忙看看哪里出問題了,謝謝!
微信關(guān)于接收事件推送不顯示問題
homedevise
2016-10-02 12:35:04