获取服务器信息
https://yourdomain.com/api/wechat
。环境要求
登录公众平台后台
进入账号的“开发-基本配置”页面,点击“修改配置”按钮。
填写服务器信息
提交并验证服务器
点击“提交”后,公众平台会向填写的URL发送一个GET请求,携带以下参数:
signature=xxx×tamp=xxx&nonce=xxx&echostr=xxx
signature
比对,一致则返回echostr
明文。代码示例(PHP):
$token = "YOUR_TOKEN"; $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $echostr = $_GET["echostr"]; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode($tmpArr); $hashCode = sha1($tmpStr); if ($hashCode == $signature) { echo $echostr; exit; }
验证失败
%20
)。消息加解密异常
WXBizMsgCrypt
)。后续消息推送失败
参考资料