<?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數據(xml格式)
?????$postArr?=?$GLOBALS('HTTP_RAW_POST_DATA');
?????//2.處理消息類型,并設置回復類型和內容
?????$postObj?=?simplexml_load_string($postArr);//轉化成對象
?????//$postObj->ToUserName='';
?????//$postObj->FromUserName='';
?????//$postObj->CreateTime?='';
?????//$postObj->MsgType='';
?????//$postObj->Event='';
?????//判斷該數據包是否是訂閱的時間推送
?????if(?strtolower(?$postObj->MsgType)?==?'event'){
?????????//如果是關注subscribe事件
?????????if(?strtolower($postObj->Event?==?'subscribe')?){
?????????????//回復用戶消息
????????? $toUser????=?$postObj->FromUserName;
????????? $fromUser??=?$postObj->toUserName;
????????? $time??????=?time();
????????? $msgType???=?'text';
????????? $content???=?'歡迎關注我們的微信公眾賬號';
????????? $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);
?????????}
?????}
????}
}首先微信中服務器配置已經更改為自己的了,token也改了。但在啟用服務器配置并訂閱后什么推送消息都沒有,輸入zhongmei后也沒有返回值,只返回該公眾號暫時無法提供服務,請稍后再試。請幫忙看看哪里出問題了,謝謝!
微信關于接收事件推送不顯示問題
homedevise
2016-10-02 12:35:04