新浪云應用sae的代碼里創建一個weixin.php文件,寫入以下代碼
-
define("TOKEN","myToken");// 后臺填寫的token,在微信公眾平臺啟用
-
$wechatObj = new wechatAPI();
-
$wechatObj->isValid();
-
class wechatAPI
-
{
-
public function isValid()//驗證微信接口,驗證函數以外的代碼和微信公眾號開發token設置相同
-
{
-
$echoStr = $_GET["echostr"];
-
if ($this->checkSignature()) {
-
header('content-type:text');//add,一定要加入header
-
echo $echoStr;
-
exit;
-
}
-
}
-
private function checkSignature() //官方的驗證函數
-
{
-
$signature = $_GET["signature"];
-
$timestamp = $_GET["timestamp"];
-
$nonce = $_GET["nonce"];
-
$token = TOKEN;
-
$tmpArr = array($token, $timestamp, $nonce);
-
sort($tmpArr, SORT_STRING);
-
$tmpStr = implode( $tmpArr );
-
$tmpStr = sha1( $tmpStr );
-
if( $tmpStr == $signature ){
-
return true;
-
}else{
-
return false;
-
}
-
}
-
};
保存后通過url訪問,在地址欄復制url,寫入微信公眾平臺中

在微信公眾平臺的開發設置中,填入以上獲得的url和設置的token,自動生成EncodingASEKey

設置完成

|