Bladeren bron

小程序授权改为一一对应

pull/385/head
wanjing 10 maanden geleden
bovenliggende
commit
c6fa15416f
1 gewijzigde bestanden met toevoegingen van 17 en 11 verwijderingen
  1. +17
    -11
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java

+ 17
- 11
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java Bestand weergeven

@@ -60,6 +60,7 @@ public class WxServiceImpl implements IWxService {
@Override
public JsonResult openId(String code) {
if (StringUtils.isEmpty(code)) {
log.info("code为空");
return JsonResult.error("code为空");
}
String userId = CurrentUserUtil.getUserId();
@@ -77,19 +78,23 @@ public class WxServiceImpl implements IWxService {
//根据当前登录用户id查询授权表是否存在一条授权数据
UserAuthorize beforeUserAuthorize = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery()
.eq(UserAuthorize::getUserId, userId)
.eq(UserAuthorize::getOpenId, code)
.eq(UserAuthorize::getOpenId, openid)
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isEmpty(beforeUserAuthorize)) {
UserAuthorize userAuthorize = new UserAuthorize();
userAuthorize.setOpenId(openid);
userAuthorize.setUserId(userId);
userAuthorize.setCreateTime(DateUtils.now());
userAuthorize.setCreateUser(userId);
int result = userAuthorizeMapper.insert(userAuthorize);
if (result <= 0) {
return JsonResult.error("授权数据入库失败");
}
if (ObjectUtil.isNotEmpty(beforeUserAuthorize)) {
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);
if (result <= 0) {
return JsonResult.error("授权数据入库失败");
}

//关联登录用户,已经做过授权 修改授权标识
User user = CurrentUserUtil.getUserInfo();
if (ObjectUtil.isEmpty(user)) {
@@ -100,6 +105,7 @@ public class WxServiceImpl implements IWxService {
user.setUpdateUser(userId);
int count = userMapper.updateById(user);
if (count <= 0) {
log.info("用户授权标识更新失败, userId={}", userId);
return JsonResult.error("用户授权标识更新失败");
}
return JsonResult.success();

Laden…
Annuleren
Opslaan