|
@ -149,34 +149,18 @@ public class AppletApiLoginService { |
|
|
if (currentUser == null) { |
|
|
if (currentUser == null) { |
|
|
return Result.error("用户未登录"); |
|
|
return Result.error("用户未登录"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 从Redis获取手机号 |
|
|
|
|
|
// String phoneCodeKey = PHONE_CODE_PREFIX + phoneCode; |
|
|
|
|
|
// String phoneNumber = (String) redisTemplate.opsForValue().get(phoneCodeKey); |
|
|
|
|
|
// if (phoneNumber == null) { |
|
|
|
|
|
// return Result.error("手机号code已过期或无效"); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String phoneNumber = getPhoneNumber(phoneCode).getResult(); |
|
|
|
|
|
|
|
|
// 查找用户 |
|
|
// 查找用户 |
|
|
AppletUser user = appletUserService.getByOpenid(currentUser.getOpenid()); |
|
|
AppletUser user = appletUserService.getByOpenid(currentUser.getOpenid()); |
|
|
if (user == null) { |
|
|
if (user == null) { |
|
|
return Result.error("用户不存在"); |
|
|
return Result.error("用户不存在"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 检查手机号是否已被其他用户绑定 |
|
|
|
|
|
// AppletUser existingUser = appletUserService.getByPhone(phoneNumber); |
|
|
|
|
|
// if (existingUser != null && !existingUser.getId().equals(user.getId())) { |
|
|
|
|
|
// return Result.error("该手机号已被其他用户绑定"); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// // 更新用户手机号 |
|
|
|
|
|
// user.setPhone(phoneNumber); |
|
|
|
|
|
// appletUserService.updateById(user); |
|
|
|
|
|
// |
|
|
|
|
|
// // 删除Redis中的临时数据 |
|
|
|
|
|
// redisTemplate.delete(phoneCodeKey); |
|
|
|
|
|
// |
|
|
|
|
|
// log.info("绑定手机号成功,用户: {}, 手机号: {}", user.getName(), phoneNumber); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user.setPhone(phoneNumber); |
|
|
|
|
|
appletUserService.updateById(user); |
|
|
|
|
|
|
|
|
return Result.OK("绑定成功"); |
|
|
return Result.OK("绑定成功"); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
@ -223,29 +207,6 @@ public class AppletApiLoginService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 退出登录 |
|
|
|
|
|
* |
|
|
|
|
|
* @param token 用户token |
|
|
|
|
|
* @return 退出结果 |
|
|
|
|
|
*/ |
|
|
|
|
|
public Result<String> logout(String token) { |
|
|
|
|
|
try { |
|
|
|
|
|
String openid = JwtUtil.getUsername(token); |
|
|
|
|
|
if (openid != null) { |
|
|
|
|
|
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token); |
|
|
|
|
|
|
|
|
|
|
|
log.info("用户退出登录: {}", openid); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("退出成功"); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("退出登录异常", e); |
|
|
|
|
|
return Result.error("退出失败: " + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 更新用户信息 |
|
|
* 更新用户信息 |
|
|
* |
|
|
* |
|
|