收藏
回答

基本配置 Token 验证失败 ?

操作时间:2021-03-06 00:13

1:测试账号流程全部走完,没有问题,

2:URL配置为调用后端获取菜单列表的接口

@GetMapping("/create")
public String menuCreateSample(@PathVariable String appid) throws WxErrorException, MalformedURLException {
    //校验信息
    WxMenu menu = menuInfoService.createMenu(appid);
    this.wxService.switchover(appid);
    return this.wxService.getMenuService().menuCreate(menu);
}


3:TOKEN配置和后端配置相同,域名为个人域名,端口80

4: 如果URL配置调用Token 校验正常。

@GetMapping(produces = "text/plain;charset=utf-8")
public String authGet(@PathVariable String appid,
                      @RequestParam(name = "signature", required = false) String signature,
                      @RequestParam(name = "timestamp", required = false) String timestamp,
                      @RequestParam(name = "nonce", required = false) String nonce,
                      @RequestParam(name = "echostr", required = false) String echostr) {

    log.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature,
            timestamp, nonce, echostr);
    if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
        throw new IllegalArgumentException("请求参数非法,请核实!");
    }

    if (!this.wxService.switchover(appid)) {
        throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
    }

    if (wxService.checkSignature(timestamp, nonce, signature)) {
        return echostr;
    }

    return "非法请求";
}
最后一次编辑于  03-06
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签