小程序
小游戏
企业微信
微信支付
扫描小程序码分享
https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Getting_Started_Guide.html
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
微信回调上面的第一个接口是只调一次还是多次,
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
package com.example.demo.controller; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.apache.commons.codec.digest.DigestUtils; import java.util.Arrays; @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); } }
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
微信回调上面的第一个接口是只调一次还是多次,
package com.example.demo.controller; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.apache.commons.codec.digest.DigestUtils; import java.util.Arrays; @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); } }