Browse Source

修改签名生成方法

欧阳劲驰 3 weeks ago
parent
commit
783b10ec40

+ 2 - 12
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/IntegrationMetadata.java

@@ -6,16 +6,6 @@ package com.shkpr.service.customgateway.core.constants;
  * @author 欧阳劲驰
  * @since 1.0.0
  */
-public interface IntegrationMetadata {
-    /**
-     * 头
-     */
-    interface Headers {
-        //密钥
-        String APP_KEY = "appKey";
-        //时间戳
-        String TIMESTAMP = "timestamp";
-        //签名
-        String SIGN = "sign";
-    }
+public abstract class IntegrationMetadata {
+
 }

+ 10 - 26
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/IntegrationKey.java

@@ -1,12 +1,8 @@
 package com.shkpr.service.customgateway.core.domain;
 
+import lombok.AllArgsConstructor;
 import lombok.Data;
-import org.apache.commons.codec.digest.DigestUtils;
-
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.util.Map;
-import java.util.stream.Collectors;
+import lombok.NoArgsConstructor;
 
 /**
  * 集成密钥
@@ -15,6 +11,8 @@ import java.util.stream.Collectors;
  * @since 1.0.0
  */
 @Data
+@NoArgsConstructor(force = true)
+@AllArgsConstructor
 public class IntegrationKey {
     /**
      * 时间戳
@@ -23,31 +21,17 @@ public class IntegrationKey {
     /**
      * key
      */
-    private String appKey;
+    private String accessKey;
     /**
      * Secret
      */
-    private String appSecret;
-    /**
-     * 参数
-     */
-    private Map<String, String> params;
+    private String secretKey;
     /**
      * 签名
      */
     private String sign;
-
-    public IntegrationKey(String appKey, String appSecret, Map<String, String> params) {
-        this.appKey = appKey;
-        this.appSecret = appSecret;
-        this.params = params;
-        this.timestamp = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
-
-        //连接参数
-        String paramsStr = params.entrySet().stream()
-                .map(entry -> entry.getKey() + "=" + entry.getValue())
-                .collect(Collectors.joining("&"));
-        //签名密钥
-        this.sign = DigestUtils.md5Hex(this.appSecret + "&" + this.timestamp + "&" + paramsStr).toUpperCase();
-    }
+    /**
+     * 密钥
+     */
+    private String token;
 }

+ 0 - 11
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/CallingProperties.java

@@ -1,6 +1,5 @@
 package com.shkpr.service.customgateway.core.properties;
 
-import com.shkpr.service.customgateway.core.domain.IntegrationKey;
 import lombok.Data;
 import lombok.Getter;
 import lombok.Setter;
@@ -63,15 +62,5 @@ public class CallingProperties {
          * 密码
          */
         private String secretKey;
-
-        /**
-         * 获取密钥
-         *
-         * @param params 参数
-         * @return 密钥
-         */
-        public IntegrationKey getKey(Map<String, String> params) {
-            return new IntegrationKey(accessKey, secretKey, params);
-        }
     }
 }

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/InfoSynchronizer.java

@@ -67,10 +67,10 @@ public class InfoSynchronizer {
             put(MiddlePlatformMetadata.Params.PAGE_SIZE, pageable.getPageSize() + "");
         }}, params -> {
             //获取密钥
-            IntegrationKey key = endpoint.getKey(params);
+            IntegrationKey key = MiddlePlatformMetadata.getKey(endpoint.getAccessKey(), endpoint.getSecretKey(), params);
             //存入请求头
             return Arrays.asList(
-                    new BasicHeader(MiddlePlatformMetadata.Headers.APP_KEY, key.getAppKey()),
+                    new BasicHeader(MiddlePlatformMetadata.Headers.APP_KEY, key.getAccessKey()),
                     new BasicHeader(MiddlePlatformMetadata.Headers.TIMESTAMP, key.getTimestamp() + ""),
                     new BasicHeader(MiddlePlatformMetadata.Headers.SIGN, key.getSign())
             );

+ 45 - 5
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/constants/MiddlePlatformMetadata.java

@@ -1,6 +1,13 @@
 package com.shkpr.service.customgateway.zydma.constants;
 
 import com.shkpr.service.customgateway.core.constants.IntegrationMetadata;
+import com.shkpr.service.customgateway.core.domain.IntegrationKey;
+import org.apache.commons.codec.digest.DigestUtils;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 中台集成元数据
@@ -8,32 +15,65 @@ import com.shkpr.service.customgateway.core.constants.IntegrationMetadata;
  * @author 欧阳劲驰
  * @since 1.0.0
  */
-public interface MiddlePlatformMetadata extends IntegrationMetadata {
+public abstract class MiddlePlatformMetadata extends IntegrationMetadata {
     //系统名称
-    String NAME = "middlePlatform";
+    public static String NAME = "middlePlatform";
+
+    /**
+     * 获取密钥
+     *
+     * @param accessKey 公钥
+     * @param secretKey 私钥
+     * @param params    参数
+     * @return 密钥
+     */
+    public static IntegrationKey getKey(String accessKey, String secretKey, Map<String, String> params) {
+        //时间戳
+        long timestamp = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+        //连接参数
+        String paramsStr = params.entrySet().stream()
+                .map(entry -> entry.getKey() + "=" + entry.getValue())
+                .collect(Collectors.joining("&"));
+        //签名密钥
+        String sign = DigestUtils.md5Hex(secretKey + "&" + timestamp + "&" + paramsStr).toUpperCase();
+        return new IntegrationKey(timestamp, accessKey, secretKey, sign, null);
+    }
 
     /**
      * 接口地址
      */
-    interface Uri {
+    public interface Uri {
         //获取用户
         String GET_USERS = "/IntegrationAuth/GetUsers";
     }
 
     /**
+     * 头
+     */
+    public interface Headers {
+        //密钥
+        String APP_KEY = "appKey";
+        //时间戳
+        String TIMESTAMP = "timestamp";
+        //签名
+        String SIGN = "sign";
+    }
+
+    /**
      * 参数
      */
-    interface Params {
+    public interface Params {
         //页码
         String PAGE_NUMBER = "pageIndex";
         //分页大小
         String PAGE_SIZE = "pageSize";
     }
 
+
     /**
      * 默认值
      */
-    interface DefaultValues {
+    public interface DefaultValues {
         //角色id
         String ROLE_ID = "255";
         //组织