转自:点击打开链接
http://lvwenhan.com/create/372.html
实质:就是使用官方文件,调用
$wechatObj->valid();<p>而不是,注释后,调用:</p><pre class="brush:php;toolbar:false;" andale mono overflow:auto font-size:13px padding:1em line-height:1.42857143 color:rgb word-break:normal word-wrap:normal border:1px dashed rgb direction:ltr margin-top:1.2em margin-bottom:1.2em background:rgb>$wechatObj->responseMsg();<h2helvetica neue sans gb w3 micro hei yahei ui line-height:38px color:rgb margin-top:20px margin-bottom:18px font-size:24px margin-left:0px letter-spacing:1px text-align:center>关于微信公共平台"你的服务未能正确响应Token验证"错误的解决办法<pre class="brush:php;toolbar:false;" andale mono overflow:auto font-size:13px padding:1em line-height:1.42857143 color:rgb word-break:normal word-wrap:normal border:1px dashed rgb direction:ltr margin-top:1.2em margin-bottom:1.2em background:rgb><?php /**
* wechat php test
*/
//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
//valid signature , option
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
public function responseMsg()
{
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//extract post data
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml><tousername></tousername><fromusername></fromusername><createtime>%s</createtime><msgtype></msgtype><content></content><funcflag>0</funcflag></xml>";
if(!empty( $keyword ))
{
$msgType = "text";
$contentStr = "Welcome to wechat world!";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}else{
echo "Input something...";
}
}else {
echo "";
exit;
}
}
private 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;
}
}
}
?><phelvetica neue sans gb w3 micro hei yahei ui margin-top:0px margin-bottom:10px color:rgb font-size:16px line-height:25.6000003814697px> <phelvetica neue sans gb w3 micro hei yahei ui margin-top:0px margin-bottom:10px color:rgb font-size:16px line-height:25.6000003814697px>以上为腾讯官方提供的接口文件示例。<phelvetica neue sans gb w3 micro hei yahei ui margin-top:0px margin-bottom:10px color:rgb font-size:16px line-height:25.6000003814697px>解决问题其实很简单,微信文档貌似没写(或者我没找到==):<phelvetica neue sans gb w3 micro hei yahei ui margin-top:0px margin-bottom:10px color:rgb font-size:16px line-height:25.6000003814697px> <br><h3helvetica neue sans gb w3 micro hei yahei ui line-height:1.6em color:rgb margin-top:20px margin-bottom:10px font-size:18px margin-left:0px>验证token时使用:<pre class="brush:php;toolbar:false;" andale mono overflow:auto font-size:13px padding:1em line-height:1.42857143 color:rgb word-break:normal word-wrap:normal border:1px dashed rgb direction:ltr margin-top:1.2em margin-bottom:1.2em background:rgb>$wechatObj->valid();
<h3helvetica neue sans gb w3 micro hei yahei ui line-height:1.6em color:rgb margin-top:20px margin-bottom:10px font-size:18px margin-left:0px>正式生产环境中需要回复用户消息时,使用:<phelvetica neue sans gb w3 micro hei yahei ui margin-top:0px margin-bottom:10px color:rgb font-size:16px line-height:25.6000003814697px><pre class="brush:php;toolbar:false;" andale mono overflow:auto font-size:13px padding:1em line-height:1.42857143 color:rgb word-break:normal word-wrap:normal border:1px dashed rgb direction:ltr margin-top:1.2em margin-bottom:1.2em background:rgb>$wechatObj->responseMsg();
<phelvetica neue sans gb w3 micro hei yahei ui margin-top:0px margin-bottom:10px color:rgb font-size:16px line-height:25.6000003814697px><phelvetica neue sans gb w3 micro hei yahei ui margin-top:0px margin-bottom:10px color:rgb font-size:16px line-height:25.6000003814697px><br><phelvetica neue sans gb w3 micro hei yahei ui margin-top:0px margin-bottom:10px color:rgb font-size:16px line-height:25.6000003814697px>问题解决。<br><p>
以上就介绍了关于微信公共平台"你的服务未能正确响应Token验证"错误的解决办法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。</p>
<p>
</p>
</phelvetica></phelvetica></phelvetica>











