|
@@ -116,17 +116,18 @@ public class LoginServiceImpl implements LoginService {
|
|
|
return ResponseJson.error(appletsInfo.getMsg(), null);
|
|
|
}
|
|
|
Map<String, Object> infoData = appletsInfo.getData();
|
|
|
- String openId = (String) infoData.get("openid");
|
|
|
- String unionId = (String) infoData.get("unionid");
|
|
|
- String sessionKey = (String) infoData.get("session_key");
|
|
|
+ String openId = (String) infoData.get(WeChatService.Keys.OPEN_ID);
|
|
|
+ String unionId = (String) infoData.get(WeChatService.Keys.UNION_ID);
|
|
|
+ String sessionKey = (String) infoData.get(WeChatService.Keys.SESSION_KEY);
|
|
|
+
|
|
|
try {
|
|
|
if (StringUtils.isEmpty(unionId) || StringUtils.isBlank(unionId)) {
|
|
|
String result = WeChatService.decrypt(encryptedData, sessionKey, iv, "UTF-8");
|
|
|
log.info("解密数据>>>>>>" + result);
|
|
|
Map parseMap = JSONObject.parseObject(result, Map.class);
|
|
|
assert parseMap != null;
|
|
|
- unionId = parseMap.get("unionid").toString();
|
|
|
- infoData.put("unionid", unionId);
|
|
|
+ unionId = parseMap.get(WeChatService.Keys.UNION_ID).toString();
|
|
|
+ infoData.put(WeChatService.Keys.UNION_ID, unionId);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -185,7 +186,7 @@ public class LoginServiceImpl implements LoginService {
|
|
|
try {
|
|
|
// 通过code获取微信用户信息
|
|
|
Map<String, Object> map = weChatService.getInfoMapByWeb(code, "crm");
|
|
|
- String openId = (String) map.get("openid");
|
|
|
+ String openId = (String) map.get(WeChatService.Keys.OPEN_ID);
|
|
|
if (mode == 1) {
|
|
|
// 静默授权
|
|
|
Integer userId = loginMapper.getUserIdByOpenId(openId, "www");
|
|
@@ -201,7 +202,7 @@ public class LoginServiceImpl implements LoginService {
|
|
|
String accessToken = weChatService.getAccessToken();
|
|
|
// 获取微信用户信息
|
|
|
Map<String, Object> infoData = weChatService.getUserInfo(accessToken, openId);
|
|
|
- String unionId = (String) infoData.get("unionid");
|
|
|
+ String unionId = (String) infoData.get(WeChatService.Keys.UNION_ID);
|
|
|
// 用户数据存入Redis,key前缀:wxInfo:website:
|
|
|
redisService.setMap("wxInfo:website:" + unionId, infoData);
|
|
|
log.info("移动端授权登录,返回unionId给前端,用户数据存入Redis,key:wxInfo:website:" + unionId);
|
|
@@ -314,11 +315,11 @@ public class LoginServiceImpl implements LoginService {
|
|
|
// 用code换取access_token
|
|
|
Map<String, Object> tokenMap = weChatService.getInfoMapByWeb(code, "pc");
|
|
|
String accessToken = (String) tokenMap.get("access_token");
|
|
|
- String openid = (String) tokenMap.get("openid");
|
|
|
- log.info(">>>>>wx回调openId:" + openid + " ,accessToken"+ accessToken);
|
|
|
+ String openId = (String) tokenMap.get(WeChatService.Keys.OPEN_ID);
|
|
|
+ log.info(">>>>>(code换取access_token)wx回调openId:" + openId + " ,accessToken:"+ accessToken);
|
|
|
// 用access_token获取微信用户信息
|
|
|
- Map<String, Object> infoData = weChatService.getUserInfo(accessToken, openid);
|
|
|
- log.info(">>>>>wx回调openId:" + infoData.get("openid") + " ,unionId"+ infoData.get("unionid"));
|
|
|
+ Map<String, Object> infoData = weChatService.getUserInfoByWeb(accessToken, openId);
|
|
|
+ log.info(">>>>>(用access_token获取用户信息)wx回调openId:" + infoData.get(WeChatService.Keys.OPEN_ID) + " ,unionId:"+ infoData.get(WeChatService.Keys.UNION_ID));
|
|
|
// 微信用户信息存入redis
|
|
|
redisService.setMap("scan:" + state, infoData);
|
|
|
} catch (Exception e) {
|
|
@@ -349,9 +350,9 @@ public class LoginServiceImpl implements LoginService {
|
|
|
}
|
|
|
// 清除redis的扫码数据
|
|
|
redisService.remove("scan:" + state);
|
|
|
- String unionId = (String) infoData.get("unionid");
|
|
|
- String openId = (String) infoData.get("openid");
|
|
|
- log.info(">>>>>>pc商城unionId:" + unionId + " ,openid:" + openId);
|
|
|
+ String unionId = (String) infoData.get(WeChatService.Keys.UNION_ID);
|
|
|
+ String openId = (String) infoData.get(WeChatService.Keys.OPEN_ID);
|
|
|
+ log.info(">>>>>>pc商城unionId:" + unionId + " ,openId:" + openId);
|
|
|
// 用户数据存入Redis,key前缀:wxInfo:website:
|
|
|
String infoDataStr = JSON.toJSONString(infoData);
|
|
|
Map<String, Object> infoDataMap = JSON.parseObject(infoDataStr);
|
|
@@ -391,7 +392,7 @@ public class LoginServiceImpl implements LoginService {
|
|
|
}
|
|
|
Map<Object, Object> infoData = redisService.getEntries("wxInfo:website:" + unionId);
|
|
|
log.info("扫码绑定微信, 获取unionId>>>>>>" + unionId);
|
|
|
- String openId = (String) infoData.get("openid");
|
|
|
+ String openId = (String) infoData.get(WeChatService.Keys.OPEN_ID);
|
|
|
String nickName = (String) infoData.get("nickname");
|
|
|
String avatarUrl = (String) infoData.get("headimgurl");
|
|
|
// 判断微信是否已经绑定
|
|
@@ -490,7 +491,7 @@ public class LoginServiceImpl implements LoginService {
|
|
|
operationPo.setUnionId(unionId);
|
|
|
Map<Object, Object> infoData = redisService.getEntries("wxInfo:applets:" + unionId);
|
|
|
// 微信openId
|
|
|
- operationPo.setOpenId((String) infoData.get("openid"));
|
|
|
+ operationPo.setOpenId((String) infoData.get(WeChatService.Keys.OPEN_ID));
|
|
|
// 微信昵称
|
|
|
operationPo.setNickName(nickName);
|
|
|
// 微信头像
|
|
@@ -547,7 +548,7 @@ public class LoginServiceImpl implements LoginService {
|
|
|
}
|
|
|
Map<Object, Object> infoData = redisService.getEntries("wxInfo:applets:" + unionId);
|
|
|
log.info("绑定微信bindingWx,获取unionId>>>>>>" + unionId);
|
|
|
- String openId = (String) infoData.get("openid");
|
|
|
+ String openId = (String) infoData.get(WeChatService.Keys.OPEN_ID);
|
|
|
// 判断微信是否已经绑定
|
|
|
UserLoginVo operationByUnionId = loginMapper.getLoginUserByUnionId(unionId,"mini");
|
|
|
if (operationByUnionId != null) {
|