From 4b47d63f3a39c845eebd44a8e2be7d48173f073f Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 23 五月 2023 18:37:23 +0800
Subject: [PATCH] 欧普特眯着

---
 service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgPaymentFactoryAdapt.java |  101 +++++++++-----------------------------------------
 1 files changed, 18 insertions(+), 83 deletions(-)

diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgPaymentFactoryAdapt.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgPaymentFactoryAdapt.java
index 6e3a9f8..b49712e 100644
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgPaymentFactoryAdapt.java
+++ b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgPaymentFactoryAdapt.java
@@ -195,11 +195,10 @@
     private Map<String, String> java110UnifieldOrder(String feeName, String orderNum,
                                                      String tradeType, double payAmount, String openid,
                                                      SmallWeChatDto smallWeChatDto, String notifyUrl) throws Exception {
-        String mchtNo_RSA2 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "mchtNo_RSA2");
-        String productNo_RSA2 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "productNo_RSA2");
-        String opToken_RSA2 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "opToken_RSA2");
-        String mcht_PrivateKey_RSA2 = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "mcht_PrivateKey_RSA2");
-        String bank_PublicKey_RSA2 = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "bank_PublicKey_RSA2");
+
+        String mchtNo_SM4 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "mchtNo_SM4");
+        String productNo_SM4 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "productNo_SM4");
+        String publicKey_SM4 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "publicKey_SM4");
 
         if (feeName.length() > 127) {
             feeName = feeName.substring(0, 126);
@@ -207,8 +206,8 @@
 
         Map<String, Object> params = new HashMap<>();
         params.put("version", VERSION);// 鐗堟湰鍙� 1.0
-        params.put("mcht_no", mchtNo_RSA2);// 鏀舵鍟嗘埛缂栧彿
-        params.put("product_no", productNo_RSA2);// 浜у搧缂栧彿
+        params.put("mcht_no", mchtNo_SM4);// 鏀舵鍟嗘埛缂栧彿
+        params.put("product_no", productNo_SM4);// 浜у搧缂栧彿
         params.put("biz_type", "WX_GZH");// 涓氬姟绫诲瀷
         params.put("tran_no", String.valueOf(System.nanoTime()));// 鍟嗘埛娴佹按
         params.put("code", "");// 鎺堟潈鐮�
@@ -218,58 +217,7 @@
         params.put("ware_name", feeName);// 鍟嗗搧鍚嶇О
         params.put("ware_describe", "");// 鍟嗘埛鏁版嵁鍖�
         params.put("asyn_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));// 閫氱煡鍦板潃
-        String json = JsonUtil.mapToJson(params);
-        System.out.println("鍔犲瘑鍓嶏細" + json);
-
-        Map<String, Object> soreMap = JsonUtil.sortMapByKey(params);
-
-        // 寮�濮嬪姞瀵�
-        byte[] en = AesEncrypt.encryptByte(json, "utf-8", opToken_RSA2);
-        if (en == null || en.length <= 0) {
-            System.err.println("鍔犲瘑澶辫触");
-            throw new IllegalArgumentException("鍔犲瘑澶辫触");
-        }
-        String encryptBase64Str = AesEncrypt.parseByte2HexStr(en);
-        System.out.println("鍔犲瘑鍚庯細" + encryptBase64Str);
-
-        String signtBase64Str = CAUtil.rsa256Sign(json, "utf-8", mcht_PrivateKey_RSA2);
-        System.out.println("鍔犵涓诧細" + signtBase64Str);
-
-        Map<String, Object> signParams = new HashMap<>();
-        signParams.put("mcht_no", mchtNo_RSA2);// 鏀舵鍟嗘埛缂栧彿
-        signParams.put("sign_type", SIGN_TYPE);
-        signParams.put("sign", signtBase64Str);
-        signParams.put("enc_data", encryptBase64Str);// 鍔犲瘑鍚庤姹傚弬鏁�
-
-        String requestParams = JsonUtil.mapToJson(signParams);
-        System.out.println("鏈�缁堣姹傚弬鏁帮細" + requestParams);
-        System.err.println("");
-        String returnResult = HttpRequestUtil.httpPost(gzhPayUrl, requestParams);
-        System.out.println("鏀粯缁撴灉杩斿洖鍊�(鍘熸枃):" + returnResult);
-        if (returnResult == null) {
-            System.err.println("閫氶亾鍝嶅簲寮傚父");
-            throw new IllegalArgumentException("閫氶亾鍝嶅簲寮傚父");
-        }
-        // 寮�濮嬭В瀵�
-        Map<String, Object> responseParams = JsonUtil.jsonToMap(returnResult);
-        // 寮�濮嬭В瀵�
-        String decryptBase64Str = (String) responseParams.get("enc_data");
-        String verifyBase64Str = (String) responseParams.get("sign");
-        byte[] bt = AesEncrypt.parseHexStr2Byte(decryptBase64Str);
-        byte[] decrypt = AesEncrypt.decryptByte(bt, opToken_RSA2);
-        if (decrypt == null) {
-            System.err.println("瑙e瘑澶辫触");
-            throw new IllegalArgumentException("瑙e瘑澶辫触");
-        }
-        boolean isSuccess = CAUtil.rsa256Verify(decrypt, verifyBase64Str, bank_PublicKey_RSA2);
-        System.out.println("鏁版嵁楠岀锛�" + isSuccess);
-        if (!isSuccess) {
-            System.err.println("楠岀澶辫触");
-            throw new IllegalArgumentException("楠岀澶辫触");
-        }
-        String decryParams = new String(decrypt);
-        System.out.println("鏀粯缁撴灉杩斿洖鍊�(瑙e瘑鍚�):" + decryParams);
-
+        String decryParams = EncryptDecryptFactory.execute(smallWeChatDto.getObjId(), gzhPayUrl, params);
         JSONObject paramOut = JSONObject.parseObject(decryParams);
         if (!"0000".equals(paramOut.getString("return_code"))
                 || !"SUCCESS".equals(paramOut.getString("status"))
@@ -294,39 +242,26 @@
     @Override
     public PaymentOrderDto java110NotifyPayment(NotifyPaymentOrderDto notifyPaymentOrderDto) {
 
-        String opToken_RSA2 = CommunitySettingFactory.getValue(notifyPaymentOrderDto.getCommunityId(), "opToken_RSA2");
-        String bank_PublicKey_RSA2 = CommunitySettingFactory.getRemark(notifyPaymentOrderDto.getCommunityId(), "bank_PublicKey_RSA2");
+        String privateKey_SM4 = CommunitySettingFactory.getValue(notifyPaymentOrderDto.getCommunityId(), "privateKey_SM4");
 
         String resXml = "";
         String param = notifyPaymentOrderDto.getParam();
         PaymentOrderDto paymentOrderDto = new PaymentOrderDto();
-        Map<String, Object> responseParams = JsonUtil.jsonToMap(param);
         // 寮�濮嬭В瀵�
-        String decryptBase64Str = (String) responseParams.get("enc_data");
-        String verifyBase64Str = (String) responseParams.get("sign");
-        byte[] bt = AesEncrypt.parseHexStr2Byte(decryptBase64Str);
-        byte[] decrypt = new byte[0];
-        try {
-            decrypt = AesEncrypt.decryptByte(bt, opToken_RSA2);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+        Map<String, Object> responseParams = JsonUtil.jsonToMap(param);
+        if (!responseParams.containsKey("enc_data")) {
+            System.err.println("閫氱煡澶辫触");
+            throw new IllegalArgumentException("閫氱煡澶辫触");
         }
-        if (decrypt == null) {
+        String decryptStr = (String) responseParams.get("enc_data");
+        String messageKey = (String) responseParams.get("message_key");
+        String secretKey = GmUtil.decryptSm2(messageKey, privateKey_SM4);
+        if (secretKey == null) {
             System.err.println("瑙e瘑澶辫触");
             throw new IllegalArgumentException("瑙e瘑澶辫触");
         }
-        boolean isSuccess = false;
-        try {
-            isSuccess = CAUtil.rsa256Verify(decrypt, verifyBase64Str, bank_PublicKey_RSA2);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-        System.out.println("鏁版嵁楠岀锛�" + isSuccess);
-        if (!isSuccess) {
-            System.err.println("楠岀澶辫触");
-            throw new IllegalArgumentException("楠岀澶辫触");
-        }
-        String decryParams = new String(decrypt);
+        String decryParams = GmUtil.decryptSm4(decryptStr, secretKey);
+
         System.out.println("鏀粯缁撴灉杩斿洖鍊�(瑙e瘑鍚�):" + decryParams);
 
         JSONObject paramOut = JSONObject.parseObject(decryParams);

--
Gitblit v1.8.0