自己的服务器为什么接受不到微信后台发送过来的信息呢 。
急急急,请微信开发的大侠帮忙啊!提交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><!]></ToUserName>
<FromUserName><!]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><!]></MsgType>
<Content><!]></Content>
</xml>";
$resultStr=sprintf($retTmp,$fromUserName,$toUserName,time(),$retMsg);
echo $resultStr;
?>
从你的代码来看,应该是没有通过签名验证,即checkSignature()方法返回了false。你把你2次的签名都打印出来看看,然后再调试吧。 验证成功之后可以把验证函数删掉了
自己写返回就好,你的代码我扫了一眼
你看看我写的文章吧:lol
http://my.oschina.net/lampdraem/blog/174658
页:
[1]