相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- PHP中opcode緩存簡(jiǎn)單用法分析
- thinkPHP控制器變量在模板中的顯示方法示例
- PHP move_uploaded_file() 函數(shù)(將上傳的文件移動(dòng)到新位置)
- dirname(__FILE__)的含義和應(yīng)用說(shuō)明
- thinkPHP5框架實(shí)現(xiàn)分頁(yè)查詢功能的方法示例
- PHP中單雙號(hào)與變量
- PHP獲得當(dāng)日零點(diǎn)時(shí)間戳的方法分析
- Laravel ORM對(duì)Model::find方法進(jìn)行緩存示例詳解
- PHP讀寫文件高并發(fā)處理操作實(shí)例詳解
- 【CLI】利用Curl下載文件實(shí)時(shí)進(jìn)度條顯示的實(shí)現(xiàn)
微信小程序 消息推送php服務(wù)器驗(yàn)證實(shí)例詳解
微信小程序 消息推送php服務(wù)器驗(yàn)證實(shí)例詳解
微信文檔(靠下有個(gè)“接入指引”):https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/callback_help.html
設(shè)置頁(yè)面(“設(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)容主要是通過(guò)token驗(yàn)證消息是否為微信發(fā)來(lái)的,代碼參照官方的例子:
define("TOKEN","xxxxx");/ 后臺(tái)填寫的token $wechatObj = new wechatAPI(); $wechatObj->isValid(); class wechatAPI { public function isValid()//驗(yàn)證微信接口,如果確認(rèn)是微信就返回它傳來(lái)的echostr參數(shù) { $echoStr = $_GET["echostr"]; if ($this->checkSignature()) { 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; } } };