openId获取修改
This commit is contained in:
@@ -40,7 +40,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
|||||||
log.info(code);
|
log.info(code);
|
||||||
String openId;
|
String openId;
|
||||||
if (UserAuthSourceEnum.WECHAT.getValue().equals(source)) {
|
if (UserAuthSourceEnum.WECHAT.getValue().equals(source)) {
|
||||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(code, true);
|
openId = wechatAuthUtil.getAccountOpenId(code);
|
||||||
}else {
|
}else {
|
||||||
openId = alipayUtil.getOpenId(code, true);
|
openId = alipayUtil.getOpenId(code, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,25 @@ public class WechatAuthUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAccountOpenId(String code) {
|
||||||
|
String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?";
|
||||||
|
Map<String, Object> requestUrlParam = new HashMap<>();
|
||||||
|
// https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN
|
||||||
|
//小程序appId
|
||||||
|
requestUrlParam.put("appid", accountAppId);
|
||||||
|
//小程序secret
|
||||||
|
requestUrlParam.put("secret", accountSecrete);
|
||||||
|
//小程序端返回的code
|
||||||
|
requestUrlParam.put("code", code);
|
||||||
|
//默认参数
|
||||||
|
requestUrlParam.put("grant_type", "authorization_code");
|
||||||
|
log.info("微信获取openid请求报文:{}", requestUrlParam);
|
||||||
|
//发送post请求读取调用微信接口获取openid用户唯一标识
|
||||||
|
String resp = HttpUtil.post(requestUrl, requestUrlParam);
|
||||||
|
log.info("响应报文{}", resp);
|
||||||
|
return JSONObject.parseObject(resp).getString("openid");
|
||||||
|
}
|
||||||
|
|
||||||
public String getSessionKeyOrOpenId(String code, boolean isAccount) {
|
public String getSessionKeyOrOpenId(String code, boolean isAccount) {
|
||||||
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
||||||
Map<String, Object> requestUrlParam = new HashMap<>();
|
Map<String, Object> requestUrlParam = new HashMap<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user