收藏
回答

验证票据提示成功,一直收不到微信推送消系,还需要配置什么吗?

接收参数有问题吗?

回答关注问题邀请回答
收藏

1 个回答

  • stop eating
    stop eating
    03-13

    建议你把get post请求先分开,小程序客服、服务号回复消息都会推送到这上面,先把这基本的功能先走通了,再谈这个票据推送


    @RestController
    @RequestMapping("/hello")
    public class AuthController {
    
        @GetMapping(produces = MediaType.TEXT_PLAIN_VALUE)
        public String authGet(
                @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) {
            if (this.checkSignature(timestamp, nonce, signature)) {
                return echostr;
            }
            return "非法请求";
        }
    
        @PostMapping(produces = MediaType.APPLICATION_XML_VALUE)
        public String post(
                @RequestBody String requestBody,
                @RequestParam(name = "msg_signature", required = false) String msgSignature,
                @RequestParam(name = "encrypt_type", required = false) String encryptType,
                @RequestParam(name = "signature", required = false) String signature,
                @RequestParam("timestamp") String timestamp,
                @RequestParam("nonce") String nonce) throws Exception {
            if (!this.checkSignature(timestamp, nonce, signature)) {
                return "";
            }
            return "success";
        }
    
        private boolean checkSignature(String timestamp, String nonce, String signature) {
            String token = "hello";
            String[] arr = {token, timestamp, nonce};
            Arrays.sort(arr);
            StringBuilder stringBuilder = new StringBuilder();
            for (String a : arr) {
                stringBuilder.append(a);
            }
            return DigestUtils.sha1Hex(stringBuilder.toString()).equals(signature);
        }
    
    }
    


    03-13
    有用
    回复 4
    • 后来呢
      后来呢
      03-13
      好的,我试试,谢谢
      03-13
      回复
    • 后来呢
      后来呢
      03-13
      还是不行, 验证成功后我打的日志一直没出现
      03-13
      回复
    • stop eating
      stop eating
      03-13回复后来呢
      用postman测测 post接口
      03-13
      回复
    • 后来呢
      后来呢
      03-13
      可以调通, 就是配置启动后没有调我接口
      03-13
      回复
登录 后发表内容
问题标签