相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
微信小程序 消息推送php服務(wù)器驗證實例詳解
微信小程序 消息推送php服務(wù)器驗證實例詳解
微信文檔(靠下有個“接入指引”):https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/callback_help.html
設(shè)置頁面(“設(shè)置”>>“開發(fā)設(shè)置”):
https://mp.weixin.qq.com/wxopen/initprofile?action=home&lang=zh_CN
1.設(shè)置服務(wù)器域名
比如:https://hosts.com
注意http和https協(xié)議的不同。
2.設(shè)置消息推送
2.1 在你的服務(wù)器里添加服務(wù)器接口test.php,test.php接口內(nèi)容主要是通過token驗證消息是否為微信發(fā)來的,代碼參照官方的例子:
define("TOKEN","xxxxx");/ 后臺填寫的token $wechatObj = new wechatAPI(); $wechatObj->isValid(); class wechatAPI { public function isValid()//驗證微信接口,如果確認是微信就返回它傳來的echostr參數(shù) { $echoStr = $_GET["echostr"]; if ($this->checkSignature()) { echo $echoStr; exit; } } private function checkSignature() //官方的驗證函數(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; } } };