微信公众号的消息模式是这样的
订阅者将消息发送给微信Sever,微信Sever将这个消息转发给你配置的开发者Sever的接口文件上。
接口文件interface.php
//define your token
define("TOKEN", "your_token");
valid();
function valid()
{
$echoStr = $_GET["echostr"];
//valid signature
if (checkSignature()) {
echo $echoStr;//return 'echoStr'
exit;
}
}
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;
}
}