xuhy
2026-01-23 a69908c4f93094ee3590304fb4fb50142861a92f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.ruoyi.system.utils.xiMaUtil;
 
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.system.model.TSysAiConfig;
import com.ruoyi.system.service.TSysAiConfigService;
import com.ruoyi.system.utils.util.HttpClientUtils;
import com.ruoyi.system.utils.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
@Slf4j
@Component
public class XimaAIUtil {
 
    @Autowired
    private TSysAiConfigService sysAiConfigService;
 
    /**
     * 获取舌面授权H5页面链接接口
     */
    public static final String AUTHORIZATION_H5_URL_TEST = "http://61.169.68.85:6008/open/web/auth/tongue_face";
    public static final String AUTHORIZATION_H5_URL_PROD = "http://rest.ximalife.com:6008/open/web/auth/tongue_face";
 
    /**
     * 获取舌面授权H5页面链接接口
     * @param out_user_id 外部用户唯一标志
     * @param nickname 用户昵称,也可用“真实姓名”
     * @param phone     手机号码
     * @param sex   性别(0 男 1 女)
     * @param height 身高(cm)
     * @param weight 体重(kg)
     * @param device_type 设备类型:android ios
     * @return
     */
    public JSONObject getAuthorizationH5(String out_user_id,String nickname,String phone,String sex,String birthday,Integer height,Integer weight,String device_type) {
        TSysAiConfig sysAiConfig = sysAiConfigService.getById(1);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("client_id", sysAiConfig.getClientId());
        jsonObject.put("client_secret", sysAiConfig.getClientSecret());
        jsonObject.put("out_user_id", out_user_id);
        jsonObject.put("nickname", nickname);
        jsonObject.put("phone", phone);
        jsonObject.put("birthday", birthday);
        jsonObject.put("sex", sex);
        jsonObject.put("height", height);
        jsonObject.put("weight", weight);
        jsonObject.put("device_type", device_type);
 
        String result = HttpClientUtils.postFrom(AUTHORIZATION_H5_URL_PROD, JsonUtils.toJsonString(jsonObject));
        log.info("获取舌面授权H5页面链接接口:{}", result);
        JSONObject object = JSONObject.parseObject(result);
        if(!object.getBoolean("ok")){
            JSONObject error = object.getJSONObject("error");
            throw new ServiceException(error.getString("err_msg"));
        }
        JSONObject data = object.getJSONObject("data");
        String accessToken = data.getString("access_token");
        Integer expiresIn = data.getInteger("expires_in");
        String requestUrl = data.getString("request_url");
        JSONObject response = new JSONObject();
        response.put("access_token", accessToken);
        response.put("expires_in", expiresIn);
        response.put("request_url", requestUrl);
        log.info("获取舌面授权H5页面返回信息:{}", response);
        return response;
    }
 
    public static void main(String[] args) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("client_id", "xima_0003");
        jsonObject.put("client_secret", "7987dfafafaf8798dfafadfadff");
        jsonObject.put("out_user_id", "5f68e822-72bb-42cd-ad11-4c2102942dd2");
        jsonObject.put("nickname", "周帅");
        jsonObject.put("phone", "19983174515");
        jsonObject.put("sex", "0");
        jsonObject.put("height", 170);
        jsonObject.put("weight", 65);
        jsonObject.put("device_type", "android");
 
        String result = HttpClientUtils.postFrom(AUTHORIZATION_H5_URL_TEST, JsonUtils.toJsonString(jsonObject));
        log.info("获取舌面授权H5页面链接接口:{}", result);
        JSONObject object = JSONObject.parseObject(result);
        if(!object.getBoolean("ok")){
            JSONObject error = object.getJSONObject("error");
            throw new ServiceException(error.getString("err_msg"));
        }
        JSONObject data = object.getJSONObject("data");
        String accessToken = data.getString("access_token");
        Integer expiresIn = data.getInteger("expires_in");
        String requestUrl = data.getString("request_url");
        JSONObject response = new JSONObject();
        response.put("access_token", accessToken);
        response.put("expires_in", expiresIn);
        response.put("request_url", requestUrl);
        log.info("获取舌面授权H5页面返回信息:{}", response);
    }
 
}