Jelajahi Sumber

平安财险配置修改

wks 2 tahun lalu
induk
melakukan
91a2a4fbc3

+ 5 - 0
pom.xml

@@ -561,6 +561,11 @@
             <version>2.3.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.bouncycastle</groupId>
+            <artifactId>bcprov-jdk15on</artifactId>
+            <version>1.56</version>
+        </dependency>
     </dependencies>
 
 

+ 0 - 1
src/main/java/com/ydtech/config/properties/BohaiApiConfigurationProperties.java

@@ -26,5 +26,4 @@ public class BohaiApiConfigurationProperties {
     private String insurerCode;
 
 
-
 }

+ 13 - 1
src/main/java/com/ydtech/config/properties/PingAnApiConfigurationProperties.java

@@ -12,10 +12,22 @@ import org.springframework.stereotype.Component;
  **/
 @Data
 @Component
-//@ConfigurationProperties(prefix = "ping.api")
+@ConfigurationProperties(prefix = "pingan.api")
 public class PingAnApiConfigurationProperties {
 
+    // 接口地址
+    private String url;
 
+    // 令牌地址
+    private String accessUrl;
 
+    // 我司公钥
+    private String selfPublicKey;
+
+    // 我司私钥
+    private String selfPrivateKey;
+
+    // 平安财险方公钥
+    private String pingAnPublicKey;
 
 }

+ 41 - 0
src/main/java/com/ydtech/modules/order/entity/api/pingan/constants/RequestUrl.java

@@ -0,0 +1,41 @@
+package com.ydtech.modules.order.entity.api.pingan.constants;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+
+
+/**
+ * @version
+ * @description: 平安
+ * @author: wenks
+ * @date: 2024/3/25 14:16
+ **/
+@AllArgsConstructor
+@Getter
+public enum RequestUrl {
+
+    R_001("001", "/property/chexian/query/searchPAVehicleList", "平安车型搜索接口"),
+    R_002("002", "/property/chexian/query/getPolicyPdf", "电子保单"),
+    R_31("31", "/property/chexian/insure/index", "标的检查"),
+    R_41("41", "/property/chexian/insure/renewalConfirm", "续保确认"),
+    R_42("42", "/property/chexian/insure/carConfirm", "车辆信息确认"),
+    R_43("43", "/property/chexian/insure/getDmvehicleInfo", "交管车辆验证码"),
+    R_44("44", "/property/chexian/insure/getUnAutoProductList", "获取财意险险种套餐列表"),
+    R_45("45", "/property/chexian/insure/ getUnAutoProductDetail", "获取财意险险种套餐责任信息"),
+    R_51("51", "/property/chexian/insure/quote", "保费计算"),
+    R_52("52", "/property/chexian/insure/queryServiceContract", "服务类特约检索"),
+    R_61("61", "/property/chexian/insure/submitApply", "补充信息并核保"),
+    R_78("78", "/property/getScanCodeURL", "二维码支付"),
+    R_82("82", "/property/chexian/insure/accept", "承保接口"),
+    R_91("91", "/property/chexian/insure/getDocumentStatusList", "单证状态查询"),
+    R_92("92", "/property/chexian/insure/repealDocument", "撤销单证"),
+    R_93("93", "/property/chexian/insure/uploadFiles", "资料上传");
+
+    private final String code;
+
+    private final String url;
+
+    private final String desc;
+
+}

+ 222 - 0
src/main/java/com/ydtech/modules/order/utils/PingAnRSAUtils.java

