Browse Source

[华信科] 龙旗对接 配置修改

zxl 1 week ago
parent
commit
6ee29e4c0e

+ 50 - 4
src/main/java/com/uas/eis/longcheer/config/LongcheerConfig.java

@@ -35,12 +35,14 @@ public class LongcheerConfig {
     private java.util.Map<String, String> supplierMapping = new java.util.HashMap<String, String>();
 
     public static class Inventory {
-        /** 应用密钥 Key */
+        /** 应用密钥 Key(默认值,credentials 未匹配时使用) */
         private String appKey;
-        /** 应用密钥 Secret */
+        /** 应用密钥 Secret(默认值,credentials 未匹配时使用) */
         private String appSecret;
         /** 接口地址 */
         private String url;
+        /** 按 master 区分的凭证映射,key=master,value=该 master 对应的 appKey/appSecret */
+        private java.util.Map<String, Credential> credentials = new java.util.HashMap<String, Credential>();
 
         public String getAppKey() {
             return appKey;
@@ -65,15 +67,25 @@ public class LongcheerConfig {
         public void setUrl(String url) {
             this.url = url;
         }
+
+        public java.util.Map<String, Credential> getCredentials() {
+            return credentials;
+        }
+
+        public void setCredentials(java.util.Map<String, Credential> credentials) {
+            this.credentials = credentials;
+        }
     }
 
     public static class Po {
-        /** 应用密钥 Key */
+        /** 应用密钥 Key(默认值,credentials 未匹配时使用) */
         private String appKey;
-        /** 应用密钥 Secret */
+        /** 应用密钥 Secret(默认值,credentials 未匹配时使用) */
         private String appSecret;
         /** 接口地址 */
         private String url;
+        /** 按 elsAccount 区分的凭证映射,key=elsAccount,value=该 elsAccount 对应的 appKey/appSecret */
+        private java.util.Map<String, Credential> credentials = new java.util.HashMap<String, Credential>();
 
         public String getAppKey() {
             return appKey;
@@ -98,6 +110,40 @@ public class LongcheerConfig {
         public void setUrl(String url) {
             this.url = url;
         }
+
+        public java.util.Map<String, Credential> getCredentials() {
+            return credentials;
+        }
+
+        public void setCredentials(java.util.Map<String, Credential> credentials) {
+            this.credentials = credentials;
+        }
+    }
+
+    /**
+     * 凭证信息(appKey + appSecret)
+     */
+    public static class Credential {
+        /** 应用密钥 Key */
+        private String appKey;
+        /** 应用密钥 Secret */
+        private String appSecret;
+
+        public String getAppKey() {
+            return appKey;
+        }
+
+        public void setAppKey(String appKey) {
+            this.appKey = appKey;
+        }
+
+        public String getAppSecret() {
+            return appSecret;
+        }
+
+        public void setAppSecret(String appSecret) {
+            this.appSecret = appSecret;
+        }
     }
 
     public Inventory getInventory() {

+ 15 - 3
src/main/java/com/uas/eis/longcheer/controller/LongcheerController.java

@@ -65,12 +65,24 @@ public class LongcheerController {
             @RequestHeader(value = "x-app-secret", required = false) String appSecret,
             @RequestBody PoPushRequest request) {
 
-        // 鉴权验证:校验 x-app-key 和 x-app-secret
-        String configAppKey = longcheerConfig.getPo().getAppKey();
+        // 鉴权验证:根据 elsAccount 动态获取配置的 appKey/appSecret
+            String configAppKey = longcheerConfig.getPo().getAppKey();
         String configAppSecret = longcheerConfig.getPo().getAppSecret();
+        java.util.Map<String, LongcheerConfig.Credential> poCredentials =
+                longcheerConfig.getPo().getCredentials();
+        if (poCredentials != null && request != null && !isBlank(request.getElsAccount())) {
+            LongcheerConfig.Credential cred = poCredentials.get(request.getElsAccount().trim());
+            if (cred != null) {
+                configAppKey = cred.getAppKey();
+                configAppSecret = cred.getAppSecret();
+                logger.info("[龙旗接口]采购订单鉴权使用elsAccount={}对应凭证,appKey={}",
+                        request.getElsAccount().trim(), configAppKey);
+            }
+        }
         if (isBlank(appKey) || isBlank(appSecret)
                 || !appKey.equals(configAppKey) || !appSecret.equals(configAppSecret)) {
-            logger.warn("[龙旗接口]采购订单接收鉴权失败,appKey={}", appKey);
+            logger.warn("[龙旗接口]采购订单接收鉴权失败,appKey={},elsAccount={}", appKey,
+                    request == null ? null : request.getElsAccount());
             return new LongcheerResponse(401, "鉴权失败:x-app-key或x-app-secret不正确", false);
         }
 

+ 11 - 1
src/main/java/com/uas/eis/longcheer/serviceImpl/LongcheerServiceImpl.java

@@ -74,9 +74,19 @@ public class LongcheerServiceImpl implements LongcheerService {
 
         // 调用龙旗接口
         String url = longcheerConfig.getInventory().getUrl();
-        // 需要提供
+        // 根据 master 动态获取 appKey/appSecret,未匹配时使用默认值
         String appKey = longcheerConfig.getInventory().getAppKey();
         String appSecret = longcheerConfig.getInventory().getAppSecret();
+        java.util.Map<String, LongcheerConfig.Credential> inventoryCredentials =
+                longcheerConfig.getInventory().getCredentials();
+        if (inventoryCredentials != null && !isBlank(master)) {
+            LongcheerConfig.Credential cred = inventoryCredentials.get(master.trim());
+            if (cred != null) {
+                appKey = cred.getAppKey();
+                appSecret = cred.getAppSecret();
+                logger.info("[龙旗接口]库存推送使用master={}对应凭证,appKey={}", master.trim(), appKey);
+            }
+        }
 
         String requestBody = JSON.toJSONString(request);
         logger.info("[龙旗接口]调用库存同步接口,url={}", url);

+ 16 - 3
src/main/resources/application-dev.yml

@@ -35,10 +35,26 @@ longcheer:
         app-key: 4865982d
         app-secret: cc0486b594134a679ff8a0d94144d685
         url: https://srm-uat.longcheer.com:8019/els/supplierApi/invokeSrm/inventoryReceive
+        # 按 master 区分的 app-key/app-secret
+        credentials:
+            LHWX_SZ_P:
+                app-key: 1f4cfda7
+                app-secret: b43523ab7eb94d9e824245f3a09d115d
+            LHWX_HK_P:
+                app-key: 4865982d
+                app-secret: cc0486b594134a679ff8a0d94144d685
     po:
         app-key: a23b0e49
         app-secret: cce462b6026f49e8b49e66d27c76b785
         url: https://srm-uat.longcheer.com:8019/api/v1/po/push
+        # 按 elsAccount 区分的 app-key/app-secret
+        credentials:
+            3582452:
+                app-key: 219f6156
+                app-secret: 41333e82b88241b9a5a5e0c061856d6d
+            3582700:
+                app-key: a23b0e49
+                app-secret: cce462b6026f49e8b49e66d27c76b785
     timeout: 30000
     retry-times: 3
     retry-interval: 30000
@@ -50,6 +66,3 @@ longcheer:
     supplier-mapping:
         LHWX_SZ_P: 103362
         LHWX_HK_P: 101661
-
-
-

+ 16 - 0
src/main/resources/application-prod.yml

@@ -35,10 +35,26 @@ longcheer:
         app-key: 4865982d
         app-secret: cc0486b594134a679ff8a0d94144d685
         url: https://srm-uat.longcheer.com:8019/els/supplierApi/invokeSrm/inventoryReceive
+        # 按 master 区分的 app-key/app-secret
+        credentials:
+            LHWX_SZ_P:
+                app-key: 1f4cfda7
+                app-secret: b43523ab7eb94d9e824245f3a09d115d
+            LHWX_HK_P:
+                app-key: 4865982d
+                app-secret: cc0486b594134a679ff8a0d94144d685
     po:
         app-key: a23b0e49
         app-secret: cce462b6026f49e8b49e66d27c76b785
         url: https://srm-uat.longcheer.com:8019/api/v1/po/push
+        # 按 elsAccount 区分的 app-key/app-secret
+        credentials:
+            3582452:
+                app-key: 219f6156
+                app-secret: 41333e82b88241b9a5a5e0c061856d6d
+            3582700:
+                app-key: a23b0e49
+                app-secret: cce462b6026f49e8b49e66d27c76b785
     timeout: 30000
     retry-times: 3
     retry-interval: 30000