java 网页授权获取微信用户信息错误 40029 微信端会发出两次请求 错误的oauth第二次无效的code
来源:互联网 发布:php淘宝短网址还原 编辑:程序博客网 时间:2024/05/20 05:45
使用一个最笨的办法就是多设置几个全局变量通过对比是微信端发出的第二次请求无效
直接上代码了
@Controllerpublic class CoreController {@AutowiredCoreService coreService;@Value("${projecturl}")String projecturl;String openId = null;String bleancode="false";// 第三方用户唯一凭证@Value("${appId}")String appId;// 第三方用户唯一凭证密钥@Value("${appSecret}")String appSecret;// 模板id@Value("${TemplateId}")String templateId;// 通知url@Value("${tzurl}")String tzurl;@Value("${mydb}")String mydb;// 增加日志private static Logger log = LoggerFactory.getLogger(CoreController.class);// 验证是否来自微信服务器的消息@RequestMapping(value = "/", method = RequestMethod.GET)@ResponseBodypublic String checkSignature(@RequestParam(name = "signature", required = false) String signature,@RequestParam(name = "nonce", required = false) String nonce,@RequestParam(name = "timestamp", required = false) String timestamp,@RequestParam(name = "echostr", required = false) String echostr) {// 通过检验signature对请求进行校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败if (SignUtil.checkSignature(signature, timestamp, nonce)) {log.info("接入成功");return echostr;}log.error("接入失败");return "";}// 调用核心业务类接收消息、处理消息跟推送消息@RequestMapping(value = "/", method = RequestMethod.POST)@ResponseBodypublic String post(HttpServletRequest req) throws UnsupportedEncodingException {req.setCharacterEncoding("UTF-8");req.setCharacterEncoding("UTF-8");String respMessage = coreService.processRequest(req);return respMessage;}@RequestMapping({ "/oath" })public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");// 用户同意授权后,能获取到codeString code = request.getParameter("code");if (bleancode.equals("false")||(!bleancode.equals(code))) {bleancode=code;// 用户同意授权if (!"authdeny".equals(code)) {// 获取网页授权access_tokenWeixinOauth2Token weixinOauth2Token = AdvancedUtil.getOauth2AccessToken(appId, appSecret, code);// 用户标识openId = weixinOauth2Token.getOpenId();System.out.println(openId);}}if (coreService.isuser(openId).size()>0) {response.sendRedirect(projecturl + "&openid=" + openId);return;} else {request.getRequestDispatcher("/xmbd?openid=" + openId).forward(request, response);}}
阅读全文
0 0
- java 网页授权获取微信用户信息错误 40029 微信端会发出两次请求 错误的oauth第二次无效的code
- 网页授权获取微信用户信息错误40029:微信会发出两次提交 不合法的oauth_code
- 微信网页授权获取code值回调两次的问题
- 微信开发(七)微信网页授权( Oauth )通过Oauth获取用户信息
- Java微信网页授权获取用户信息 微信分享
- 微信网页授权获取用户信息 返回{"errcode":40066,"errmsg":"invalid url hint: [FZbxRA0556sz12!]"}错误
- 微信网页授权,获取微信code,获取access_tocken,获取用户信息
- 微信网页授权—获取用户信息
- 微信网页授权(获取用户信息)
- 微信网页授权后台获取用户信息
- 微信开发-网页授权获取用户信息
- 微信网页授权及获取用户信息
- 微信公众号开发-微信网页授权获取用户openid以及用户信息的步骤
- 微信公众号开发-微信网页授权获取用户openid以及用户信息的步骤
- 支付宝网页授权获取用户信息 网页获取用户信息的
- 基于Springboot的微信公众号接入、通过网页授权机制获取用户信息
- 微信网页授权登陆的一次查错误经历
- java通过微信授权获取用户信息
- RocketMQ消息类型
- Ubuntu16.04下编译OpenCV3.0.0
- 【Vue】5.vue mock数据(模拟后台)
- linux安装JDK,Maven,intellij IDEA
- <context:include-filter>和<context:exclude-filter>
- java 网页授权获取微信用户信息错误 40029 微信端会发出两次请求 错误的oauth第二次无效的code
- Android-框架-The Clean Architecture
- hibernate插入数据到mysql数据库中乱码问题
- 判断网络的工具类
- JAVA课程学习十:继承训练
- 如何在 Azure 中均衡 Linux 虚拟机负载以创建高可用性应用程序
- Windows10专业版系统镜镜像
- Android 备份(提取)apk
- 块元素、内联元素、内联块特性