Browse Source

Merge branch 'develop' of gitadmin/tuoheng_freeway into release

pull/393/head
wanjing 10 months ago
parent
commit
234a2134de
1 changed files with 26 additions and 14 deletions
  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 View File

log.info("code为空"); log.info("code为空");
return JsonResult.error("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); String openidResult = GetOpenIdUtil.getopenid(code, CommonConfig.appId, CommonConfig.appSecret);
if (null != JSONObject.parseObject(openidResult).getInteger("errcode") || if (null != JSONObject.parseObject(openidResult).getInteger("errcode") ||
StringUtils.isNotEmpty(JSONObject.parseObject(openidResult).getString("errmsg"))) { StringUtils.isNotEmpty(JSONObject.parseObject(openidResult).getString("errmsg"))) {
log.error("获取openid失败:", openidResult); log.error("获取openid失败:", openidResult);
return JsonResult.error("获取openid失败"); 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::getUserId, userId)
.eq(UserAuthorize::getOpenId, openid) .eq(UserAuthorize::getOpenId, openid)
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode())); .eq(UserAuthorize::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isNotEmpty(beforeUserAuthorize)) {
if (ObjectUtil.isNotEmpty(userAuthorize)) {
log.info("该用户已做过授权, openid={}", openid); log.info("该用户已做过授权, openid={}", openid);
return JsonResult.error("该用户已做过授权"); 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) { if (result <= 0) {
return JsonResult.error("授权数据入库失败"); 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.setAuthorize(AuthorizeStatusEnum.AUTHORIZE_ON.getCode());
user.setUpdateTime(DateUtils.now()); user.setUpdateTime(DateUtils.now());
user.setUpdateUser(userId); user.setUpdateUser(userId);

Loading…
Cancel
Save