收藏
回答

token效验失败什么原因?

token效验失败什么原因?

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

1 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-03-12

    token校验失败,就是校验失败,字面意思。

    @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);
        }
    
    }
    
    2020-03-12
    有用
    回复 24
    • XIN
      XIN
      2020-03-13
      这是我写的服务器接口https://m.bao315.com/api/fet/owner/wXBizMsg  java的  大神能帮我看看哪里出问题吗?
      2020-03-13
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-03-13回复XIN
      只需要returnechostr
      2020-03-13
      回复
    • XIN
      XIN
      2020-03-13回复Mr.Zhao
      我写的就是只return echostr的  token还是验证失败
      2020-03-13
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-03-13回复XIN
      你写的并不是啊
      2020-03-13
      回复
    • XIN
      XIN
      2020-03-13回复Mr.Zhao
      就是这个是一个java程序员写的  他说他就是只返回了echostr  现在都不知道怎么弄了
      2020-03-13
      回复
    查看更多(19)
登录 后发表内容
问题标签