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);
|
}
|
|
}
|