fix: 某种不知名的情况下,微信联合登陆会报错问题处理

This commit is contained in:
Chopper711 2023-08-25 11:48:03 +08:00
parent 56b800e4ff
commit 105162aa89

View File

@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.lili.cache.Cache; import cn.lili.cache.Cache;
import cn.lili.cache.CachePrefix;
import cn.lili.common.enums.ClientTypeEnum; import cn.lili.common.enums.ClientTypeEnum;
import cn.lili.common.enums.ResultCode; import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException; import cn.lili.common.exception.ServiceException;
@ -125,9 +124,7 @@ public class ConnectServiceImpl extends ServiceImpl<ConnectMapper, Connect> impl
@Transactional @Transactional
public Token miniProgramAutoLogin(WechatMPLoginParams params) { public Token miniProgramAutoLogin(WechatMPLoginParams params) {
Object cacheData = cache.get(CachePrefix.WECHAT_SESSION_PARAMS.getPrefix() + params.getUuid());
Map<String, String> map = new HashMap<>(3); Map<String, String> map = new HashMap<>(3);
if (cacheData == null) {
//得到微信小程序联合登陆信息 //得到微信小程序联合登陆信息
JSONObject json = this.getConnect(params.getCode()); JSONObject json = this.getConnect(params.getCode());
//存储session key 后续登录用得到 //存储session key 后续登录用得到
@ -137,12 +134,8 @@ public class ConnectServiceImpl extends ServiceImpl<ConnectMapper, Connect> impl
map.put("sessionKey", sessionKey); map.put("sessionKey", sessionKey);
map.put("unionId", unionId); map.put("unionId", unionId);
map.put("openId", openId); map.put("openId", openId);
cache.put(CachePrefix.WECHAT_SESSION_PARAMS.getPrefix() + params.getUuid(), map, 900L);
} else {
map = (Map<String, String>) cacheData;
}
//微信联合登陆参数
//微信联合登陆参数
return phoneMpBindAndLogin(map.get("sessionKey"), params, map.get("openId"), map.get("unionId")); return phoneMpBindAndLogin(map.get("sessionKey"), params, map.get("openId"), map.get("unionId"));
} }
@ -217,7 +210,7 @@ public class ConnectServiceImpl extends ServiceImpl<ConnectMapper, Connect> impl
connectQueryDTO.getUnionType()) connectQueryDTO.getUnionType())
.eq(CharSequenceUtil.isNotEmpty(connectQueryDTO.getUnionId()), Connect::getUnionId, .eq(CharSequenceUtil.isNotEmpty(connectQueryDTO.getUnionId()), Connect::getUnionId,
connectQueryDTO.getUnionId()); connectQueryDTO.getUnionId());
return this.getOne(queryWrapper,false); return this.getOne(queryWrapper, false);
} }
@Override @Override
@ -267,13 +260,13 @@ public class ConnectServiceImpl extends ServiceImpl<ConnectMapper, Connect> impl
private Token unionLoginCallback(ConnectAuthUser authUser, boolean longTerm) { private Token unionLoginCallback(ConnectAuthUser authUser, boolean longTerm) {
try { try {
Member member =null; Member member = null;
//判断是否传递手机号如果传递手机号则使用手机号登录 //判断是否传递手机号如果传递手机号则使用手机号登录
if(StrUtil.isNotBlank(authUser.getPhone())){ if (StrUtil.isNotBlank(authUser.getPhone())) {
member = memberService.findByMobile(authUser.getPhone()); member = memberService.findByMobile(authUser.getPhone());
} }
//如果未查到手机号的会员则使用第三方登录 //如果未查到手机号的会员则使用第三方登录
if(member==null){ if (member == null) {
LambdaQueryWrapper<Connect> queryWrapper = new LambdaQueryWrapper<Connect>(); LambdaQueryWrapper<Connect> queryWrapper = new LambdaQueryWrapper<Connect>();
//使用UnionId登录 //使用UnionId登录
if (authUser.getToken() != null && StrUtil.isNotBlank(authUser.getToken().getUnionId())) { if (authUser.getToken() != null && StrUtil.isNotBlank(authUser.getToken().getUnionId())) {