I just started to learn the development of official account. According to the tutorials of Mutu.com, the previous server verification part has been successful, and the latter reply part can not be received on Wechat. I would like to ask God for help to see where there is a problem. Thank you very much!
<?php
//
//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();
}
//
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 = "";
$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;
}
}
}
?>