@@ -0,0 +1,222 @@
+package com.ydtech.modules.order.utils;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.log4j.lf5.util.StreamUtils;
+
+import javax.crypto.Cipher;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.security.*;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.*;
+
+public class PingAnRSAUtils {
+
+    private static String algorithm = "SHA256withRSA";
+
+    public static void main(String[] args) {
+        String keyword = "奥迪";
+        String userId = "123456789";
+        String oldSign = "Ugaug0keK0tm/4Aq9easzvNUDtnEELnXq6IS52tPSCmRVccfYZe3WvOt/RmIaO2JX8vDTHcA4X3zEzXTNpJ80+75Q1t" +
+                "/5hl5HafoWOYumRsbbywEtGtRZgngxKtNeQ6Jz/Jr6YlAki6g3y5XyKBKfE5EUpwjesR5QAZU7vs0vUY=";
+        String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCUoFBcJMk+rQhs" +
+                "/MpXcxY8ltZ3Pjxsxec9cIyJ8GIKHvueh92gstmvR4ebNV3PPD4LmL7yJlycz4n17+HGF1uGpNMN5j/EFds0boan5jpetLlQ43ylzqrzq+5VG7l2Gwe" +
+                "+YO6GSaJsstP0Av8GaXEZcGT2B0E1c5gx3XTo9th+uQIDAQAB";
+        String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJSgUFwkyT6tCGz8yldzFjyW1nc+PGzF5z1wjInwYgoe" +
+                "+56H3aCy2a9Hh5s1Xc88PguYvvImXJzPifXv4cYXW4ak0w3mP8QV2zRuhqfmOl60uVDjfKXOqvOr7lUbuXYbB75g7oZJomyy0/QC" +
+                "/wZpcRlwZPYHQTVzmDHddOj22H65AgMBAAECgYBKTh" +
+                "//AVEvqZiFzJhowhwC7LKKaS4Sf5rNZ8CLkgeh4b2Qk4KlPeWBMTTFzxd4bTjj2VjVfYJdz5C8yVJKFBFoa0w+P/g" +
+                "/YT5V8IqsRuF74eJeVScrBDqk5Tk5WpE/P" +
+                "+au8gWamHrJnsansfYDCArCfOf4T48pxq4i0LXgkbg6pQJBAMj2343kFRE1ViPI87F3g7dWJv2qLgEWX9xPM4HJdtQsRpuyV5n9UGp7Nn7i08sv4Rg9aLMOjtS97Sn4M6zssKcCQQC9VCQPsPxRejznNCVYTiq6hRhCXaK5ysrVLQXFs9I7gVX3CEA746GMV8iNIv7K7q9ZnKuj2ZHcreSriyMRTOGfAkBJQcUIYkZTuY+nB8/dt2VqZZtdCLYwa0mSc8Sg4SHSAjnS89X/KlowFq4s3t65yMBTJ7+M1he28W0MyY98z+MtAkAG7jCPvnvOA7p9ACSp0dqwjzSvITxWrry0BvziGs4ETZy2+T9YseF1ALWfrPtEtG4IyrphuhIj0N3BBcvX00ejAkBkc7AXJAb+Cn0rsGZe9ZdLogVWJKA5gTYy0ThSQ2SocoCLuy+rRlBX67rHN3/0BKF+byWaf/MTdc5QtbH5pK9J";
+        Map<String, String> bizdata = new HashMap<String, String>();
+        bizdata.put("keyword", keyword);
+        bizdata.put("userId", userId);
+        // 签名前先排序
+        String wtsign = sortParametersWithASCII(bizdata);
+        System.out.println(wtsign);
+        String signData = "";
+        try {
+            // 加签
+            signData = sign(wtsign, privateKey);
+            System.out.println(signData);
+        } catch (Exception se) {
+        }
+        //验签
+        Boolean verifyresult = verifySignRsa(bizdata, oldSign, publicKey);
+        System.out.println(verifyresult);
+        //解密方式
+        //原始加密串
+        String pwd = "g4otiaYyELiIEv2x9X4CDvMYfmWFZzV3VRDgzGCSjgyVR4FWxEKneEYJp" +
+                "/MvOfqkHfseuDnJvgnNKXDOUY37q40w4GoUiurIyXOaorhpjtrBJ9jmL3n3ExDHrq0kARnUjRuw3Y2dio9WocfpCMyW0XEAYaQQZtHcIs3k2lWbLYc=";
+        //解密
+        try {
+            System.out.println("解密后值为:" + rsaDecrypt(pwd, privateKey, "UTF-8"));
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+
+    public static String sign(String responseBody, String inPrivateKey) throws Exception {
+        byte[] dataEncode = Base64.encodeBase64(responseBody.getBytes("UTF-8"));
+        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(inPrivateKey.getBytes()));
+        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+        PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
+        Signature signatureChecker;
+        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
+        signatureChecker = Signature.getInstance(algorithm);
+        signatureChecker.initSign(privateKey);
+        signatureChecker.update(dataEncode);
+        byte[] sign = signatureChecker.sign();
+        return new String(Base64.encodeBase64(sign));
+    }
+
+    public static Boolean verifySignRsa(Map param, String signature, String verifyKey) {
+        if (!hasText(signature)) {
+            return false;
+        }
+        String wtsign = "";
+        wtsign = sortParametersWithASCII(param);
+        Boolean verifyresult = false;
+        verifyresult = verify(wtsign, signature, verifyKey);
+        //兼容partnerId不加密
+        if (!verifyresult) {
+            param.remove("partnerId");
+            wtsign = sortParametersWithASCII(param);
+            verifyresult = verify(wtsign, signature, verifyKey);
+        }
+        return verifyresult;
+    }
+
+    /**
+     * 验签
+     *
+     * @param businessdata 实际业务数据
+     * @param signedText   加密后待验证数据
+     * @return boolean
+     */
+    public static boolean verify(String businessdata, String signedText, String verifyKey) {
+        try {
+            String dataEncode = new String(Base64.encodeBase64(businessdata.getBytes("UTF-8")));
+            X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.decodeBase64(verifyKey.getBytes()));
+            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+            PublicKey publicKey = keyFactory.generatePublic(keySpec);
+            Signature signatureChecker = null;
+            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
+            signatureChecker = Signature.getInstance(algorithm);
+            signatureChecker.initVerify(publicKey);
+            signatureChecker.update(dataEncode.replace("\n", "").getBytes());
+            byte[] signBytes = signedText.getBytes("UTF-8");
+            byte[] sign = Base64.decodeBase64(signBytes);
+            return signatureChecker.verify(sign);
+        } catch (Exception e) {
+        }
+        return false;
+    }
+
+    public static String rsaDecrypt(String content, String privateKey, String charset) throws Exception {
+        return rsaDecrypt(content, privateKey, charset, null);
+    }
+
+    public static String rsaDecrypt(String content, String privateKey, String charset, String signType) throws Exception {
+        int maxDecryptBlock = 256;
+        try {
+            PrivateKey priKey = getPrivateKeyFromPKCS8("RSA", new ByteArrayInputStream(privateKey.getBytes()));
+            Cipher cipher = Cipher.getInstance("RSA");
+            cipher.init(2, priKey);
+            byte[] encryptedData = StringUtils.isEmpty(charset) ? Base64.decodeBase64(content.getBytes()) :
+                    Base64.decodeBase64(content.getBytes(charset));
+            int inputLen = encryptedData.length;
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            int offSet = 0;
+            int i = 0;
+            while (inputLen - offSet > 0) {
+                byte[] cache;
+                if (inputLen - offSet > maxDecryptBlock) {
+                    cache = cipher.doFinal(encryptedData, offSet, maxDecryptBlock);
+                } else {
+                    cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet);
+                }
+                out.write(cache, 0, cache.length);
+                i++;
+                offSet = i * maxDecryptBlock;
+            }
+            byte[] decryptedData = out.toByteArray();
+            out.close();
+
+            return StringUtils.isEmpty(charset) ? new String(decryptedData) : new String(decryptedData, charset);
+        } catch (Exception e) {
+            throw new Exception("RSA解密失败. EncodeContent = " + content + ",charset = " + charset, e);
+        }
+    }
+
+    public static PrivateKey getPrivateKeyFromPKCS8(String algorithm, InputStream ins) throws Exception {
+        if ((ins == null) || (StringUtils.isEmpty(algorithm))) {
+            return null;
+        }
+        KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
+        byte[] encodedKey = StreamUtils.getBytes(ins);
+        encodedKey = Base64.decodeBase64(encodedKey);
+        return keyFactory.generatePrivate(new PKCS8EncodedKeySpec(encodedKey));
+    }
+
+    public static boolean hasText(String str) {
+        if (!hasLength(str)) {
+            return false;
+        } else {
+            int strLen = str.length();
+
+            for (int i = 0; i < strLen; ++i) {
+                if (!Character.isWhitespace(str.charAt(i))) {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+    }
+
+    public static boolean hasLength(String str) {
+        return str != null && str.length() > 0;
+    }
+
+    public static String sortParametersWithASCII(Map param) {
+        List sortList = new LinkedList<String>();
+        Iterator listadd = param.keySet().iterator();
+        while (listadd.hasNext()) {
+            Object obj = listadd.next();
+            sortList.add(obj.toString());
+        }
+        //参数排序
+        Collections.sort(sortList);
+        String sortStr = "";
+        for (int i = 0; i < sortList.size(); i++) {
+            String paramListStr = "";
+            //对List数据进行排序
+            if (param.get(sortList.get(i)) instanceof java.util.List) {
+                List dataList = (List) param.get(sortList.get(i));
+                if (null != dataList && dataList.size() > 0) {
+                    Collections.sort(dataList);
+                    for (int k = 0; k < dataList.size(); k++) {
+                        paramListStr = paramListStr + dataList.get(k) + ",";
+                    }
+                    paramListStr = paramListStr.substring(0, paramListStr.length() - 1);
+
+                }
+                sortStr = sortStr + sortList.get(i) + "=" + paramListStr + "&";
+
+            } else {
+                sortStr = sortStr + sortList.get(i) + "=" + param.get(sortList.get(i)) + "&";
+
+            }
+
+        }
+        sortStr = sortStr.substring(0, sortStr.length() - 1);
+        return sortStr;
+
+    }
+}

+ 9 - 0
src/main/resources/application-pre.yml

@@ -288,6 +288,15 @@ bohai:
     boHaiPublicKey: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCIC3wgJd+7Wue63Qjdh3/uscQSKec2m9gaeCq007kjEiSFES5Tfx75VPSxRj6qk6XN4umHOsHY+W9jkv+Cj4+z3XpPozsRdoj21oxPx8fPJzpVeaUHrEkZtj9Yvo/KhByBK5sRjKmlENXVF3wXVfAg48JZR2XUyUcBdZhR9aHhoQIDAQAB
     insurerCode: 'BPIC'
 
+# 平安财险
+pingan:
+  api:
+    url: https://api.pingan.com.cn/open/appsvr
+    accessUrl: https://api.pingan.com.cn/oauth/oauth2/access_token
+    selfPublicKey:
+    selfPrivateKey:
+    pingAnPublicKey:
+
 knife4j:
   enable: false
 

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

@@ -287,6 +287,15 @@ bohai:
     boHaiPublicKey: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCIC3wgJd+7Wue63Qjdh3/uscQSKec2m9gaeCq007kjEiSFES5Tfx75VPSxRj6qk6XN4umHOsHY+W9jkv+Cj4+z3XpPozsRdoj21oxPx8fPJzpVeaUHrEkZtj9Yvo/KhByBK5sRjKmlENXVF3wXVfAg48JZR2XUyUcBdZhR9aHhoQIDAQAB
     insurerCode: 'BPIC'
 
+# 平安财险
+pingan:
+  api:
+    url: https://api.pingan.com.cn/open/appsvr
+    accessUrl: https://api.pingan.com.cn/oauth/oauth2/access_token
+    selfPublicKey:
+    selfPrivateKey:
+    pingAnPublicKey:
+
 knife4j:
   enable: false
 

+ 10 - 0
src/main/resources/application-test.yml

@@ -372,6 +372,16 @@ bohai:
     boHaiPublicKey: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCIC3wgJd+7Wue63Qjdh3/uscQSKec2m9gaeCq007kjEiSFES5Tfx75VPSxRj6qk6XN4umHOsHY+W9jkv+Cj4+z3XpPozsRdoj21oxPx8fPJzpVeaUHrEkZtj9Yvo/KhByBK5sRjKmlENXVF3wXVfAg48JZR2XUyUcBdZhR9aHhoQIDAQAB
     insurerCode: 'BPIC'
 
+
+# 平安财险
+pingan:
+  api:
+    url: https://test-api.pingan.com.cn:20443/open/appsvr
+    accessUrl: https://test-api.pingan.com.cn:20443/oauth/oauth2/access_token
+    selfPublicKey:
+    selfPrivateKey:
+    pingAnPublicKey:
+
 xxl:
   job:
     admin: