Selaa lähdekoodia

Merge branch 'develop' of gitadmin/tuoheng_freeway into release

pull/393/head
wanjing 10 kuukautta sitten
vanhempi
commit
234a2134de
1 muutettua tiedostoa jossa 26 lisäystä ja 14 poistoa
  1. +26
    -14
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java

+ 26
- 14
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java Näytä tiedosto

@@ -96,7 +96,8 @@ public class WxServiceImpl implements IWxService {
log.info("code为空");
return JsonResult.error("code为空");
}
String userId = CurrentUserUtil.getUserId();
User user = CurrentUserUtil.getUserInfo();
String userId = user.getId();
String openidResult = GetOpenIdUtil.getopenid(code, CommonConfig.appId, CommonConfig.appSecret);
if (null != JSONObject.parseObject(openidResult).getInteger("errcode") ||
StringUtils.isNotEmpty(JSONObject.parseObject(openidResult).getString("errmsg"))) {
@@ -108,31 +109,42 @@ public class WxServiceImpl implements IWxService {
log.error("获取openid失败:", openidResult);
return JsonResult.error("获取openid失败");
}
//根据当前登录用户id查询授权表是否存在一条授权数据
UserAuthorize beforeUserAuthorize = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery()

// 根据当前登录用户id查询授权表是否存在一条授权数据
UserAuthorize userAuthorize = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery()
.eq(UserAuthorize::getUserId, userId)
.eq(UserAuthorize::getOpenId, openid)
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isNotEmpty(beforeUserAuthorize)) {
if (ObjectUtil.isNotEmpty(userAuthorize)) {
log.info("该用户已做过授权, openid={}", openid);
return JsonResult.error("该用户已做过授权");
}

UserAuthorize userAuthorize = new UserAuthorize();
userAuthorize.setOpenId(openid);
userAuthorize.setUserId(userId);
userAuthorize.setCreateTime(DateUtils.now());
userAuthorize.setCreateUser(userId);
int result = userAuthorizeMapper.insert(userAuthorize);
// 当前用户已经与其他微信做过绑定,先解绑
UserAuthorize userAuthorizeTmp = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery()
.eq(UserAuthorize::getUserId, userId)
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isNotEmpty(userAuthorizeTmp)) {
log.info("该用户已做绑定,先进行解绑, userId={},openid={}", userId, openid);
userAuthorizeMapper.deleteById(userAuthorizeTmp.getId());

user.setAuthorize(AuthorizeStatusEnum.AUTHORIZE_DOWN.getCode());
user.setUpdateTime(DateUtils.now());
user.setUpdateUser(userId);
userMapper.updateById(user);
}

UserAuthorize userAuthorizeNew = new UserAuthorize();
userAuthorizeNew.setOpenId(openid);
userAuthorizeNew.setUserId(userId);
userAuthorizeNew.setCreateTime(DateUtils.now());
userAuthorizeNew.setCreateUser(userId);
int result = userAuthorizeMapper.insert(userAuthorizeNew);
if (result <= 0) {
return JsonResult.error("授权数据入库失败");
}

//关联登录用户,已经做过授权 修改授权标识
User user = CurrentUserUtil.getUserInfo();
if (ObjectUtil.isEmpty(user)) {
return JsonResult.error(UserCodeEnum.USER_IS_NULL.getCode(), UserCodeEnum.USER_IS_NULL.getMsg());
}
user.setAuthorize(AuthorizeStatusEnum.AUTHORIZE_ON.getCode());
user.setUpdateTime(DateUtils.now());
user.setUpdateUser(userId);

Loading…
Peruuta
Tallenna