- 首先你需要阅读一下这篇文档 微信开放文档
- 你需要去搞一个本地内网穿透,这样你就可以在本地进行调试你的代码。
我用的穿透工具是这个:natapp - 你还需要下载一个微信开发者工具 开发者工具下载,因为从手机上进行测试的话有时候微信会拦截你的URL,你就会收到如下一个页面。
一、使用拦截器判断用户是否近期登陆过项目假如登录过能取到session可以直接放行,假如没有就去微信拿openid,调用链接中有回调地址会进入项目中从后台调用取openid的链接。
-
/** * @author 梁XL * @description * @date 2020/1/20 */ public class UserInterceptor implements HandlerInterceptor { //在请求处理之前进行调用(Controller方法调用之前 @Override public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception { System.out.println("preHandle被调用"); // 校验 Object openid = httpServletRequest.getSession().getAttribute("openid"); // 判空 if(openid==null){ System.out.println("该次访问未获取到session中的openid"); //生成静默授权获取openid跳转链接 String url = "https://open.weixin.qq.com/connect/oauth2/aut