|
@@ -2,7 +2,10 @@ package thyyxxk.webserver.utils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
import thyyxxk.webserver.constants.sidicts.SiFunction;
|
|
|
import thyyxxk.webserver.entity.ResultVo;
|
|
@@ -19,25 +22,26 @@ import java.util.*;
|
|
|
* @author: DingJie
|
|
|
* @create: 2021-05-14 16:41:21
|
|
|
**/
|
|
|
+@Component
|
|
|
public class SiUtil {
|
|
|
private static int serial = 1000;
|
|
|
private static final int MIN_VAL = 1000;
|
|
|
private static final int MAX_VAL = 9999;
|
|
|
private static final String REQ_HEADER_PREFIX = "yfb-";
|
|
|
- public static final String INSTUTUTION_AREA = "430105";
|
|
|
+ public static final String INSTITUTION_AREA = "430105";
|
|
|
public static final String INSTITUTION_ID = "H43010500370";
|
|
|
public static final String INSTITUTION_NAME = "长沙泰和医院";
|
|
|
- public static final String API_ACCESS_KEY = "OvwSdUUS3E9c9DtcEZ87jDTbKiw3k6dEZ9oeS1";
|
|
|
- public static final String API_SECRET_KEY = "SKQ42Wj9RTnlFzl53jAgkPyCTeNGeof9lwP36FN4";
|
|
|
-
|
|
|
-// public static final String INSTUTUTION_AREA = "431122";
|
|
|
-// public static final String INSTITUTION_ID = "H43112200226";
|
|
|
-// public static final String INSTITUTION_NAME = "东安县人民医院";
|
|
|
-// public static final String API_ACCESS_KEY = "OvwSdUUS3E9c9DtcEZ87jDTbKiw3k6dEZ9oeS1";
|
|
|
-// public static final String API_SECRET_KEY = "SKQ42Wj9RTnlFzl53jAgkPyCTeNGeof9lwP36FN4";
|
|
|
+ private static String apiAccessKey;
|
|
|
+ private static String apiSecretKey;
|
|
|
|
|
|
public static final String API_VERSION = "1.0.0";
|
|
|
|
|
|
+ @Autowired
|
|
|
+ public SiUtil(Environment environment) {
|
|
|
+ apiAccessKey = environment.getProperty("si-access-key");
|
|
|
+ apiSecretKey = environment.getProperty("si-secret-key");
|
|
|
+ }
|
|
|
+
|
|
|
private static String timestamp() {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
return sdf.format(new Date());
|
|
@@ -54,8 +58,8 @@ public class SiUtil {
|
|
|
public static HttpHeaders getHttpHeaders(SiFunction function) {
|
|
|
String timestamp = String.valueOf(System.currentTimeMillis());
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.add("_api_access_key", API_ACCESS_KEY);
|
|
|
- headers.add("_api_secreKey", API_SECRET_KEY);
|
|
|
+ headers.add("_api_access_key", apiAccessKey);
|
|
|
+ headers.add("_api_secreKey", apiSecretKey);
|
|
|
headers.add("_api_name", REQ_HEADER_PREFIX + function.getCode());
|
|
|
headers.add("_api_version", API_VERSION);
|
|
|
headers.add("_api_timestamp", timestamp);
|
|
@@ -65,7 +69,7 @@ public class SiUtil {
|
|
|
|
|
|
public static String getSignature(String timestamp, String function) {
|
|
|
String source =
|
|
|
- "_api_access_key=" + API_ACCESS_KEY +
|
|
|
+ "_api_access_key=" + apiAccessKey +
|
|
|
"&_api_name=" + REQ_HEADER_PREFIX + function +
|
|
|
"&_api_timestamp=" + timestamp +
|
|
|
"&_api_version=" + API_VERSION;
|
|
@@ -75,7 +79,7 @@ public class SiUtil {
|
|
|
private static String hmacSha1(String src) {
|
|
|
byte[] result = null;
|
|
|
try {
|
|
|
- SecretKeySpec signInKey = new SecretKeySpec(API_SECRET_KEY.getBytes(), "HmacSHA1");
|
|
|
+ SecretKeySpec signInKey = new SecretKeySpec(apiSecretKey.getBytes(), "HmacSHA1");
|
|
|
Mac mac = Mac.getInstance("HmacSHA1");
|
|
|
mac.init(signInKey);
|
|
|
byte[] rawHmac = mac.doFinal(src.getBytes());
|