//token?驗證是通過的,但是關注事件的反饋不成功,查了幾遍代碼,改了幾個錯誤,還是不行。
<?php
class?IndexAction?extends?Action?{
????protected?function?_initialize()?{
????????header("Content-Type:text/html;?charset=utf-8");
????}
????public?function?index(){
//獲得參數?signature?nonce?token?timestamp?echostor
$nonce =$_GET['nonce'];
$token ='we';
$timestamp =$_GET['timestamp'];
$echostr =$_GET['echostr'];
$signature =$_GET['signature'];
//形成數組,然后按字典序排列
$array =array();
$array =array($nonce,$timestamp,$token);
sort($array);
//拼接成字符串,加密,然后與signature校驗
$str =sha1(implode($array));
if($str==$signature?&&?$echostr){
????????????//第一次介入微信API接口,之后就沒有$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'){//strtolower將字符串轉換成小寫形式
???????????//如果是關注事件subscribe?事件
????????????if(strtolower($postObj->Event?==?'subscribe')){
???????????? $toUser?=?$postObj->FromUserName;
???????????? $fromUser?=?$postObj->ToUserName;
????????????????$time?=?time();
????????????????$Msgtype?=?'text';
????????????????$Content?=?'歡迎關注我們的公眾賬號,zxy';
????????????????$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;
????????????}
????????}
????}
????
}
?>
2016-12-07
$postObj?=$simplexml_load_string($postArr);這個地方不對的
2016-08-15
同問啊!
2016-07-28
不知道哪里出問題了,關注了以后也不出現回復
2016-07-28
一樣啊,我也是這樣的問題每次this->reponseMsg();這個有錯誤
2015-12-05
補充:我查到是this->reponseMsg();這句有符號錯誤,然后改成了this.reponseMsg();這個時候符號錯誤沒有了,又出現說reponseMsg()函數未定義,我明明后面寫了public function reponseMsg(){}??!天啊,這是為什么?