微信小程序 消息推送php服务器验证实例详解
微信文档(靠下有个“接入指引”):https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/callback_help.html
设置页面(“设置”“开发设置”):
https://mp.weixin.qq.com/wxopen/initprofile"https://hosts.com">https://hosts.com
注意http和https协议的不同。
2.设置消息推送
2.1 在你的服务器里添加服务器接口test.php,test.php接口内容主要是通过token验证消息是否为微信发来的,代码参照官方的例子:
define("TOKEN","xxxxx");/ 后台填写的token $wechatObj = new wechatAPI(); $wechatObj->isValid(); class wechatAPI { public function isValid()//验证微信接口,如果确认是微信就返回它传来的echostr参数 { $echoStr = $_GET["echostr"]; if ($this->checkSignature()) { 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; } } };
2.2 设置小程序后台消息推送相关信息
URL(服务器地址):https://hosts.com/xx/test.php
Token: 任意符合规范的字符串,如上面定义的"xxxxx"
EncodingAESKey(消息加密密钥):(随机生成,自己保存就好了,这个加解密才用)
消息加密方式:暂时选择明文,不用去考虑加密解密的问题。
数据格式:根据需求选择。
提交,如果没有问题就会成功了。(如果有问题你可以用假的数据通过浏览器测试)
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 【中国音乐】盛中国《新疆之春》2004[FLAC+CUE]
- 群星《音你而来 第8期》[320K/MP3][44.64MB]
- 群星《音你而来 第8期》[FLAC/分轨][121.21MB]
- 群星《十二女声Ⅲ》[WAV/CUE/分轨][626.4MB]
- 陈百强.1993-离不开...纪念歌集2CD【华纳】【WAV+CUE】
- 于台烟.2003-爱自己【乾坤唱片】【WAV+CUE】
- 群星.2024-我们永远是我们电影原声带【乐禾发文化】【FLAC分轨】
- 【中国民乐】张维良《秋江夜泊》2004[FLAC+CUE]
- 明达年度发烧碟MasterSuperiorAudiophile2011[DSF]
- 明达年度发烧碟MasterSuperiorAudiophile2017[DSF]
- 翁立友.2008-恨孤单【大旗】【WAV+CUE】
- 群星.2009-Magic.Cover日粤精华3CD【环球】【WAV+CUE】
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]