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

---
 service-job/src/main/java/com/java110/job/adapt/fee/ReturnPayFeeToPlutusAdapt.java |   40 +++++++++++++++++++++++++---------------
 1 files changed, 25 insertions(+), 15 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..b627b13 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,13 @@
 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 com.java110.utils.util.StringUtil;
 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 +115,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 +138,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,31 +151,31 @@
         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);
+        System.out.println(paramOut);
 
         JSONObject paramObj = JSONObject.parseObject(paramOut);
 
-        if (paramObj.getIntValue("status") == 1) {
-            doUpdateOnlinePay(onlinePayDtos.get(0).getOrderId(), OnlinePayDto.STATE_CT, "閫�娆惧畬鎴�");
-        } else {
+        if (paramObj.getIntValue("status") != 2) {
             doUpdateOnlinePay(onlinePayDtos.get(0).getOrderId(), OnlinePayDto.STATE_FT, paramObj.getString("remark"));
+        } else {
+            doUpdateOnlinePay(onlinePayDtos.get(0).getOrderId(), OnlinePayDto.STATE_CT, "閫�娆惧畬鎴�");
         }
 
     }
 
     private void doUpdateOnlinePay(String orderId, String state, String message) {
         OnlinePayPo onlinePayPo = new OnlinePayPo();
-        onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
+        onlinePayPo.setMessage(!StringUtil.isEmpty(message) && message.length() > 1000 ? message.substring(0, 1000) : message);
         onlinePayPo.setOrderId(orderId);
         onlinePayPo.setState(state);
         onlinePayV1InnerServiceSMOImpl.updateOnlinePay(onlinePayPo);

--
Gitblit v1.8.0