Просмотр исходного кода

招行支付2.0—公钥秘钥地址由配置文件调整到数据库服务商表

ZhangWenQiang 4 лет назад
Родитель
Сommit
5b6a711eba

+ 5 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/common/zhutils/RsaUtils.java

@@ -1,5 +1,7 @@
 package org.jeecg.common.zhutils;
 
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+
 import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -10,6 +12,7 @@ import java.net.URLConnection;
 import java.security.KeyFactory;
 import java.security.PrivateKey;
 import java.security.PublicKey;
+import java.security.Security;
 import java.security.spec.PKCS8EncodedKeySpec;
 import java.security.spec.X509EncodedKeySpec;
 
@@ -28,6 +31,7 @@ public class RsaUtils {
      * @throws Exception
      */
     public static PublicKey getPublicKey(String filename) throws Exception {
+        Security.addProvider(new BouncyCastleProvider());
         String crtBase64 = readFile(filename);
         return getPublicKeys(crtBase64);
     }
@@ -40,6 +44,7 @@ public class RsaUtils {
      * @throws Exception
      */
     public static PrivateKey getPrivateKey(String filename) throws Exception {
+        Security.addProvider(new BouncyCastleProvider());
         String crtBase64 = readFile(filename);
         return getPrivateKeys(crtBase64);
     }

+ 18 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwsubcontractor/entity/HlwSubcontractor.java

@@ -130,6 +130,24 @@ public class HlwSubcontractor implements Serializable {
     private String trsTyp;
 
     /**
+     * 公钥地址(免前置)
+     */
+    @ApiModelProperty(value = "公钥地址(免前置)")
+    private String pubKeyUrl;
+
+    /**
+     * 私钥地址(免前置)
+     */
+    @ApiModelProperty(value = "私钥地址(免前置)")
+    private String priKeyUrl;
+
+    /**
+     * aes加密(免前置)
+     */
+    @ApiModelProperty(value = "aes加密(免前置)")
+    private String aesKey;
+
+    /**
      * 创建时间
      */
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")

+ 27 - 34
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/utils/PayRsaCommon.java

@@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.apache.commons.lang3.StringUtils;
-import org.jeecg.common.zhutils.PayConst;
-import org.jeecg.common.zhutils.PayRequest;
-import org.jeecg.common.zhutils.RandomRequest;
-import org.jeecg.common.zhutils.RsaKeyProperties;
+import org.jeecg.common.zhutils.*;
 import org.jeecg.modules.hlwpayaccount.entity.HlwPayAccountCmb;
 import org.jeecg.modules.hlwpayaccount.entity.HlwPayRecord;
 import org.jeecg.modules.hlwpayaccount.service.IHlwPayAccountCmbService;
@@ -33,28 +30,24 @@ import java.util.stream.Stream;
 public class PayRsaCommon {
     @Autowired
     private IHlwPayAccountCmbService hlwPayAccountCmbService;
-    @Autowired
-    private RsaKeyProperties rsaKeyProperties;
 
     public static PayRsaCommon payCommon;
 
     public static IHlwPayAccountCmbService iHlwPayAccountCmbService;
-    public static RsaKeyProperties iRsaKeyProperties;
 
     @PostConstruct
     public void init() {
         payCommon = this;
         iHlwPayAccountCmbService = hlwPayAccountCmbService;
-        iRsaKeyProperties = rsaKeyProperties;
     }
 
     /**
      * 账户信息查询
      *
-     * @param hlgSubcontractor
+     * @param hlwSubcontractor
      * @return
      */
-    public static List<HlwPayAccountCmb> DCLISACC(HlwSubcontractor hlgSubcontractor) {
+    public static List<HlwPayAccountCmb> DCLISACC(HlwSubcontractor hlwSubcontractor) {
         List<HlwPayAccountCmb> hlwPayAccountCmbList = new ArrayList<>();
         try {
             // body
@@ -62,11 +55,11 @@ public class PayRsaCommon {
             //funCode接口名称
             String funCode = PayConst.DCLISACC;
             //业务类别
-            obj_body.put("buscod", hlgSubcontractor.getBuscod());
+            obj_body.put("buscod", hlwSubcontractor.getBuscod());
             //业务模式
-            obj_body.put("busmod", hlgSubcontractor.getBusmod());
-            String result = PayRequest.doRequest(obj_body, funCode, hlgSubcontractor.getUserId(), hlgSubcontractor.getPaymentUrl(),
-                    iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
+            obj_body.put("busmod", hlwSubcontractor.getBusmod());
+            String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
+                    RsaUtils.getPublicKey(hlwSubcontractor.getPubKeyUrl()), RsaUtils.getPrivateKey(hlwSubcontractor.getPriKeyUrl()), hlwSubcontractor.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
                 JSONObject jsonObject1 = jsonObject.getJSONObject("response");
@@ -80,7 +73,7 @@ public class PayRsaCommon {
                         JSONObject jsonObject2 = jsonArray.getJSONObject(i);
                         System.out.println("账号========" + jsonObject2.get("accnbr"));
                         System.out.println("户名========" + jsonObject2.get("accnam"));
-                        HlwPayAccountCmb hlwPayAccountCmb = iHlwPayAccountCmbService.saveAccout(jsonObject2, hlgSubcontractor.getId());
+                        HlwPayAccountCmb hlwPayAccountCmb = iHlwPayAccountCmbService.saveAccout(jsonObject2, hlwSubcontractor.getId());
                         hlwPayAccountCmbList.add(hlwPayAccountCmb);
                     }
                     System.out.println("head========" + jsonObjectHead.getString("resultcode"));
@@ -100,26 +93,26 @@ public class PayRsaCommon {
     /**
      * 代发交易代码查询
      */
-    public static void NTAGTLS2(HlwSubcontractor hlgSubcontractor) {
+    public static void NTAGTLS2(HlwSubcontractor hlwSubcontractor) {
         try {
             // body
             JSONObject obj_body = new JSONObject();
             //funCode接口名称
             String funCode = PayConst.NTAGTLS2;
             //账户
-            HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlgSubcontractor);
+            HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlwSubcontractor);
             /**
              * 查询条件
              */
             JSONArray jsonArrayRequest = new JSONArray();
             JSONObject jsonObjectRequest = new JSONObject();
-            jsonObjectRequest.put("buscod", hlgSubcontractor.getBuscod());
+            jsonObjectRequest.put("buscod", hlwSubcontractor.getBuscod());
             jsonObjectRequest.put("accnbr", hlwPayAccountCmb.getAccnbr());
             jsonArrayRequest.add(jsonObjectRequest);
             //查询条件
             obj_body.put("ntagtls2x", jsonArrayRequest);
-            String result = PayRequest.doRequest(obj_body, funCode, hlgSubcontractor.getUserId(), hlgSubcontractor.getPaymentUrl(),
-                    iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
+            String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
+                    RsaUtils.getPublicKey(hlwSubcontractor.getPubKeyUrl()), RsaUtils.getPrivateKey(hlwSubcontractor.getPriKeyUrl()), hlwSubcontractor.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
                 JSONObject jsonObject1 = jsonObject.getJSONObject("response");
@@ -259,7 +252,7 @@ public class PayRsaCommon {
             obj_body.put("ntagcagcx1", jsonArrayRequest2);
             obj_body.put("ntagcdtly1", jsonArrayRequest3);
             String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
-                    iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
+                    RsaUtils.getPublicKey(hlwSubcontractor.getPubKeyUrl()), RsaUtils.getPrivateKey(hlwSubcontractor.getPriKeyUrl()), hlwSubcontractor.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
                 JSONObject jsonObject1 = jsonObject.getJSONObject("response");
@@ -320,7 +313,7 @@ public class PayRsaCommon {
             //查询条件
             obj_body.put("ntagcinyx1", jsonArrayRequest);
             String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
-                    iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
+                    RsaUtils.getPublicKey(hlwSubcontractor.getPubKeyUrl()), RsaUtils.getPrivateKey(hlwSubcontractor.getPriKeyUrl()), hlwSubcontractor.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
                 JSONObject jsonObject1 = jsonObject.getJSONObject("response");
@@ -378,7 +371,7 @@ public class PayRsaCommon {
             //查询条件
             obj_body.put("ntagdinfy1", jsonArrayRequest);
             String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
-                    iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
+                    RsaUtils.getPublicKey(hlwSubcontractor.getPubKeyUrl()), RsaUtils.getPrivateKey(hlwSubcontractor.getPriKeyUrl()), hlwSubcontractor.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
                 JSONObject jsonObject1 = jsonObject.getJSONObject("response");
@@ -414,16 +407,16 @@ public class PayRsaCommon {
     /**
      * 代发明细对账单查询
      *
-     * @param hlgSubcontractor
+     * @param hlwSubcontractor
      */
-    public static JSONObject DCAGPPDF(HlwPayment hlwPayment, HlwPayRecord hlwPayRecord, HlwSubcontractor hlgSubcontractor) {
+    public static JSONObject DCAGPPDF(HlwPayment hlwPayment, HlwPayRecord hlwPayRecord, HlwSubcontractor hlwSubcontractor) {
         JSONObject jsonObjectBody = new JSONObject();
         try {
             // body
             JSONObject obj_body = new JSONObject();
             //funCode接口名称
             String funCode = PayConst.DCAGPPDF;
-            HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlgSubcontractor);
+            HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlwSubcontractor);
             /**
              * 查询条件
              */
@@ -434,17 +427,17 @@ public class PayRsaCommon {
             //结束日期
             obj_body.put("enddat", DateUtils.GetTime(hlwPayment.getCreateTime(), "yyyy-MM-dd"));
             //业务类型
-            obj_body.put("buscod", hlgSubcontractor.getBuscod());
+            obj_body.put("buscod", hlwSubcontractor.getBuscod());
             //业务模式
-            obj_body.put("busmod", hlgSubcontractor.getBusmod());
+            obj_body.put("busmod", hlwSubcontractor.getBusmod());
             //业务参考号
             obj_body.put("ptyref", hlwPayRecord.getYurref());
             //打印模式 S:逐笔打印:每笔明细生成一个PDF文件 M:批量打印:所有明细生成生成到一个PDF文件里面
             obj_body.put("prtmod", "M");
             //查询标记,首次查询请输入0
             obj_body.put("begidx", "0");
-            String result = PayRequest.doRequest(obj_body, funCode, hlgSubcontractor.getUserId(), hlgSubcontractor.getPaymentUrl(),
-                    iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
+            String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
+                    RsaUtils.getPublicKey(hlwSubcontractor.getPubKeyUrl()), RsaUtils.getPrivateKey(hlwSubcontractor.getPriKeyUrl()), hlwSubcontractor.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
                 JSONObject jsonObject1 = jsonObject.getJSONObject("response");
@@ -471,9 +464,9 @@ public class PayRsaCommon {
     /**
      * 代发明细对账单处理结果查询
      *
-     * @param hlgSubcontractor
+     * @param hlwSubcontractor
      */
-    public static JSONObject DCTASKID(String taskId, HlwSubcontractor hlgSubcontractor) {
+    public static JSONObject DCTASKID(String taskId, HlwSubcontractor hlwSubcontractor) {
         JSONObject jsonObjectBody = new JSONObject();
         try {
             // body
@@ -485,8 +478,8 @@ public class PayRsaCommon {
              */
             //查询ID
             obj_body.put("taskid", taskId);
-            String result = PayRequest.doRequest(obj_body, funCode, hlgSubcontractor.getUserId(), hlgSubcontractor.getPaymentUrl(),
-                    iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
+            String result = PayRequest.doRequest(obj_body, funCode, hlwSubcontractor.getUserId(), hlwSubcontractor.getPaymentUrl(),
+                    RsaUtils.getPublicKey(hlwSubcontractor.getPubKeyUrl()), RsaUtils.getPrivateKey(hlwSubcontractor.getPriKeyUrl()), hlwSubcontractor.getAesKey());
             if (StringUtils.isNotBlank(result)) {
                 JSONObject jsonObject = JSONObject.parseObject(result);
                 JSONObject jsonObject1 = jsonObject.getJSONObject("response");