微信公衆號的消息模式是這樣的
訂閱者將消息發送給微信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;
}
}