cn.binarywang.wx.miniapp.api.WxMaService.checkSignature()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(201)

本文整理了Java中cn.binarywang.wx.miniapp.api.WxMaService.checkSignature()方法的一些代码示例,展示了WxMaService.checkSignature()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WxMaService.checkSignature()方法的具体详情如下:
包路径:cn.binarywang.wx.miniapp.api.WxMaService
类名称:WxMaService
方法名:checkSignature

WxMaService.checkSignature介绍

[英]```
验证消息的确来自微信服务器.
详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319&token=&lang=zh_CN

  1. [中]```
  2. 验证消息的确来自微信服务器.
  3. 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319&token=&lang=zh_CN

代码示例

代码示例来源:origin: ustcwudi/springboot-seed

  1. @GetMapping(produces = "text/plain;charset=utf-8" )
  2. public String authGet(@RequestParam(name = "signature", required = false) String signature,
  3. @RequestParam(name = "timestamp", required = false) String timestamp,
  4. @RequestParam(name = "nonce", required = false) String nonce,
  5. @RequestParam(name = "echostr", required = false) String echostr) {
  6. if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
  7. throw new IllegalArgumentException("invalid argument" );
  8. }
  9. if (this.wxService.checkSignature(timestamp, nonce, signature)) {
  10. return echostr;
  11. }
  12. return "非法请求";
  13. }

代码示例来源:origin: binarywang/weixin-java-miniapp-demo

  1. @GetMapping(produces = "text/plain;charset=utf-8")
  2. public String authGet(@PathVariable String appid,
  3. @RequestParam(name = "signature", required = false) String signature,
  4. @RequestParam(name = "timestamp", required = false) String timestamp,
  5. @RequestParam(name = "nonce", required = false) String nonce,
  6. @RequestParam(name = "echostr", required = false) String echostr) {
  7. this.logger.info("\n接收到来自微信服务器的认证消息:signature = [{}], timestamp = [{}], nonce = [{}], echostr = [{}]",
  8. signature, timestamp, nonce, echostr);
  9. if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
  10. throw new IllegalArgumentException("请求参数非法,请核实!");
  11. }
  12. final WxMaService wxService = WxMaConfiguration.getMaService(appid);
  13. if (wxService.checkSignature(timestamp, nonce, signature)) {
  14. return echostr;
  15. }
  16. return "非法请求";
  17. }

相关文章