From c453f5a9c2c6e78d7b886a16a0bc3fe6ca8ef3e5 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期一, 17 一月 2022 17:25:40 +0800
Subject: [PATCH] 优化代码

---
 service-job/src/main/java/com/java110/job/adapt/fee/ReturnPayFeeToPlutusAdapt.java |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/service-job/src/main/java/com/java110/job/adapt/fee/ReturnPayFeeToPlutusAdapt.java b/service-job/src/main/java/com/java110/job/adapt/fee/ReturnPayFeeToPlutusAdapt.java
index 6bf8ffe..aee7fca 100644
--- a/service-job/src/main/java/com/java110/job/adapt/fee/ReturnPayFeeToPlutusAdapt.java
+++ b/service-job/src/main/java/com/java110/job/adapt/fee/ReturnPayFeeToPlutusAdapt.java
@@ -6,6 +6,7 @@
 import com.java110.core.client.OssUploadTemplate;
 import com.java110.core.factory.CommunitySettingFactory;
 import com.java110.core.factory.PlutusFactory;
+import com.java110.core.log.LoggerFactory;
 import com.java110.dto.onlinePay.OnlinePayDto;
 import com.java110.dto.smallWeChat.SmallWeChatDto;
 import com.java110.entity.order.Business;
@@ -15,11 +16,12 @@
 import com.java110.intf.store.ISmallWeChatInnerServiceSMO;
 import com.java110.job.adapt.DatabusAdaptImpl;
 import com.java110.po.onlinePay.OnlinePayPo;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.WechatConstant;
 import com.java110.utils.util.BeanConvertUtil;
 import com.java110.utils.util.PayUtil;
 import org.bouncycastle.util.encoders.Base64;
 import org.slf4j.Logger;
-import com.java110.core.log.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
@@ -112,8 +114,20 @@
         smallWeChatDto.setMchId(onlinePayDtos.get(0).getMchId());
         smallWeChatDto.setAppId(onlinePayDtos.get(0).getAppId());
         List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
+        String privateKey = "";
+        String devId = "";
+        String payPassword = "";
+        String publicKey = "";
         if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
-            throw new IllegalArgumentException("鏈厤缃叕浼楀彿鎴栬�呭皬绋嬪簭淇℃伅");
+            privateKey = MappingCache.getRemark(WechatConstant.WECHAT_DOMAIN, "PLUTUS_PRIVATE_KEY");
+            devId = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "PLUTUS_DEV_ID");
+            payPassword = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "key");
+            publicKey = MappingCache.getRemark(WechatConstant.WECHAT_DOMAIN, "PLUTUS_PUBLIC_KEY");
+        } else {
+            privateKey = CommunitySettingFactory.getRemark(smallWeChatDtos.get(0).getObjId(), "PLUTUS_PRIVATE_KEY");
+            devId = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "PLUTUS_DEV_ID");
+            payPassword = smallWeChatDtos.get(0).getPayPassword();
+            publicKey = CommunitySettingFactory.getRemark(smallWeChatDtos.get(0).getObjId(), "PLUTUS_PUBLIC_KEY");
         }
 
 
@@ -123,13 +137,8 @@
         parameters.put("outRefundId", onlinePayDtos.get(0).getPayId());//鎴戜滑鑷繁璁惧畾鐨勯��娆剧敵璇峰彿锛岀害鏉熶负UK
         parameters.put("refundAmount", PayUtil.moneyToIntegerStr(Double.parseDouble(onlinePayDtos.get(0).getTotalFee())));//璁㈠崟閲戦 鍗曚綅涓哄垎锛侊紒锛佽繖閲岀◢寰敞鎰忎竴涓�
 
-        if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
-            throw new IllegalArgumentException("鏈厤缃叕浼楀彿鎴栬�呭皬绋嬪簭淇℃伅");
-        }
-        String privateKey = CommunitySettingFactory.getRemark(smallWeChatDtos.get(0).getObjId(), "PLUTUS_PRIVATE_KEY");
-        String devId = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "PLUTUS_DEV_ID");
 
-        String param = PlutusFactory.Encryption(parameters.toJSONString(),privateKey,smallWeChatDtos.get(0).getPayPassword(),devId);
+        String param = PlutusFactory.Encryption(parameters.toJSONString(), privateKey, payPassword, devId);
         System.out.println(param);
 
         String str = PlutusFactory.post(wechatReturnUrl, param);
@@ -141,15 +150,14 @@
         String content = json.getString("content");
 
 
-        String publicKey = CommunitySettingFactory.getRemark(smallWeChatDtos.get(0).getObjId(), "PLUTUS_PUBLIC_KEY");
         //楠岀
-        Boolean verify = PlutusFactory.verify256(content, org.bouncycastle.util.encoders.Base64.decode(signature), publicKey);
+        Boolean verify = PlutusFactory.verify256(content, Base64.decode(signature), publicKey);
         //楠岀鎴愬姛
         if (!verify) {
             throw new IllegalArgumentException("鏀粯澶辫触绛惧悕澶辫触");
         }
         //瑙e瘑
-        byte[] bb = PlutusFactory.decrypt(Base64.decode(content), smallWeChatDtos.get(0).getPayPassword());
+        byte[] bb = PlutusFactory.decrypt(Base64.decode(content), payPassword);
         //鏈嶅姟鍣ㄨ繑鍥炲唴瀹�
         String paramOut = new String(bb);
 

--
Gitblit v1.8.0