注册微信公众平台后要成为开发者,token可以随意定义,url输入的不行就通过不了,会提示url超时,或者你的服务器没有正确响应Token验证,请阅读消息接口使用指南,下面你要有你的主机,写一个php文件,内容如下,将此php文件的url地址写上就ok了
<?php
define ( "TOKEN", "dismath" );
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"]; //随机字符串
if($this->checkSignature()){
echo $echoStr;
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;
}
}
}