幫我看一下代碼哪兒錯了 關(guān)注后沒有回復(fù)消息
<?php
class wei{
? ?public function index(){
? ? ? ?$timestamp = $_GET['timestamp'];
? ? ? ?$token ? ? = '15228990111';
? ? ? ?$nonce ? ? = $_GET['nonce'];
? ? ? ?$signature = $_GET['signature'];
? ? ? ?$echostr ? = $_GET['echostr'];
? ? ? ?$array=array($nonce,$timestamp,$token);
? ? ? ?sort($array);
? ? ? ?$str=implode('',$array);
? ? ? ?$str=sha1($str);
? ? ? ?if($str == $signature && $echostr){
? ? ? ? ? ?echo $echostr;
? ? ? ? ? ?exit;
? ? ? ?}else{
? ? ? ? ? ?$this->info();
? ? ? ?}
? ?}
? ?public function info(){
? ? ? ?//獲得微信推送過來的 POST 數(shù)據(jù)
? ? ? ?$postArr = $GLOBALS['HTTP_RAW_POST_DATA'];
? ? ? ?//處理消息類型 XML格式轉(zhuǎn)換,并設(shè)置回復(fù)類型和內(nèi)容
? ? ? ?$postObj=simplexml_load_string( $postArr );
// ? ? ? ?$postObj->ToUserName='';
// ? ? ? ?$postObj->FromUserName='';
// ? ? ? ?$postObj->CreateTime='';
// ? ? ? ?$postObj->MsgType='';
// ? ? ? ?$postObj->Event='';
? ? ? ?//判斷該數(shù)據(jù)是否是訂閱事件
? ? ? ?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)注我們的微信公眾號';
? ? ? ? ? ? ? ?$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;
? ? ? ? ? ?}
? ? ? ?}
? ?}
}
$wei=new wei();
$wei->index();
2017-12-25
你那有個小寫 TO? to改成To
2017-03-23
我是按照官方的文檔里的demo寫的,你最好還是用官方的試一試,改幾個參數(shù)就行。然后在原有的基礎(chǔ)上做其他的東西