1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 微信公众平台测试号管理接口配置信息配置失败

微信公众平台测试号管理接口配置信息配置失败

时间:2020-09-29 16:32:18

相关推荐

微信公众平台测试号管理接口配置信息配置失败

接口配置信息修改
请填写接口配置信息,此信息需要你有自己的服务器资源,填写的URL需要正确响应微信发送的Token验证,请阅读 消息接口使用指南。 URL http://sjjwx.nat300.top/wxSignatureCheck Token wxtoken

重点来了!!!

微信服务器会对我们填写的URL发送请求

如果我们的URL为http://sjjwx.nat300.top/wxSignatureCheck

那么,微信服务器就会发送如下请求

http://sjjwx.nat300.top/wxSignatureCheck?timestamp=1598322596602&signature=33f90dee6b86275b5851143d871d0122ef48cb0e&nonce=8588471354&echostr=c695cca1-8f36-403b-96e0-ffdac740b0ef

当返回结果为echostr的值时,就算调用成功了

c695cca1-8f36-403b-96e0-ffdac740b0ef

所以我们需要在自己的项目中写一个方法,提供给微信服务器调用

我是这么写的

controller

@RestControllerpublic class WxSignatureCheckController {@Autowiredprivate WxSignatureCheckService wxSignatureCheckService;@RequestMapping("/wxSignatureCheck")public String wxSignatureCheck(@RequestParam(value = "signature") String signature, @RequestParam(value = "timestamp") String timestamp,@RequestParam(value = "nonce") String nonce,@RequestParam(value = "echostr") String echostr){return wxSignatureCheckService.wxSignatureCheck(signature, timestamp, nonce, echostr);}}

service

import java.util.ArrayList;import java.util.Arrays;import org.springframework.stereotype.Service;import com.elven.member.util.Decript;@Servicepublic class WxSignatureCheckService {//tokenprivate final String token = "wxtoken";public String wxSignatureCheck(String signature, String timestamp, String nonce, String echostr) {ArrayList<String> array = new ArrayList<String>();array.add(signature);array.add(timestamp);array.add(nonce);//排序String sortString = sort(token, timestamp, nonce);//加密String mytoken = Decript.SHA1(sortString);//校验签名if (mytoken != null && mytoken != "" && mytoken.equals(signature)) {System.out.println("签名校验通过。");return echostr; //如果检验成功输出echostr,微信服务器接收到此输出,才会确认检验完成。} else {System.out.println("签名校验失败。");return null;}}/*** 排序方法* @param token* @param timestamp* @param nonce* @return*/public static String sort(String token, String timestamp, String nonce) {String[] strArray = {token, timestamp, nonce };Arrays.sort(strArray);StringBuilder sbuilder = new StringBuilder();for (String str : strArray) {sbuilder.append(str);}return sbuilder.toString();}}

Decript

import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;/*** 加密的方法:* @author shao* @date 8月25日 上午10:03:50*/public class Decript {public static String SHA1(String decript) {try {MessageDigest digest = MessageDigest.getInstance("SHA-1");digest.update(decript.getBytes());byte messageDigest[] = digest.digest();// Create Hex StringStringBuffer hexString = new StringBuffer();// 字节数组转换为 十六进制 数for (int i = 0; i < messageDigest.length; i++) {String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);if (shaHex.length() < 2) {hexString.append(0);}hexString.append(shaHex);}return hexString.toString();} catch (NoSuchAlgorithmException e) {e.printStackTrace();}return "";}}

关于本地项目如何做内网穿透

使用 Natapp:/

管理控制台:/tunnel/lists

NATAPP1分钟快速新手图文教程:/article/natapp_newbie

用Natapp(ngrok)进行微信本地开发调试:/article/wechat_local_debug

使用本地配置文件config.ini

下载config.ini:/article/config_ini

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。