|
@@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.util.Map;
|
|
|
import java.util.Random;
|
|
@@ -59,7 +61,7 @@ public class WechatController {
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping(value = "token")
|
|
|
- public R checkFormWeixin(String signature, String timestamp, String nonce, String echostr, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ public void checkFormWeixin(String signature, String timestamp, String nonce, String echostr, HttpServletRequest request, HttpServletResponse response) {
|
|
|
log.info("处理来自微信的token请求验证");
|
|
|
// sha1加密1. 将token、timestamp、nonce三个参数进行字典序排序
|
|
|
// 2. 将三个参数字符串拼接成一个字符串进行sha1加密
|
|
@@ -69,7 +71,19 @@ public class WechatController {
|
|
|
throw new BusinessException(ResultCode.WECHAT_INVALID_REQUEST_ORIGIN.getDescription());
|
|
|
}
|
|
|
log.info("微信端随机数:" + echostr);
|
|
|
- return R.success(echostr);
|
|
|
+ PrintWriter out = null;
|
|
|
+ try {
|
|
|
+ out = response.getWriter();
|
|
|
+ out.print(echostr);
|
|
|
+ out.flush(); //这个地方必须画重点,消息推送配置Token令牌错误校验失败,搞了我很久,必须要刷新!!!!!!!
|
|
|
+ } catch ( IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("微信token验证异常" + e.getMessage());
|
|
|
+ throw new BusinessException(ResultCode.WECHAT_INVALID_REQUEST_ORIGIN.getDescription());
|
|
|
+ } finally {
|
|
|
+ out.close();
|
|
|
+ out = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|