Commit 2dc0b392 authored by 马超's avatar 马超

fix(微问诊): 修复请求工具类url错误的问题、删除冗余代码

parent 32e0971b
...@@ -65,7 +65,7 @@ public class CdfortisResponseUtil { ...@@ -65,7 +65,7 @@ public class CdfortisResponseUtil {
HttpUrl httpUrl = urlBuild.build(); HttpUrl httpUrl = urlBuild.build();
log.debug("request url: {} ", httpUrl.toString()); log.debug("request url: {} ", httpUrl.toString());
Request.Builder builder = new Request.Builder(); Request.Builder builder = new Request.Builder();
builder.url(url); builder.url(httpUrl);
// 处理请求头 // 处理请求头
if (headers != null) { if (headers != null) {
builder.headers(Headers.of(headers)); builder.headers(Headers.of(headers));
......
...@@ -69,8 +69,6 @@ public class PreDrugs implements Serializable { ...@@ -69,8 +69,6 @@ public class PreDrugs implements Serializable {
private Long createBy; private Long createBy;
/* 更新人 */ /* 更新人 */
private Long updateBy; private Long updateBy;
/* 价格 */
private String price;
public PreDrugs() { public PreDrugs() {
this.delFlag = false; this.delFlag = false;
......
package com.cftech.prescription.service;
import com.alibaba.fastjson.JSONObject;
/**
* 获取微问诊token Service
*
* @author :machao
* @date :Created in 2021/08/19 9:30
*/
public interface TokenService {
/**
* 获取微问诊token
*
* @return
*/
JSONObject getTokenResult();
}
package com.cftech.prescription.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.cftech.prescription.service.TokenService;
import com.cftech.prescription.utils.CdfortisTokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 获取微问诊token Service
*
* @author :machao
* @date :Created in 2021/08/19 9:30
*/
@Slf4j
@Service
public class TokenServiceImpl implements TokenService {
@Autowired
CdfortisTokenUtil cdfortisTokenUtil;
@Override
public JSONObject getTokenResult() {
JSONObject rtnJson = new JSONObject();
try {
String token = cdfortisTokenUtil.getToken();
rtnJson.put("errorNo", "0");
rtnJson.put("token", token);
} catch (Exception e) {
e.printStackTrace();
rtnJson.put("errorNo", "1");
rtnJson.put("errorMsg", e.getMessage());
rtnJson.put("errorEnMsg", e.getMessage());
}
return rtnJson;
}
}
package com.cftech.prescription.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cftech.core.util.OKHttpUtils;
import com.cftech.core.util.SystemConfig;
import com.qcloud.cos.utils.Md5Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
* 获取微问诊token Service
*
* @author :machao
* @date :Created in 2021/08/19 15:30
*/
@Slf4j
@Component
public class CdfortisTokenUtil {
/**
* 获取token的Url
*/
private static String tokenUrl = SystemConfig.p.getProperty("cdfortis.token_url");
/**
* appkey
*/
private static String appid = SystemConfig.p.getProperty("cdfortis.appid");
/**
* appSecrt
*/
private static String appSecret = SystemConfig.p.getProperty("cdfortis.secret");
/**
* flag
*/
private static String flag = SystemConfig.p.getProperty("cdfortis.flag");
/**
* redis存储key
*/
private static String CDFORTIS_TOKEN_KEY = "cdfortis_token" + ":" + appid;
/**
* 成功的返回值
*/
private static String RESULT_SUCC_CODE = "C00010000";
@Autowired
private RedisTemplate<String, String> redisTemplate;
private RedisTemplate<String, String> getConfig() {
StringRedisSerializer stringSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(stringSerializer);
return redisTemplate;
}
/**
* 获取token
*
* @return
*/
public String getToken() throws Exception {
// 检查redis中是否存在
if (getConfig().hasKey(CDFORTIS_TOKEN_KEY)) {
return redisTemplate.opsForValue().get(CDFORTIS_TOKEN_KEY);
}
long timestamp = System.currentTimeMillis();
// 获取签名
String sign = sign(appid, appSecret, flag, timestamp);
// 获取tokenUrl
String url = tokenUrl.replace("{appid}", appid).replace("{flag}", flag)
.replace("{timestamp}", timestamp + "").replace("{sign}", sign);
log.debug("微问诊token请求地址:{}", url);
try {
// 解析结果
String retStr = OKHttpUtils.getJSON(url);
log.debug("微问诊token请求结果:{}", retStr);
JSONObject retObj = JSON.parseObject(retStr);
JSONObject returnCode = retObj.getJSONObject("returnCode");
if (!RESULT_SUCC_CODE.equals(returnCode.getString("key"))) {
log.error(returnCode.toJSONString());
throw new Exception(returnCode.getString("content"));
}
JSONObject data = retObj.getJSONObject("data");
String token = data.getString("token");
Long expire = data.getLongValue("expire");
//存到redis
redisTemplate.opsForValue().set(CDFORTIS_TOKEN_KEY, token, expire, TimeUnit.SECONDS);
return token;
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new Exception(e.getMessage());
}
}
/**
* 获取签名
*
* @param appId
* @param secret
* @param flag
* @param timestamp
* @return
*/
private String sign(String appId, String secret, String flag, long timestamp) {
String signStr = String.format("appid=%s&flag=%s&secret=%s&timestamp=%s", appId, flag, secret, timestamp);
String sign = Md5Utils.md5Hex(signStr.getBytes());
return sign;
}
}
package com.cftech.prescription.web;
import com.alibaba.fastjson.JSONObject;
import com.cftech.prescription.service.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 获取微问诊token
*
* @author :machao
* @date :Created in 2021/08/19 9:30
*/
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/mobile/auth/cdfortis")
public class CdfortisTokenController {
@Autowired
TokenService tokenService;
@GetMapping("get/token")
public JSONObject getToken() {
return tokenService.getTokenResult();
}
}
GET http://localhost:8080/aidea/a/prescription/list ### 获取token
GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/token
### ### 药品清单上传
POST http://localhost:8080/aidea/mobile/auth/cdfortis/upload/druginfo POST http://localhost:8080/aidea/mobile/auth/cdfortis/upload/druginfo
Content-Type: application/json Content-Type: application/json
...@@ -13,7 +14,13 @@ Content-Type: application/json ...@@ -13,7 +14,13 @@ Content-Type: application/json
"drugCompay": "xx药业" "drugCompay": "xx药业"
}] }]
### ### 获取图文处方列表接口
GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/list?iDisplayStart=1&iDisplayLength=10&startTime=2020-09-07 00:00:00&endTime=2020-09-14 23:59:59 GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/list?iDisplayStart=1&iDisplayLength=10&startTime=2020-09-07 00:00:00&endTime=2020-09-14 23:59:59
### 获取图文处方图片
GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/picture?presId=123456
### 获取单条图文处方详情
GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/detail?presId=123456
### ###
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment