新浪云應(yīng)用sae的代碼里創(chuàng)建一個(gè)weixin.php文件,寫入以下代碼
-
define("TOKEN","myToken");// 后臺(tái)填寫的token,在微信公眾平臺(tái)啟用
-
$wechatObj = new wechatAPI();
-
$wechatObj->isValid();
-
class wechatAPI
-
{
-
public function isValid()//驗(yàn)證微信接口,驗(yàn)證函數(shù)以外的代碼和微信公眾號開發(fā)token設(shè)置相同
-
{
-
$echoStr = $_GET["echostr"];
-
if ($this->checkSignature()) {
-
header('content-type:text');//add,一定要加入header
-
echo $echoStr;
-
exit;
-
}
-
}
-
private function checkSignature() //官方的驗(yàn)證函數(shù)
-
{
-
$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訪問,在地址欄復(fù)制url,寫入微信公眾平臺(tái)中
在微信公眾平臺(tái)的開發(fā)設(shè)置中,填入以上獲得的url和設(shè)置的token,自動(dòng)生成EncodingASEKey
設(shè)置完成
|