扫描小程序码分享
https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Message_Encryption/Message_encryption_and_decryption.html
开发者可以在微信公众平台接口调试工具,在接口类型中选择“消息接口调试”,并选择安全模式的加密调试,进行消息加解密的在线调试。
微信公众平台接口调试工具:https://mp.weixin.qq.com/debug
11 个评论
加粗
标红
插入代码
插入链接
插入图片
上传视频
调试完了呢;会怎么样;我调试好了;还是提示:Token校验失败,请检查确认
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
被经验坑了
小程序这里不要回复success
需要回复地址栏附带的echostr
也就是$_GET['echostr']
//小程序通知
public function notify(){
echo $_GET['echostr'];
}
实际测试下来,确实是因为业务代码处理没有做好导致,不过这个提示页太魔幻了!提供一下我的代码片段供大家参考
//接收微信小程序发送的消息(接入验证用) public void receiveAppletMessage(HttpServletRequest request, HttpServletResponse response) throws Exception { //signature:签名 String signature = request.getParameter("signature"); String timestamp = request.getParameter("timestamp"); String nonce = request.getParameter("nonce"); String echostr = request.getParameter("echostr"); String token = weChatProperties.getReceiveMessageAppToken(); log.info("收到消息配置验证参数:{}/{}/{}/{}", signature, timestamp, nonce, echostr); //进行验证 if(verifySignature(signature, token, timestamp, nonce)){ response.setContentType("text/plain"); response.getWriter().print(echostr); }else{ response.getWriter().print("Verification failed"); } } //微信小程序验证消息 private boolean verifySignature(String signature, String token, String timestamp, String nonce) { String[] arr = new String[]{token, timestamp, nonce}; //处理规则 Arrays.sort(arr); StringBuilder sb = new StringBuilder(); for (String s : arr) { sb.append(s); } //解析字符串 String localSign = sha1(sb.toString()); log.info("解析结果:{}", localSign); //判断返回 if (signature.equals(localSign)) { return true; }else{ return false; } } // SHA1加密工具方法 private static String sha1(String input) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] digest = md.digest(input.getBytes()); StringBuilder hexStr = new StringBuilder(); for (byte b : digest) { hexStr.append(String.format("%02x", b)); // 转为16进制 } return hexStr.toString(); } catch (Exception e) { throw new RuntimeException("SHA1 encryption failed", e); } }
同样 token 有问题
这些参数改怎么填写呢
帖子和问题毫不相关,我们问的问题是https://developers.weixin.qq.com/community/develop/doc/0004e2be044b9884d6d28471161800?fromCreate=1
无法使用json的安全模式和兼容模式。点击回出现,请求地址:undefined。json的明文模式和xml的三个模式都能用
有用吗
怎么解决超时问题的大佬?访问一直提示超时!!
使用curl、postman、浏览器公网访问一切正常,小程序后台点击验证收不到微信的请求。
Token校验失败,请检查确认? - 微信开放社区 https://developers.weixin.qq.com/community/develop/doc/000e08020b0328211acf99a3056800
正在加载...
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
调试完了呢;会怎么样;我调试好了;还是提示:Token校验失败,请检查确认
被经验坑了
小程序这里不要回复success
也就是$_GET['echostr']
//小程序通知
public function notify(){
echo $_GET['echostr'];
}
实际测试下来,确实是因为业务代码处理没有做好导致,不过这个提示页太魔幻了!提供一下我的代码片段供大家参考
//接收微信小程序发送的消息(接入验证用) public void receiveAppletMessage(HttpServletRequest request, HttpServletResponse response) throws Exception { //signature:签名 String signature = request.getParameter("signature"); String timestamp = request.getParameter("timestamp"); String nonce = request.getParameter("nonce"); String echostr = request.getParameter("echostr"); String token = weChatProperties.getReceiveMessageAppToken(); log.info("收到消息配置验证参数:{}/{}/{}/{}", signature, timestamp, nonce, echostr); //进行验证 if(verifySignature(signature, token, timestamp, nonce)){ response.setContentType("text/plain"); response.getWriter().print(echostr); }else{ response.getWriter().print("Verification failed"); } } //微信小程序验证消息 private boolean verifySignature(String signature, String token, String timestamp, String nonce) { String[] arr = new String[]{token, timestamp, nonce}; //处理规则 Arrays.sort(arr); StringBuilder sb = new StringBuilder(); for (String s : arr) { sb.append(s); } //解析字符串 String localSign = sha1(sb.toString()); log.info("解析结果:{}", localSign); //判断返回 if (signature.equals(localSign)) { return true; }else{ return false; } } // SHA1加密工具方法 private static String sha1(String input) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] digest = md.digest(input.getBytes()); StringBuilder hexStr = new StringBuilder(); for (byte b : digest) { hexStr.append(String.format("%02x", b)); // 转为16进制 } return hexStr.toString(); } catch (Exception e) { throw new RuntimeException("SHA1 encryption failed", e); } }
同样 token 有问题
这些参数改怎么填写呢
帖子和问题毫不相关,我们问的问题是https://developers.weixin.qq.com/community/develop/doc/0004e2be044b9884d6d28471161800?fromCreate=1
无法使用json的安全模式和兼容模式。点击回出现,请求地址:undefined。json的明文模式和xml的三个模式都能用
有用吗
怎么解决超时问题的大佬?访问一直提示超时!!
使用curl、postman、浏览器公网访问一切正常,小程序后台点击验证收不到微信的请求。
Token校验失败,请检查确认? - 微信开放社区 https://developers.weixin.qq.com/community/develop/doc/000e08020b0328211acf99a3056800