在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/PHP  網(wǎng)絡(luò)營銷/ 微信公眾號死活無法回復(fù)信息,求指點!

微信公眾號死活無法回復(fù)信息,求指點!

剛開始學(xué)習(xí)公眾號開發(fā),按照慕課網(wǎng)的教程,前面服務(wù)器驗證部分已經(jīng)成功,后面回復(fù)信息部分怎么調(diào)在微信上都無法收到回復(fù)信息,求大神幫忙看看哪兒有問題,感激不盡!

<?php
//以下為服務(wù)器驗證,已經(jīng)驗證成功
//1. 排序
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$token = 'weixin';
$signature = $_GET['signature'];
$array = array($timestamp,$nonce,$token);
sort($array);

//2. 加密
$tmpstr = implode('',$array);
$tmpstr = sha1($tmpstr);

//3. 對比
if ($tmpstr == $signature AND $_GET['echostr']) {
echo $_GET['echostr'];
exit;
}else{
responseMsg();
}

//以下是回復(fù)信息的部分,實在不知道為什么沒有反應(yīng)

public function responseMsg(){
    $postArr = $GLOBALS['HTTP_RAW_POST_DATA'];
    $postObj = simplexml_load_string($postArr);
    
    if (strtolower($postObj->MsgType) == 'event'){
        if (strtolower($postObj->Event) == 'subscribe'){
        
            $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;
        }
    }
}
?>
回答
編輯回答
綰青絲

if后面的else去掉,直接調(diào)用那個函數(shù)就行了!

2018年4月13日 03:24
編輯回答
艷骨

樓主你那個回復(fù)消息的函數(shù)寫錯位置了,不應(yīng)該寫在3.對比里面的else,應(yīng)該寫在服務(wù)器驗證部分的后面

2018年1月22日 00:37
編輯回答
執(zhí)念

非常感謝兩位的幫助,后面我發(fā)現(xiàn),錯誤的原因是回復(fù)模板里面的嘆號兩邊各多了一個空格,導(dǎo)致無法回復(fù)成功。。。。。感謝兩位!

2018年4月17日 09:20