6666
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
package net.lab1024.sa.admin.extend.fangxinqian;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.common.common.exception.BusinessException;
|
||||
import net.lab1024.sa.common.module.support.redis.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class Base {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Value("${fxq.client-id}")
|
||||
private static String clientId;
|
||||
|
||||
@Value("${fxq.client-secret}")
|
||||
private static String clientSecret;
|
||||
|
||||
@Value("${fxq.client-url}")
|
||||
private static String clientUrl;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 发送 POST JSON 请求
|
||||
* @param url 请求地址
|
||||
* @param jsonData JSON 字符串
|
||||
* @param headers 请求头
|
||||
* @return 响应字符串
|
||||
*/
|
||||
public String postJson(String url, String jsonData, Map<String, String> headers) {
|
||||
// 获取token
|
||||
String tokenKey = "fangxinqian:" + clientId;
|
||||
String token = redisService.get(tokenKey);
|
||||
if (token == null) {
|
||||
token = getAccessToken();
|
||||
}
|
||||
|
||||
// 刷新token
|
||||
HttpRequest request = HttpRequest.post(url)
|
||||
.body(jsonData)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer " + token);
|
||||
|
||||
if (headers != null) {
|
||||
headers.forEach(request::header);
|
||||
}
|
||||
|
||||
try (HttpResponse response = request.execute()) {
|
||||
JSONObject json = JSONUtil.parseObj(response.body());
|
||||
|
||||
log.info("获取app数据返回:{}",json);
|
||||
|
||||
int code = json.getInt("code", -1);
|
||||
if (code == 10000) {
|
||||
return response.body();
|
||||
} else if (code == 10005) {
|
||||
// token 失效,重新获取
|
||||
getAccessToken();
|
||||
|
||||
return postJson(url,jsonData,headers);
|
||||
}else{
|
||||
throw new BusinessException(json.getStr("message", "操作失败"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getAccessToken(){
|
||||
String url = String.format("%s?grant_type=client_credentials&client_id=%s&client_secret=%s",
|
||||
"https://saasapi.fangxinqian.cn/oauth/token", clientId, clientSecret);
|
||||
|
||||
HttpRequest request = HttpRequest.post(url);
|
||||
|
||||
try (HttpResponse response = request.execute()) {
|
||||
if (response.getStatus() != 200) {
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
JSONObject json = JSONUtil.parseObj(response.body());
|
||||
|
||||
log.info("获取app数据返回:{}",json);
|
||||
|
||||
String accessToken = json.getStr("access_token");
|
||||
if (accessToken == null || accessToken.isEmpty()) {
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
Integer expiresIn = json.getInt("expires_in");
|
||||
if (expiresIn == null || expiresIn <= 0) {
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
String tokenKey = "fangxinqian:" + clientId;
|
||||
redisService.set(tokenKey,accessToken,(expiresIn - 120));
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
public class R
|
||||
{
|
||||
/** 接口调用状态。200:正常;其它值:调用出错 */
|
||||
private int code;
|
||||
|
||||
/** 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok */
|
||||
private String msg;
|
||||
|
||||
/** 接口是否调用成功 */
|
||||
private boolean success;
|
||||
|
||||
/** 错误信息或提示信息 */
|
||||
private String message;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.lab1024.sa.admin.extend.fangxinqian;
|
||||
|
||||
/**
|
||||
* 企业账号
|
||||
*/
|
||||
public class Company {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.lab1024.sa.admin.extend.fangxinqian;
|
||||
|
||||
/**
|
||||
* 个人账号
|
||||
*/
|
||||
public class Personal {
|
||||
}
|
||||
+2
-4
@@ -229,8 +229,7 @@ public class ExpertController {
|
||||
// 获取白名单用户-姓名、医院名称
|
||||
ExpertWhiteEntity expertWhiteEntity = expertWhiteEntityService.getExpertWhiteEntityByNameAndHospitalName(name,hospital_name);
|
||||
if (expertWhiteEntity == null) {
|
||||
responseDTO.setMsg("暂无登录权限");
|
||||
return responseDTO;
|
||||
return ResponseDTO.error(NO_AUTH);
|
||||
}
|
||||
|
||||
ExpertEntity expert = new ExpertEntity();
|
||||
@@ -472,8 +471,7 @@ public class ExpertController {
|
||||
// 获取白名单用户-姓名、医院名称
|
||||
ExpertWhiteEntity expertWhiteEntity = expertWhiteEntityService.getExpertWhiteEntityByNameAndHospitalName(name,hospital_name);
|
||||
if (expertWhiteEntity == null) {
|
||||
responseDTO.setMsg("暂无登录权限");
|
||||
return responseDTO;
|
||||
return ResponseDTO.error(NO_AUTH);
|
||||
}
|
||||
|
||||
ExpertEntity expert = new ExpertEntity();
|
||||
|
||||
-1
@@ -9,7 +9,6 @@ import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class DpmsAddForm {
|
||||
|
||||
@ApiModelProperty(value = "治疗时间", required = true)
|
||||
@NotNull(message = "治疗时间 不能为空")
|
||||
private LocalDateTime treatTime;
|
||||
|
||||
@@ -12,6 +12,13 @@ server:
|
||||
spring:
|
||||
profiles:
|
||||
active: '@profiles.active@'
|
||||
data:
|
||||
redis:
|
||||
host: '139.155.127.177'
|
||||
port: 30002
|
||||
password: gdxz2022&dj.
|
||||
database: 11
|
||||
timeout: 3000
|
||||
|
||||
# 项目配置
|
||||
project:
|
||||
@@ -40,4 +47,9 @@ igandan:
|
||||
token: XUUHml5iQ9mlFsa8QqOwyBrLI2nGGGxJ
|
||||
platform: case
|
||||
doc:
|
||||
host: https://dev-doc.igandan.com/app/
|
||||
host: https://dev-doc.igandan.com/app/
|
||||
|
||||
fxq:
|
||||
client-id: Md7w4eaZih
|
||||
client-secret: 97acf8ebb09641cbb90accf06e74ccf5
|
||||
client-url: https://saasapi.fangxinqian.cn/openapi/v2/
|
||||
Reference in New Issue
Block a user