您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

微信小程序 消息推送php服务器验证实例详解

2024/3/28 15:32:24发布21次查看
这篇文章主要介绍了微信小程序 消息推送php服务器验证实例详解的相关资料,需要的朋友可以参考下
微信小程序 消息推送php服务器验证实例详解
微信文档(靠下有个“接入指引”):https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/callback_help.html
设置页面(“设置”>>“开发设置”):
https://mp.weixin.qq.com/wxopen/initprofile?action=home&lang=zh_cn
1.设置服务器域名
比如: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(消息加密密钥):(随机生成,自己保存就好了,这个加解密才用)
消息加密方式:暂时选择明文,不用去考虑加密解密的问题。
数据格式:根据需求选择。
提交,如果没有问题就会成功了。(如果有问题你可以用假的数据通过浏览器测试)
以上就是微信小程序 消息推送php服务器验证实例详解的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product