Bläddra i källkod

Merge remote-tracking branch 'origin/point_dev' into point_dev

jinshihui 1 vecka sedan
förälder
incheckning
be1068c38e

+ 40 - 1
nightFragrance-admin/src/main/java/com/ylx/web/controller/massage/WeChatController.java

@@ -2,6 +2,7 @@ package com.ylx.web.controller.massage;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ObjUtil;
 import cn.hutool.extra.qrcode.QrCodeUtil;
 import cn.hutool.extra.qrcode.QrConfig;
 import cn.hutool.json.JSONObject;
@@ -36,6 +37,8 @@ import com.ylx.massage.service.TbFileService;
 import com.ylx.massage.utils.JsSignUtil;
 import com.ylx.massage.utils.StringUtilsMassage;
 import com.ylx.massage.utils.WeChatUtil;
+import com.ylx.usercenter.domain.vo.OneAccountVO;
+import com.ylx.usercenter.service.UnifiedUserCenterService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -125,6 +128,8 @@ public class WeChatController extends BaseController {
      */
     @Value("${ylx.fixedVerifyCode:123456}")
     private String fixedVerifyCode;
+    @Resource
+    private UnifiedUserCenterService unifiedUserCenterService;
 
     /**
      * 微信Token验证
@@ -634,7 +639,7 @@ public class WeChatController extends BaseController {
      */
     @GetMapping("/sendMsg")
     @ApiOperation(value = "发送短信验证码", notes = "发送短信验证码")
-    public R<String> sendMsg(@RequestParam String phone , HttpServletRequest request) {
+    public R<String> sendMsg(@RequestParam String phone, HttpServletRequest request) {
         if (org.apache.commons.lang3.StringUtils.isEmpty(phone)) {
             return R.fail("手机号不能为空");
         }
@@ -653,4 +658,38 @@ public class WeChatController extends BaseController {
         }
         return R.fail("发送失败");
     }
+
+    @ApiOperation("uuid登录")
+    @PostMapping("/uuidLogin")
+    @Log(title = "uuid登录", businessType = BusinessType.OTHER)
+    public R<WxLoginUser> uuidLogin(@RequestBody PhoneLoginBody phoneLoginBody) {
+        String uuid = phoneLoginBody.getUuid();
+
+        if (StringUtils.isEmpty(uuid)) {
+            return R.fail("uuid不能为空");
+        }
+        OneAccountVO oneAccountVO = this.unifiedUserCenterService.queryClients(phoneLoginBody.getUuid());
+        if (ObjUtil.isNull(oneAccountVO)) {
+            return R.fail("未查询到用户信息");
+        }
+        TWxUser user = wxUserService.getById(oneAccountVO.getUserId());
+        if (ObjUtil.isNull(user)) {
+            return R.fail("登录失败");
+        }
+        // 构建WxLoginUser
+        WxLoginUser wxUser = new WxLoginUser();
+        BeanUtils.copyProperties(user, wxUser);
+        // 生成并返回令牌
+        String token = wxTokenService.createToken(wxUser);
+        log.info("uuid登录生成的token值:{}", token);
+        if (StringUtils.isEmpty(token)) {
+            return R.fail("生成令牌失败");
+        }
+        wxUser.setToken(token);
+        // 记录登录信息
+        AsyncManager.me().execute(AsyncFactory.recordLogininfor(uuid, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
+        log.info("uuid: {} 登录成功", uuid);
+        return R.ok(wxUser);
+    }
+
 }

+ 4 - 0
nightFragrance-admin/src/main/resources/application-dev.yml

@@ -293,6 +293,10 @@ remote:
     base-url: https://life.baoxianzhanggui.com/locallive-pro-java
     #本地生活平台id
     client-id: bdsh-X9yZ1wV3uT5sR7qP9o
+  # 广誉远
+  night-fragrance:
+    client-id: gyy-aB4cD6eF8gH0iJ2kL4
+
 
 ## 阿里云短信
 aliyun:

+ 3 - 0
nightFragrance-admin/src/main/resources/application-pro.yml

@@ -292,4 +292,7 @@ remote:
     base-url: https://life.baoxianzhanggui.com/locallive-pro-java
     #本地生活平台id
     client-id: bdsh-X9yZ1wV3uT5sR7qP9o
+  # 广誉远
+  night-fragrance:
+    client-id: gyy-aB4cD6eF8gH0iJ2kL4
 

+ 3 - 0
nightFragrance-admin/src/main/resources/application-test.yml

@@ -306,3 +306,6 @@ remote:
     base-url: https://life.baoxianzhanggui.com/locallive-pro-java
     #本地生活平台id
     client-id: bdsh-X9yZ1wV3uT5sR7qP9o
+  # 广誉远
+  night-fragrance:
+    client-id: gyy-aB4cD6eF8gH0iJ2kL4

+ 2 - 0
nightFragrance-common/src/main/java/com/ylx/common/core/domain/model/PhoneLoginBody.java

@@ -26,4 +26,6 @@ public class PhoneLoginBody {
     @ApiModelProperty(value = "验证码(6位数字)", required = true)
     private String code;
 
+    private String uuid;
+
 }

+ 1 - 1
nightFragrance-framework/src/main/java/com/ylx/framework/config/SecurityConfig.java

@@ -113,7 +113,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                         "/api/xiangmu/v1/getByid", "/api/xiangmu/v1/highlights", "/api/js/v1/wx/getByid", "/api/js/v1/wx/select", "/api/js/v1/wx/add", "/api/recharge/v1/test",
                         "/wx/pay/payNotify", "/wx/pay/refundNotify", "/weChat/getAccessToken","/weChat/phoneLogin","/weChat/sendMsg", "/weChat/getCode", "/weChat/verifyToken", "/sq/getAccessToken",
                         "/area/select", "/system/dept/list", "/api/xiangmu/v1/wx/recommend", "/product/category/create","/area/code","/area/city","/product/category/list",
-                        "/wx/pay/query/order/{outTradeNo}","/api/products/**","/api/user/point/**","/userCenter/userApp/queryBind").permitAll()
+                        "/wx/pay/query/order/{outTradeNo}","/api/products/**","/api/user/point/**","/userCenter/userApp/queryBind","/weChat/uuidLogin").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.txt", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 20 - 0
nightFragrance-massage/src/main/java/com/ylx/usercenter/domain/vo/OneAccountVO.java

@@ -0,0 +1,20 @@
+package com.ylx.usercenter.domain.vo;
+
+import lombok.Data;
+
+@Data
+public class OneAccountVO {
+
+    private Integer id;
+
+    private String userId;
+
+    private String clientId;
+
+    private String tenantId;
+
+    private String uuid;
+
+    private String userPhone;
+
+}

+ 2 - 2
nightFragrance-massage/src/main/java/com/ylx/usercenter/domain/vo/UnifiedUserCenterResponseVO.java

@@ -3,12 +3,12 @@ package com.ylx.usercenter.domain.vo;
 import lombok.Data;
 
 @Data
-public class UnifiedUserCenterResponseVO {
+public class UnifiedUserCenterResponseVO<L> {
 
     private Integer code;
     private String message;
     // 关键点:使用 Object 接收,因为后端可能返回 Map、List 或 Boolean
-    private Object data;
+    private L data;
 
     // 辅助方法:判断业务是否成功
     public boolean isSuccess() {

+ 3 - 0
nightFragrance-massage/src/main/java/com/ylx/usercenter/service/UnifiedUserCenterService.java

@@ -2,6 +2,7 @@ package com.ylx.usercenter.service;
 
 import com.ylx.common.core.domain.R;
 import com.ylx.usercenter.domain.dto.UnifiedUserCenterDTO;
+import com.ylx.usercenter.domain.vo.OneAccountVO;
 
 public interface UnifiedUserCenterService {
     R<?> queryBind(UnifiedUserCenterDTO dto);
@@ -9,4 +10,6 @@ public interface UnifiedUserCenterService {
     R<?> bind(UnifiedUserCenterDTO dto);
 
     R<?> unbind(UnifiedUserCenterDTO dto);
+
+    OneAccountVO queryClients(String uuid);
 }

+ 97 - 13
nightFragrance-massage/src/main/java/com/ylx/usercenter/service/impl/UnifiedUserCenterServiceImpl.java

@@ -1,9 +1,12 @@
 package com.ylx.usercenter.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.ylx.common.core.domain.R;
 import com.ylx.common.exception.ServiceException;
@@ -11,8 +14,8 @@ import com.ylx.lottery.service.LotteryCountService;
 import com.ylx.massage.domain.TWxUser;
 import com.ylx.massage.service.TWxUserService;
 import com.ylx.usercenter.domain.dto.UnifiedUserCenterDTO;
+import com.ylx.usercenter.domain.vo.OneAccountVO;
 import com.ylx.usercenter.domain.vo.UnifiedUserCenterResponseVO;
-import com.ylx.usercenter.domain.vo.UnifiedUserClientListVO;
 import com.ylx.usercenter.service.UnifiedUserCenterService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -22,6 +25,9 @@ import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
 
 @Slf4j
 @Service
@@ -29,13 +35,15 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
 
     @Value("${remote.user-center.base-url}")
     private String userCenterBaseUrl;
-    @Value("${remote.local-live.client-id}")
+    @Value("${remote.night-fragrance.client-id}")
     private String clientId;
 
     // 定义接口路径常量
     private static final String QUERY_BIND_PATH = "/userApp/queryBind";
     private static final String BIND_PATH = "/userApp/bind";
     private static final String UNBIND_PATH = "/userApp/unbind";
+    private static final String QUERY_CLIENTS_PATH = "/userApp/queryClients";
+    private static final int DEFAULT_TIMEOUT = 5000; // 5秒超时
     @Resource
     private TWxUserService wxUserService;
     @Resource
@@ -43,8 +51,6 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
 
     @Override
     public R<?> queryBind(UnifiedUserCenterDTO dto) {
-        validateDto(dto);
-//        dto.setClientId(clientId);
         // 只需要关注业务路径和日志描述即可
         return executePost(QUERY_BIND_PATH, dto, "查询用户绑定信息");
     }
@@ -67,7 +73,7 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
             R<?> remoteResult = executePost(BIND_PATH, dto, "添加用户绑定信息");
 
             // 4. 判断绑定成功
-            if (!remoteResult.getData().equals(Boolean.TRUE)) {
+            if (ObjUtil.notEqual(remoteResult.getCode(), 200)) {
                 log.error("远程绑定失败, userId: {}, msg: {}", dto.getSourceUserId(), remoteResult.getMsg());
                 return R.fail("用户绑定失败:" + remoteResult.getMsg());
             }
@@ -95,6 +101,12 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
         return executePost(UNBIND_PATH, dto, "解除用户绑定信息");
     }
 
+    @Override
+    public OneAccountVO queryClients(String uuid) {
+        log.info("调用一账通查询平台绑定信息:{}", uuid);
+        return this.queryClientsByUuid(uuid);
+    }
+
     /**
      * 通用 HTTP POST 请求执行模板
      */
@@ -127,7 +139,6 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
                 return R.fail(response.getData(), response.getMessage());
             }
 
-            // 5. 处理 data 字段
             Object dataObj = response.getData();
 
             // 情况 A: data 是布尔值 false (虽然 code=0,但没数据)
@@ -136,13 +147,27 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
                 return R.ok(response.getData());
             }
 
-            // 情况 B: data 是包含列表的对象 { "userClients": [...] }
-            if (dataObj instanceof UnifiedUserClientListVO) {
-                UnifiedUserClientListVO wrapper = (UnifiedUserClientListVO) dataObj;
-                return R.ok(wrapper.getUserClients(), response.getMessage());
+            // 情况 B: data 是 JSONObject (例如: { "userClients": [...] })
+            if (dataObj instanceof JSONObject) {
+                JSONObject jsonObject = (JSONObject) dataObj;
+
+                // 优先尝试获取 "userClients" 字段 (针对当前截图的场景)
+                Object userClientsObj = jsonObject.get("userClients");
+
+                if (userClientsObj instanceof JSONArray) {
+                    JSONArray userClientsArray = (JSONArray) userClientsObj;
+                    log.info("获取到用户客户端数量: {}", userClientsArray.size());
+                    // 如果需要转为具体的 List<UserClientVO>,可以在这里做转换
+                    return R.ok(userClientsArray);
+                }
+
+                // 兜底逻辑:如果是其他类型的 JSONObject (例如查询详情),直接返回整个对象
+                // 避免数据丢失
+                return R.ok(jsonObject);
             }
 
-            return R.ok();
+            // 情况 C: data 是其他类型 (例如直接是一个 String 或 Number)
+            return R.ok(dataObj);
 
         } catch (Exception e) {
             log.error("{}发生异常", logDesc, e);
@@ -161,8 +186,12 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
         if (StrUtil.isEmpty(dto.getTargetUserId())) {
             throw new IllegalArgumentException("目标用户ID不能为空");
         }
-        if (StrUtil.isEmpty(dto.getClientId())) {
-            throw new IllegalArgumentException("客户端ID不能为空");
+        if (StrUtil.isEmpty(dto.getSourceClientId())) {
+            throw new IllegalArgumentException("源客户端ID不能为空");
+        }
+
+        if (StrUtil.isEmpty(dto.getTargetClientId())) {
+            throw new IllegalArgumentException("目标客户端ID不能为空");
         }
     }
 
@@ -241,4 +270,59 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
             }
         }
     }
+
+
+    private OneAccountVO queryClientsByUuid(String uuid) {
+        try {
+            // 1. 构建请求参数
+            String url = userCenterBaseUrl + QUERY_CLIENTS_PATH;
+            Map<String, Object> params = Collections.singletonMap("uuid", uuid);
+
+            // 2. 发送请求
+            String resultJson = HttpUtil.get(url, params, DEFAULT_TIMEOUT);
+
+            // 3. 校验结果
+            if (StrUtil.isEmpty(resultJson)) {
+                throw new RuntimeException("调用一账通查询平台绑定信息接口失败:接口返回空结果");
+            }
+
+            // 4. 解析结果
+            UnifiedUserCenterResponseVO<List<OneAccountVO>> response = JSON.parseObject(
+                    resultJson,
+                    new TypeReference<UnifiedUserCenterResponseVO<List<OneAccountVO>>>() {
+                    }
+            );
+
+            // 5. 处理业务状态
+            if (ObjUtil.isNull(response) || !response.isSuccess()) {
+                String msg = ObjUtil.isNotNull(response) ? response.getMessage() : "未知错误";
+                Integer code = ObjUtil.isNotNull(response) ? response.getCode() : -1;
+
+                log.warn("调用一账通查询平台绑定信息接口失败: code={}, msg={}", code, msg);
+                throw new ServiceException("远程接口返回失败: " + msg);
+            }
+
+            // 6. 获取数据列表
+            List<OneAccountVO> oneAccountVOs = response.getData();
+
+            if (CollUtil.isEmpty(oneAccountVOs)) {
+                log.info("未查询到相关活动数据");
+                return null;
+            }
+
+            OneAccountVO oneAccount = oneAccountVOs.stream().filter(item -> item.getClientId().equals(clientId)).findFirst().orElse(null);
+
+            log.info("成功获取调用一账通查询平台绑定信息: {}", JSON.toJSONString(oneAccount));
+
+            return oneAccount;
+
+        } catch (ServiceException e) {
+            // 透传业务异常,不要重复包装
+            throw e;
+        } catch (Exception e) {
+            log.error("调用一账通查询平台绑定信息接口发生系统异常", e);
+            // 优化点:只抛出消息,不要直接把整个 Exception 对象 toString() 拼接到字符串里
+            throw new ServiceException("调用一账通查询平台绑定信息接口异常: " + e.getMessage());
+        }
+    }
 }