Explorar o código

merge: 修复华为 statusJson 编译阻断(fix/huawei-status-json)

Xiaogang Liao hai 5 días
pai
achega
31f5e31934

+ 35 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/huawei/HuaweiAuthService.java

@@ -293,6 +293,41 @@ public class HuaweiAuthService {
         return cnt != null && cnt.intValue() > 0;
     }
 
+    /**
+     * 绑定/通道状态 JSON(status 接口数据源;避免明文泄露)。
+     *
+     * <p>与 XiaomiAuthService.statusJson(Long) 同款契约:返回 bound/mock/channel/configured,
+     * 供 HuaweiHealthController.status() 组装前端展示;不涉及 token 明文。</p>
+     *
+     * @param memberId 家庭成员ID
+     * @return 含 bound/mock/channel/configured 的状态对象
+     */
+    public JSONObject statusJson(Long memberId) {
+        JSONObject obj = new JSONObject();
+        obj.put("memberId", memberId);
+        obj.put("bound", isBound(memberId));
+        obj.put("mock", mockEnabled);
+        if (mockEnabled) {
+            obj.put("channel", "mock");
+        } else {
+            obj.put("channel", "real");
+            obj.put("configured", clientId != null && !clientId.isEmpty()
+                    && clientSecret != null && !clientSecret.isEmpty());
+        }
+        // 有效授权过期时间(供前端展示;不涉及 token 明文)
+        try {
+            HuaweiHealthToken active = tokenMapper.selectOne(
+                    new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<HuaweiHealthToken>()
+                            .eq(HuaweiHealthToken::getMemberId, memberId)
+                            .eq(HuaweiHealthToken::getStatus, "ACTIVE"));
+            obj.put("expiresAt", active == null ? null : active.getExpiresAt());
+            obj.put("scope", active == null ? null : active.getScope());
+        } catch (Exception e) {
+            log.warn("华为状态查询 token 记录失败(忽略): memberId={}, error={}", memberId, e.getMessage());
+        }
+        return obj;
+    }
+
     private String encode(String s) {
         if (s == null) {
             return "";