|
@@ -274,10 +274,10 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, Object> openIdLogin(WxLoginBody loginBody) {
|
|
|
- if(Validator.isEmpty(loginBody.getOpenid())){
|
|
|
+ if(Validator.isEmpty(loginBody.getOpenId())){
|
|
|
throw new CustomException("openid缺失");
|
|
|
}
|
|
|
- User user = iUserService.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, loginBody.getOpenid()).last("limit 1"));
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, loginBody.getOpenId()).last("limit 1"));
|
|
|
if (ObjectUtils.isNull(user)&&Validator.isEmpty(loginBody.getUserId())) {
|
|
|
throw new CustomException("该openid暂无绑定!",666);
|
|
|
}
|
|
@@ -286,7 +286,10 @@ public class WxLoginService implements IWxLoginService {
|
|
|
if(Validator.isNotEmpty(user.getOpenId())){
|
|
|
throw new CustomException("该用户已绑定过openid!",667);
|
|
|
}
|
|
|
- user.setOpenId(loginBody.getOpenid());
|
|
|
+ user.setOpenId(loginBody.getOpenId());
|
|
|
+ if(Validator.isNotEmpty(loginBody.getUnionId())){
|
|
|
+ user.setUnionId(loginBody.getUnionId());
|
|
|
+ }
|
|
|
iUserService.updateById(user);
|
|
|
}
|
|
|
|
|
@@ -418,7 +421,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
return openId;
|
|
|
}
|
|
|
|
|
|
- public String getExamWxOpenId(WxLoginBody loginBody) {
|
|
|
+ public Map<String,String> getExamWxOpenId(WxLoginBody loginBody) {
|
|
|
if(Validator.isEmpty(loginBody.getCode())){
|
|
|
throw new CustomException("code缺失");
|
|
|
}
|
|
@@ -432,7 +435,14 @@ public class WxLoginService implements IWxLoginService {
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
String session_key = String.valueOf(jsonObject.get("session_key"));
|
|
|
openId = String.valueOf(jsonObject.get("openid"));
|
|
|
- return openId;
|
|
|
+ String unionId = null;
|
|
|
+ if (jsonObject.containsKey("unionid")) { //当没绑定开放平台
|
|
|
+ unionId = String.valueOf(jsonObject.get("unionid"));
|
|
|
+ }
|
|
|
+ Map<String,String> map = new HashMap();
|
|
|
+ map.put("openId",openId);
|
|
|
+ map.put("unionId",unionId);
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
|