|
|
@@ -5,7 +5,9 @@ import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import jakarta.validation.constraints.NotNull;
|
|
|
@@ -13,17 +15,24 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.apache.seata.spring.annotation.GlobalTransactional;
|
|
|
-import org.dromara.auth.domain.SysUserWechat;
|
|
|
import org.dromara.auth.domain.bo.SysUserWechatBo;
|
|
|
-import org.dromara.auth.domain.vo.SysUserWechatVo;
|
|
|
-import org.dromara.auth.service.MiniAuthService;
|
|
|
+import org.dromara.auth.util.HttpClientUtil;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.ServletUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
+import org.dromara.customer.api.RemoteCustomerService;
|
|
|
import org.dromara.resource.api.RemoteFileService;
|
|
|
import org.dromara.resource.api.domain.RemoteFile;
|
|
|
+import org.dromara.system.api.RemoteClientService;
|
|
|
+import org.dromara.system.api.RemoteUserService;
|
|
|
+import org.dromara.system.api.RemoteUserWechatService;
|
|
|
+import org.dromara.system.api.domain.vo.RemoteClientVo;
|
|
|
+import org.dromara.system.api.domain.vo.RemoteUserWechatVo;
|
|
|
import org.dromara.system.api.model.LoginUser;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
@@ -33,6 +42,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@@ -47,11 +57,23 @@ import java.util.Objects;
|
|
|
@RestController
|
|
|
@RequestMapping("/wx")
|
|
|
public class MiniTokenController {
|
|
|
+ public static final String WX_LOGIN = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
|
|
|
- private final MiniAuthService miniAuthService;
|
|
|
@DubboReference
|
|
|
private RemoteFileService remoteFileService;
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ private RemoteUserService remoteUserService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteClientService remoteClientService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteUserWechatService remoteUserWechatService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteCustomerService remoteCustomerService;
|
|
|
+
|
|
|
@Value("${tr.wechat.secret}")
|
|
|
private String appSecret;
|
|
|
|
|
|
@@ -63,58 +85,210 @@ public class MiniTokenController {
|
|
|
* */
|
|
|
@SaIgnore
|
|
|
@PostMapping("/login")
|
|
|
- public R<SysUserWechatVo> login(@RequestBody SysUserWechatBo wechatBo) {
|
|
|
+ public R<RemoteUserWechatVo> login(@RequestBody SysUserWechatBo wechatBo) {
|
|
|
log.info("微信用户登录:{}", wechatBo.getCode());
|
|
|
|
|
|
// 从请求头中获取 tenantId
|
|
|
- String tenantId = ServletUtils.getHeader(Objects.requireNonNull(ServletUtils.getRequest()), "tenantId");
|
|
|
- log.info("从请求头获取到 tenantId: {}", tenantId);
|
|
|
+// String tenantId = ServletUtils.getHeader(Objects.requireNonNull(ServletUtils.getRequest()), "tenantId");
|
|
|
+// log.info("从请求头获取到 tenantId: {}", tenantId);
|
|
|
+
|
|
|
+ String tenantId = "000000";
|
|
|
|
|
|
// 在动态租户上下文中执行登录逻辑
|
|
|
return TenantHelper.dynamic(tenantId, () -> {
|
|
|
- SysUserWechat wechat = miniAuthService.wxLogin(wechatBo);
|
|
|
- LoginUser loginUser = new LoginUser();
|
|
|
- loginUser.setUserId(wechat.getUserId());
|
|
|
- loginUser.setNickname(wechat.getNickname());
|
|
|
- loginUser.setUserType("app_user");
|
|
|
- loginUser.setOpenid(wechat.getOpenId());
|
|
|
- loginUser.setTenantId(tenantId); // 设置租户ID到登录用户
|
|
|
-
|
|
|
- // 配置登录参数
|
|
|
- SaLoginParameter model = new SaLoginParameter();
|
|
|
- model.setDeviceType("xcx"); // 小程序设备类型
|
|
|
- model.setTimeout(30 * 24 * 60 * 60); // 30天过期时间
|
|
|
- model.setActiveTimeout(7 * 24 * 60 * 60); // 7天活跃超时
|
|
|
- model.setExtra(LoginHelper.CLIENT_KEY, "miniprogram_client_id_2025"); // 使用系统认可的APP端客户端ID
|
|
|
-
|
|
|
- //生成token
|
|
|
- LoginHelper.login(loginUser, model);
|
|
|
- // 获取token信息
|
|
|
- String accessToken = StpUtil.getTokenValue();
|
|
|
- Long expireIn = StpUtil.getTokenTimeout();
|
|
|
- SysUserWechatVo wechatVo = BeanUtil.copyProperties(wechat, SysUserWechatVo.class);
|
|
|
- wechatVo.setOpenId(wechat.getOpenId());
|
|
|
- wechatVo.setAccessToken(accessToken);
|
|
|
- wechatVo.setExpireIn(expireIn);
|
|
|
- return R.ok(wechatVo);
|
|
|
+ try {
|
|
|
+ RemoteClientVo client = remoteClientService.queryByClientId(wechatBo.getClientId());
|
|
|
+ if (client == null) {
|
|
|
+ return R.fail("客户端不存在");
|
|
|
+ }
|
|
|
+ // 1. 调用 Service 层逻辑获取 openid
|
|
|
+ String openid = getOpenid(wechatBo.getCode());
|
|
|
+ if (openid == null) {
|
|
|
+ return R.fail("登录code无效,登录失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 通过 openid 查询用户
|
|
|
+ RemoteUserWechatVo wechat = remoteUserWechatService.getUserInfoByOpenid(openid);
|
|
|
+
|
|
|
+ // 3. 如果用户不存在,返回引导注册信息
|
|
|
+ if (wechat == null) {
|
|
|
+ log.info("检测到新用户 (OpenID: {}), 引导注册", openid);
|
|
|
+ RemoteUserWechatVo wechatVo = new RemoteUserWechatVo();
|
|
|
+ wechatVo.setOpenId(openid);
|
|
|
+ wechatVo.setAppId(appId);
|
|
|
+ return R.warn("用户未注册,请前往注册", wechatVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long customerId = null;
|
|
|
+ if(ObjectUtil.isNotEmpty(wechat.getUserId())){
|
|
|
+ customerId = remoteCustomerService.selectCustomerIdByUserId(wechat.getUserId());
|
|
|
+ if (Objects.isNull(customerId)) {
|
|
|
+ return R.warn("该手机号未注册客户,请先注册");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // --- 登录成功逻辑 (用户已存在) ---
|
|
|
+ LoginUser loginUser = new LoginUser();
|
|
|
+ loginUser.setUserId(wechat.getUserId());
|
|
|
+ loginUser.setNickname(wechat.getNickname());
|
|
|
+ loginUser.setUserType("app_user");
|
|
|
+ loginUser.setOpenid(wechat.getOpenId());
|
|
|
+ loginUser.setTenantId(tenantId);
|
|
|
+ loginUser.setClientKey(client.getClientKey());
|
|
|
+ loginUser.setDeviceType(client.getDeviceType());
|
|
|
+ loginUser.setCustomerId(customerId);
|
|
|
+
|
|
|
+ SaLoginParameter model = new SaLoginParameter();
|
|
|
+ model.setTimeout(client.getTimeout());
|
|
|
+ model.setActiveTimeout(client.getActiveTimeout());
|
|
|
+ model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
|
|
+
|
|
|
+ LoginHelper.login(loginUser, model);
|
|
|
+ String accessToken = StpUtil.getTokenValue();
|
|
|
+ Long expireIn = StpUtil.getTokenTimeout();
|
|
|
+
|
|
|
+ wechat.setAccessToken(accessToken);
|
|
|
+ wechat.setExpireIn(expireIn);
|
|
|
+
|
|
|
+ return R.ok(wechat);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 其他异常正常抛出
|
|
|
+ log.error("登录异常", e);
|
|
|
+ return R.fail("登录失败: " + e.getMessage());
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * 小程序登录手机号
|
|
|
+ * */
|
|
|
+ @SaIgnore
|
|
|
+ @PostMapping("/loginByPhone")
|
|
|
+ public R<RemoteUserWechatVo> loginByPhone(@RequestBody Map<String, String> data) {
|
|
|
+ try {
|
|
|
+ String code = data.get("code");
|
|
|
+ String openId = data.get("openId");
|
|
|
+ String clientId = data.get("clientId");
|
|
|
+ log.info("手机号快捷登录,获取临时code: {}", code);
|
|
|
+
|
|
|
+ // 获取 tenantId
|
|
|
+// String tenantId = ServletUtils.getHeader(Objects.requireNonNull(ServletUtils.getRequest()), "tenantId");
|
|
|
+
|
|
|
+ String tenantId = "000000";
|
|
|
+ RemoteClientVo client = remoteClientService.queryByClientId(clientId);
|
|
|
+ if (client == null) {
|
|
|
+ return R.fail("客户端不存在");
|
|
|
+ }
|
|
|
+ return TenantHelper.dynamic(tenantId, () -> {
|
|
|
+ // 1. 通过 code 换取手机号
|
|
|
+ String phoneNumber = getPhoneNumberByCode(code);
|
|
|
+ if (phoneNumber == null) {
|
|
|
+ return R.fail("获取手机号失败");
|
|
|
+ }
|
|
|
+ log.info("获取到手机号: {}", phoneNumber);
|
|
|
+ RemoteUserWechatVo userVo = null;
|
|
|
+ LoginUser userInfoByPhonenumber = remoteUserService.getUserInfoByPhonenumber(phoneNumber);
|
|
|
+ if (ObjectUtil.isEmpty(userInfoByPhonenumber)) {
|
|
|
+ return R.warn("该手机号未注册,请先注册");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(userInfoByPhonenumber)) {
|
|
|
+ RemoteUserWechatVo sysUserWechat = remoteUserWechatService.getUserInfoByPhoneNumber(phoneNumber);
|
|
|
+ if (ObjectUtil.isEmpty(sysUserWechat)) {
|
|
|
+ // 创建新的微信关联记录
|
|
|
+ RemoteUserWechatVo newUserWechat = new RemoteUserWechatVo();
|
|
|
+ newUserWechat.setOpenId(openId);
|
|
|
+ newUserWechat.setStatus("0");
|
|
|
+
|
|
|
+ // --- 核心修复:处理昵称 ---
|
|
|
+ // 静默登录没传昵称,生成默认昵称
|
|
|
+ String nickName = "用户_" + openId.substring(openId.length() - 8);
|
|
|
+ newUserWechat.setUserId(userInfoByPhonenumber.getUserId());
|
|
|
+ newUserWechat.setPhoneNumber(phoneNumber);
|
|
|
+ // 保存微信关联表
|
|
|
+ newUserWechat.setNickname(nickName); // 保存默认昵称
|
|
|
+ // --- 处理头像 ---
|
|
|
+ newUserWechat.setAvatarUrl("/default/avatar.png"); // 默认头像
|
|
|
+
|
|
|
+ Boolean insert = remoteUserWechatService.insertUserWechat(newUserWechat);
|
|
|
+ if (insert) {
|
|
|
+ userVo = newUserWechat;
|
|
|
+ }else{
|
|
|
+ return R.fail("保存微信关联失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ userVo = sysUserWechat;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 根据手机号查询用户
|
|
|
+ // user = miniAuthService.queryByPhoneNumber(phoneNumber);
|
|
|
+
|
|
|
+ // 如果业务逻辑是“查不到就注册”,请取消下面的注释
|
|
|
+ // if (user == null) {
|
|
|
+ // user = miniAuthService.registerByPhoneNumber(phoneNumber);
|
|
|
+ // }
|
|
|
+ Long customerId = null;
|
|
|
+ if (ObjectUtil.isNotEmpty(userVo.getUserId())) {
|
|
|
+ customerId = remoteCustomerService.selectCustomerIdByUserId(userVo.getUserId());
|
|
|
+ if (Objects.isNull(customerId)) {
|
|
|
+ return R.warn("该手机号未注册客户,请先注册");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 登录逻辑(与 /login 接口保持一致)
|
|
|
+ LoginUser loginUser = new LoginUser();
|
|
|
+ loginUser.setUserId(userVo.getUserId());
|
|
|
+ loginUser.setNickname(userVo.getNickname());
|
|
|
+ loginUser.setUserType("app_user");
|
|
|
+ loginUser.setOpenid(userVo.getOpenId());
|
|
|
+ loginUser.setTenantId(tenantId);
|
|
|
+ loginUser.setClientKey(client.getClientKey());
|
|
|
+ loginUser.setDeviceType(client.getDeviceType());
|
|
|
+ loginUser.setCustomerId(customerId);
|
|
|
+
|
|
|
+
|
|
|
+ SaLoginParameter model = new SaLoginParameter();
|
|
|
+ model.setDeviceType(client.getDeviceType());
|
|
|
+ model.setTimeout(client.getTimeout());
|
|
|
+ model.setActiveTimeout(client.getActiveTimeout());
|
|
|
+ model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
|
|
+ LoginHelper.login(loginUser, model);
|
|
|
+ String accessToken = StpUtil.getTokenValue();
|
|
|
+ Long expireIn = StpUtil.getTokenTimeout();
|
|
|
+
|
|
|
+ userVo.setAccessToken(accessToken);
|
|
|
+ userVo.setExpireIn(expireIn);
|
|
|
+
|
|
|
+ return R.ok(userVo);
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("手机号登录失败", e);
|
|
|
+ return R.fail("登录失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@SaIgnore
|
|
|
@PostMapping("/bindPhone")
|
|
|
@GlobalTransactional
|
|
|
- public R<SysUserWechatVo> getUserPhone(@RequestBody Map<String, Object> phoneData) {
|
|
|
+ public R<RemoteUserWechatVo> getUserPhone(@RequestBody Map<String, Object> phoneData) {
|
|
|
try {
|
|
|
String code = (String) phoneData.get("code");
|
|
|
Long userId = Long.valueOf(phoneData.get("userId").toString());
|
|
|
+ String clientId = (String) phoneData.get("clientId");
|
|
|
|
|
|
log.info("获取手机号请求 - userId: {}, code: {}", userId, code);
|
|
|
|
|
|
// 从请求头中获取 tenantId
|
|
|
- String tenantId = ServletUtils.getHeader(Objects.requireNonNull(ServletUtils.getRequest()), "tenantId");
|
|
|
- log.info("从请求头获取到 tenantId: {}", tenantId);
|
|
|
-
|
|
|
+// String tenantId = ServletUtils.getHeader(Objects.requireNonNull(ServletUtils.getRequest()), "tenantId");
|
|
|
+// log.info("从请求头获取到 tenantId: {}", tenantId);
|
|
|
+ String tenantId = "000000";
|
|
|
+ RemoteClientVo client = remoteClientService.queryByClientId(clientId);
|
|
|
+ if (client == null) {
|
|
|
+ return R.fail("客户端不存在");
|
|
|
+ }
|
|
|
// 在动态租户上下文中执行绑定手机号逻辑
|
|
|
return TenantHelper.dynamic(tenantId, () -> {
|
|
|
// 1. 通过手机号专用code直接获取手机号(新方法)
|
|
|
@@ -131,17 +305,21 @@ public class MiniTokenController {
|
|
|
log.info("解密得到手机号: {}", phoneNumber.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
|
|
|
|
|
|
// 3. 更新用户手机号
|
|
|
- SysUserWechatVo user = miniAuthService.queryById(userId);
|
|
|
+ RemoteUserWechatVo user = remoteUserWechatService.getUserInfoById(userId);
|
|
|
if (user == null) {
|
|
|
return R.fail("用户不存在");
|
|
|
}
|
|
|
+ Long customerId = null;
|
|
|
+ if (ObjectUtil.isNotEmpty(user.getUserId())) {
|
|
|
+ customerId = remoteCustomerService.selectCustomerIdByUserId(user.getUserId());
|
|
|
+ if (Objects.isNull(customerId)) {
|
|
|
+ return R.warn("该手机号未注册客户,请先注册");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
user.setPhoneNumber(phoneNumber);
|
|
|
- // 创建BO对象进行更新
|
|
|
- SysUserWechatBo updateBo = new SysUserWechatBo();
|
|
|
- updateBo.setUserId(userId);
|
|
|
- updateBo.setPhoneNumber(phoneNumber);
|
|
|
- miniAuthService.updateByBo(updateBo);
|
|
|
+ // 通过远程调用更新
|
|
|
+ remoteUserWechatService.updateUserWechat(user);
|
|
|
|
|
|
// 4. 重新生成token并返回用户信息
|
|
|
LoginUser loginUser = new LoginUser();
|
|
|
@@ -150,13 +328,15 @@ public class MiniTokenController {
|
|
|
loginUser.setUserType("app_user");
|
|
|
loginUser.setOpenid(user.getOpenId());
|
|
|
loginUser.setTenantId(tenantId); // 设置租户ID到登录用户
|
|
|
-
|
|
|
+ loginUser.setClientKey(client.getClientKey());
|
|
|
+ loginUser.setDeviceType(client.getDeviceType());
|
|
|
+ loginUser.setCustomerId(customerId);
|
|
|
// 配置登录参数
|
|
|
SaLoginParameter model = new SaLoginParameter();
|
|
|
- model.setDeviceType("xcx");
|
|
|
- model.setTimeout(30 * 24 * 60 * 60);
|
|
|
- model.setActiveTimeout(7 * 24 * 60 * 60);
|
|
|
- model.setExtra(LoginHelper.CLIENT_KEY, "miniprogram_client_id_2025");
|
|
|
+ model.setDeviceType(client.getDeviceType());
|
|
|
+ model.setTimeout(client.getTimeout());
|
|
|
+ model.setActiveTimeout(client.getActiveTimeout());
|
|
|
+ model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
|
|
|
|
|
// 生成token
|
|
|
LoginHelper.login(loginUser, model);
|
|
|
@@ -164,7 +344,7 @@ public class MiniTokenController {
|
|
|
// 获取token信息
|
|
|
String accessToken = StpUtil.getTokenValue();
|
|
|
Long expireIn = StpUtil.getTokenTimeout();
|
|
|
- SysUserWechatVo userVo = new SysUserWechatVo();
|
|
|
+ RemoteUserWechatVo userVo = new RemoteUserWechatVo();
|
|
|
userVo.setOpenId(user.getOpenId());
|
|
|
userVo.setUserId(user.getUserId());
|
|
|
userVo.setStatus(user.getStatus());
|
|
|
@@ -187,9 +367,53 @@ public class MiniTokenController {
|
|
|
/*
|
|
|
* 获取手机号
|
|
|
* */
|
|
|
- @PostMapping("/getPhoneNumber")
|
|
|
- public Object getPhoneNumber(@RequestBody Map<String, String> data) {
|
|
|
- return R.ok(getPhoneNumberByCode(data.get("code")));
|
|
|
+ @PostMapping("/getOpenId")
|
|
|
+ public Object getOpenId(@RequestBody Map<String, String> data) {
|
|
|
+ return R.ok(getOpenid(data.get("code")));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getOpenid(String code) {
|
|
|
+ // 1. 获取配置(注意:这里获取的是后端配置的 AppID,必须与前端小程序的 AppID 一致)
|
|
|
+
|
|
|
+ // 2. 构建参数
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("appid", appId);
|
|
|
+ map.put("secret", appSecret);
|
|
|
+ map.put("js_code", code);
|
|
|
+ map.put("grant_type", "authorization_code");
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 3. 调用微信接口
|
|
|
+ String json = HttpClientUtil.doGet(WX_LOGIN, map);
|
|
|
+ log.info("微信接口返回: {}", json);
|
|
|
+
|
|
|
+ // 4. 解析结果
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json);
|
|
|
+
|
|
|
+ // 5. 【关键】先检查有没有错误码
|
|
|
+ if (jsonObject.containsKey("errcode")) {
|
|
|
+ int errCode = jsonObject.getIntValue("errcode");
|
|
|
+ String errMsg = jsonObject.getString("errmsg");
|
|
|
+ log.error("微信登录失败: code={}, error={}", errCode, errMsg);
|
|
|
+ // 抛出异常或返回 null,让上层知道登录失败
|
|
|
+ throw new RuntimeException("微信登录失败: " + errMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 获取 OpenID
|
|
|
+ String openid = jsonObject.getString("openid");
|
|
|
+ if (StringUtils.isEmpty(openid)) {
|
|
|
+ throw new RuntimeException("微信返回openid为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 7. (可选) 获取 UnionID - 如果你需要打通公众号/App 账号体系
|
|
|
+ String unionId = jsonObject.getString("unionid");
|
|
|
+
|
|
|
+ return openid;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用微信接口异常", e);
|
|
|
+ throw new RuntimeException("网络连接微信服务失败", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private String getPhoneNumberByCode(String code) {
|
|
|
@@ -285,14 +509,9 @@ public class MiniTokenController {
|
|
|
*/
|
|
|
private boolean isPhoneNumberExists(String phoneNumber, Long excludeUserId) {
|
|
|
try {
|
|
|
- // 这里需要调用service层方法查询数据库
|
|
|
- // 由于没有现成的方法,暂时返回false,建议后续完善
|
|
|
- // WxVsUser existingUser = vsUserService.selectByPhoneNumber(phoneNumber);
|
|
|
- // return existingUser != null && !existingUser.getUserId().equals(excludeUserId);
|
|
|
-
|
|
|
log.info("检查手机号是否存在: {} (排除用户: {})",
|
|
|
phoneNumber.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"), excludeUserId);
|
|
|
- SysUserWechat existingUser = miniAuthService.queryByPhoneNumber(phoneNumber);
|
|
|
+ RemoteUserWechatVo existingUser = remoteUserWechatService.getUserInfoByPhoneNumber(phoneNumber);
|
|
|
return existingUser != null && !existingUser.getUserId().equals(excludeUserId);
|
|
|
} catch (Exception e) {
|
|
|
log.error("检查手机号重复时发生异常", e);
|
|
|
@@ -332,8 +551,8 @@ public class MiniTokenController {
|
|
|
}
|
|
|
|
|
|
@GetMapping("/userInfo/{userId}")
|
|
|
- public R<SysUserWechatVo> getInfo(@NotNull(message = "主键不能为空")
|
|
|
+ public R<RemoteUserWechatVo> getInfo(@NotNull(message = "主键不能为空")
|
|
|
@PathVariable("userId") Long id) {
|
|
|
- return R.ok(miniAuthService.queryById(id));
|
|
|
+ return R.ok(remoteUserWechatService.getUserInfoById(id));
|
|
|
}
|
|
|
}
|