|
急急急,请微信开发的大侠帮忙啊!
提交URL和TOKEN之后,提示的是提交成功了.我的URL是http://219.229.132.204/wang/echo_test.php
echo_test.php实现的功能是把用户输入的文本信息重新返回给用户(只是简单的测试)
echo_test.php的代码是如下,加入一个输出函数是为了测试。然后给公众平台输入一个文本,例如:“我们”,微信上没有任何的反映。测试输出,居然是checkSignature is wrong ,这是怎么回事,不是验证成功了吗?
<?php
define("TOKEN","mytoken");
function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature )
{
return true;
}
else{
return false;
}
}
function echo_server_log($log)
{
file_put_contents("log.txt", $log,FILE_APPEND);
}
if(false==checkSignature())
{
echo_server_log("checkSignature is wrong \n");
exit(0);
}
$echostr=$_GET['echostr'];
if($echostr)
{
echo echostr;
exit (0);
}
$PostData=file_get_contents("php://input");
if(!$PostData)
{
echo_server_log("wrong input! PostData is NULL\n");
echo "wrong input!";
exit(0);
}
$xmlObj=simplexml_load_string($PostData,'SimpleXMLElement',LIBXML_NOCDATA);
if(!$xmlObj)
{
echo_server_log("wrong input! xmlObj is NULL\n");
echo "wrong input!";
exit(0);
}
$fromUserName=$xmlObj->FromUserName;
$toUserName=$xmlObj->ToUserName;
$msgType=$xmlObj->MsgType;
if('text'!=$msgType)
{
$retMsg='只支持文本消息';
}
else
{
$content=$xmlObj->Content;
$retMsg=$content;
}
$retTmp=" <xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$resultStr=sprintf($retTmp,$fromUserName,$toUserName,time(),$retMsg);
echo $resultStr;
?>
|
|