微信小程序获取用户信息
整体流程
- 前端调用微信登录接口获取code。官方接口文档
- 后端根据code调用微信登录凭证校验接口获取session_key 和 openid。官方接口文档
- 前端调用微信授权接口获取加密后的用户信息。官方接口文档
- 后端解密,获得用户具体信息。
根据临时登录凭证code获取 session_key 和 openid
使用spring boot中的RestTemplate来发送请求
public LoginResult doLogin(String code) {
// 登录接口地址
String url = WeChatConstant.LOGIN_BASE_URL +
"?appid=" + weChatAccountConfig.getAppId() +
"&secret=" + weChatAccountConfig.getAppSecret() +
"&js_code=" + code +
"&grant_type=" + WeChatConstant.GRANT_TYPE;
// url=https://api.weixin.