|
@@ -1,96 +0,0 @@
|
|
|
-package thyyxxk.simzfeeoprnsystm.utils;
|
|
|
-
|
|
|
-import thyyxxk.simzfeeoprnsystm.dicts.SiFunction;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-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 javax.crypto.Mac;
|
|
|
-import javax.crypto.spec.SecretKeySpec;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-
|
|
|
-/**
|
|
|
- * @description: 新医保交易工具类
|
|
|
- * @author: DingJie
|
|
|
- * @create: 2021-05-14 16:41:21
|
|
|
- **/
|
|
|
-@Component
|
|
|
-@Slf4j
|
|
|
-public class SiUtil {
|
|
|
- private static int DEFAULT_SERIAL_NO = 1000;
|
|
|
- private static final int MIN_SERIAL_NO = 1000;
|
|
|
- private static final int MAX_SERIAL_NO = 9999;
|
|
|
- public static final String INSTITUTION_AREA = "430105";
|
|
|
- public static final String INSTITUTION_ID = "H43010500370";
|
|
|
- public static final String INSTITUTION_NAME = "长沙泰和医院";
|
|
|
- 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");
|
|
|
- }
|
|
|
-
|
|
|
- public static String getInstitutionArea(String insureArea) {
|
|
|
- if ("".equals(insureArea)) {
|
|
|
- return INSTITUTION_AREA;
|
|
|
- }
|
|
|
- return insureArea.startsWith("4301") ? INSTITUTION_AREA : "439900";
|
|
|
- }
|
|
|
-
|
|
|
- private static String timestamp() {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
- return sdf.format(new Date());
|
|
|
- }
|
|
|
-
|
|
|
- public static synchronized String makeMsgId() {
|
|
|
- DEFAULT_SERIAL_NO += 1;
|
|
|
- if (DEFAULT_SERIAL_NO > MAX_SERIAL_NO) {
|
|
|
- DEFAULT_SERIAL_NO = MIN_SERIAL_NO;
|
|
|
- }
|
|
|
- return INSTITUTION_ID + timestamp() + DEFAULT_SERIAL_NO;
|
|
|
- }
|
|
|
-
|
|
|
- public static HttpHeaders getHttpHeaders(SiFunction function) {
|
|
|
- String timestamp = String.valueOf(System.currentTimeMillis());
|
|
|
- String signature = getSignature(timestamp, function.getCode());
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.add("apiAccessKey", apiAccessKey);
|
|
|
- headers.add("apiSecreKey", apiSecretKey);
|
|
|
- headers.add("apiName", function.getCode());
|
|
|
- headers.add("apiVersion", API_VERSION);
|
|
|
- headers.add("apiTimestamp", timestamp);
|
|
|
- headers.add("apiSignature", signature);
|
|
|
- return headers;
|
|
|
- }
|
|
|
-
|
|
|
- public static String getSignature(String timestamp, String function) {
|
|
|
- String source =
|
|
|
- "_api_access_key=" + apiAccessKey +
|
|
|
- "&_api_name=" + function +
|
|
|
- "&_api_timestamp=" + timestamp +
|
|
|
- "&_api_version=" + API_VERSION;
|
|
|
- return hmacSha1(source);
|
|
|
- }
|
|
|
-
|
|
|
- private static String hmacSha1(String src) {
|
|
|
- byte[] result = null;
|
|
|
- try {
|
|
|
- SecretKeySpec signInKey = new SecretKeySpec(apiSecretKey.getBytes(), "HmacSHA1");
|
|
|
- Mac mac = Mac.getInstance("HmacSHA1");
|
|
|
- mac.init(signInKey);
|
|
|
- byte[] rawHmac = mac.doFinal(src.getBytes());
|
|
|
- result = Base64.encodeBase64(rawHmac);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("HmacSHA1加密出错", e);
|
|
|
- }
|
|
|
- return null == result ? null : new String(result);
|
|
|
- }
|
|
|
-}
|