修复微信公众号token验证bug

master
星期八 5 years ago
parent 4d166b6b4f
commit 1b60971272
  1. 11
      src/main/java/com/lq/wechat/web/WechatController.java

@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -55,14 +56,20 @@ public class WechatController extends BaseController {
@RequestMapping(method = { RequestMethod.GET }, produces = "application/json;charset=UTF-8") @RequestMapping(method = { RequestMethod.GET }, produces = "application/json;charset=UTF-8")
@ResponseBody @ResponseBody
public String doget(String signature,String timestamp,String nonce,String echostr,String wechatOpenId) throws UnsupportedEncodingException { public String doget(String signature, String timestamp, String nonce, String echostr, String wechatOpenId, HttpServletResponse response) throws UnsupportedEncodingException {
if (StringUtil.isNotNull(wechatOpenId)){ if (StringUtil.isNotNull(wechatOpenId)){
//通过微信公众号名称查找公众号资料 //通过微信公众号名称查找公众号资料
WechatInfo wechatInfo = wechatInfoService.getByOpenId(wechatOpenId); WechatInfo wechatInfo = wechatInfoService.getByOpenId(wechatOpenId);
if (wechatInfo!=null){ if (wechatInfo!=null){
String token = wechatInfo.getToken(); String token = wechatInfo.getToken();
if (CheckUtil.checkSingatue(signature, timestamp, nonce,token)) { if (CheckUtil.checkSingatue(signature, timestamp, nonce,token)) {
return echostr; try {
response.getWriter().write(echostr);
}catch (Exception e){
e.printStackTrace();
}
return null;
} }
} }
} }

Loading…
Cancel
Save