一、创建网站应用
1. 在微信开发平台上面创建以个网站应用
2. 微信开发平台地址 https://open.weixin.qq.com/https://open.weixin.qq.com/
二、配置基本信息
1. 把公用的信息放在application.yml中
#微信开放平台创建的网站应用的appid
AppID: *********
#微信开放平台创建的网站应用的appsecret
AppSecret: ***********************************
scope: snsapi_login
#微信开放平台创建的网站 设置的授权回调域
redirect_url: 自己的回调地址,必须是公网能够访问的
2. 获取微信二维码信息
@Value("${AppID}") private String appid; @Value("${redirect_url}") private String callBack; @Value("${scope}") private String scope; @Value("${AppSecret}") private String appsecret; @Override public String getWechatCode() { try { String oauthUrl = "https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect"; String redirect_uri = URLEncoder.encode(callBack, "utf-8"); oauthUrl = oauthUrl.replace("APPID",appid).replace("REDIRECT_URI",redirect_uri).replace("SCOPE",scope); logger.info(oauthUrl); return ReturnMessage.success(0,"获取完成",oauthUrl); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return ReturnMessage.fail(44,"失败"); }
备注:在前端页面直接加载oauthUrl 就可以出现二维码界面了。直接用的微信的页面,也可以根据自己的爱好进行设计页面。如下图
3. 接收扫码之后的信息