微信公众号 原样返回echostr 仍然验证失败的坑

博客作者在调试微信公众号API时遇到签名验证失败的问题,经过一番搜索和尝试,最终发现问题是由于`echostr`参数应为`Long`类型而非`Integer`。这个小细节在官方文档中未明确指出,导致了困扰。作者提醒开发者注意此细节,以免浪费不必要的时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

示例代码:

    @GetMapping("")
    public String checkSignature(@RequestParam(value = "timestamp") String timestamp,
                                 @RequestParam(value = "nonce") String nonce,
                                 @RequestParam(value = "signature") String signature,
                                 @RequestParam(value = "echostr") Integer echostr) {
        boolean result = wxMpService.checkSignature(timestamp, nonce, signature);
        if (result) {
            return echostr;
        } else {
            return "checkSignature error";
        }
    }

死活验证不过去,百度半天没人给出正确的解决办法。最后终于找到了解决办法,把echostr改成Long类型,验证成功

    @GetMapping("")
    public Long checkSignature(@RequestParam(value = "timestamp") String timestamp,
                               @RequestParam(value = "nonce") String nonce,
                               @RequestParam(value = "signature") String signature,
                               @RequestParam(value = "echostr") Long echostr) {
        boolean result = wxMpService.checkSignature(timestamp, nonce, signature);
        if (result) {
            return echostr;
        } else {
            return 0L;
        }
    }

 微信真的是坑啊,名字叫echostr,第一反应当然认为是一个字符串,结果是个数字???

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值