From 7b0e7c62dab0061d2aa167b46f8a838f363f579a Mon Sep 17 00:00:00 2001
From: 1098226878@qq.com <1098226878@qq.com>
Date: 星期一, 17 一月 2022 17:02:55 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity
---
service-api/src/main/java/com/java110/api/smo/payment/adapt/plutuspay/PlutusOweFeeToNotifyAdapt.java | 68 +++++++++++++++++++---------------
1 files changed, 38 insertions(+), 30 deletions(-)
diff --git a/service-api/src/main/java/com/java110/api/smo/payment/adapt/plutuspay/PlutusOweFeeToNotifyAdapt.java b/service-api/src/main/java/com/java110/api/smo/payment/adapt/plutuspay/PlutusOweFeeToNotifyAdapt.java
index ccf412b..fe70eb4 100644
--- a/service-api/src/main/java/com/java110/api/smo/payment/adapt/plutuspay/PlutusOweFeeToNotifyAdapt.java
+++ b/service-api/src/main/java/com/java110/api/smo/payment/adapt/plutuspay/PlutusOweFeeToNotifyAdapt.java
@@ -15,12 +15,16 @@
*/
package com.java110.api.smo.payment.adapt.plutuspay;
+import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.api.properties.WechatAuthProperties;
import com.java110.api.smo.DefaultAbstractComponentSMO;
import com.java110.api.smo.payment.adapt.IOweFeeToNotifyAdapt;
+import com.java110.core.factory.CommunitySettingFactory;
+import com.java110.core.factory.PlutusFactory;
import com.java110.core.factory.WechatFactory;
+import com.java110.core.log.LoggerFactory;
import com.java110.dto.fee.FeeDto;
import com.java110.dto.smallWeChat.SmallWeChatDto;
import com.java110.utils.cache.CommonCache;
@@ -29,9 +33,8 @@
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.PayUtil;
import com.java110.utils.util.StringUtil;
-import org.apache.commons.codec.digest.DigestUtils;
+import org.bouncycastle.util.encoders.Base64;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@@ -40,7 +43,10 @@
import org.springframework.web.client.RestTemplate;
import java.io.UnsupportedEncodingException;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
/**
* 瀵屽弸 鏀粯 閫氱煡瀹炵幇
@@ -80,30 +86,46 @@
* @throws Exception
*/
public String confirmPayFee(String param, String wId) {
- JSONObject resJson = new JSONObject();
- resJson.put("errCode", "INTERNAL_ERROR");
- resJson.put("errMsg", "澶辫触");
+ JSONObject json = JSON.parseObject(param);
+
+ String signature = json.getString("signature");
+ String content = json.getString("content");
+ String appId = WechatFactory.getAppId(wId);
+ SmallWeChatDto smallWeChatDto = getSmallWechat(appId);
+ if (smallWeChatDto == null) {
+ throw new IllegalArgumentException("鏈厤缃叕浼楀彿鎴栬�呭皬绋嬪簭淇℃伅");
+ }
+ String publicKey = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "PLUTUS_PUBLIC_KEY");
+ //楠岀
+ Boolean verify = PlutusFactory.verify256(content, org.bouncycastle.util.encoders.Base64.decode(signature), publicKey);
+ //楠岀鎴愬姛
+ if (!verify) {
+ throw new IllegalArgumentException("鏀粯澶辫触绛惧悕澶辫触");
+ }
+ //瑙e瘑
+ byte[] bb = PlutusFactory.decrypt(Base64.decode(content), smallWeChatDto.getPayPassword());
+ //鏈嶅姟鍣ㄨ繑鍥炲唴瀹�
+ String paramOut = new String(bb);
try {
- JSONObject map = JSONObject.parseObject(param);
+ JSONObject map = JSONObject.parseObject(paramOut);
logger.info("銆愰摱鑱旀敮浠樺洖璋冦�� 鍥炶皟鏁版嵁锛� \n" + map);
//鏇存柊鏁版嵁
int result = confirmPayFee(map, wId);
if (result > 0) {
//鏀粯鎴愬姛
- resJson.put("errCode", "SUCCESS");
- resJson.put("errMsg", "鎴愬姛");
+ return "SUCCESS";
}
} catch (Exception e) {
logger.error("閫氱煡澶辫触", e);
- resJson.put("result_msg", "閴存潈澶辫触");
+ return "ERROR";
}
-
- return resJson.toJSONString();
+ return "ERROR";
}
public int confirmPayFee(JSONObject map, String wId) {
wId = wId.replace(" ", "+");
+
ResponseEntity<String> responseEntity = null;
String appId = WechatFactory.getAppId(wId);
@@ -116,25 +138,11 @@
smallWeChatDto.setMchId(wechatAuthProperties.getMchId());
smallWeChatDto.setPayPassword(wechatAuthProperties.getKey());
}
- SortedMap<String, String> paramMap = new TreeMap<String, String>();
- for (String key : map.keySet()) {
- if ("wId".equals(key)) {
- continue;
- }
- paramMap.put(key, map.get(key).toString());
- }
- String preSign = map.getString("preSign");
- String text = preSign + smallWeChatDto.getPayPassword();
- System.out.println("寰呯鍚嶅瓧绗︿覆锛�" + text);
- String sign = DigestUtils.sha256Hex(getContentBytes(text)).toUpperCase();
+ //String sign = PayUtil.createChinaUmsSign(paramMap, smallWeChatDto.getPayPassword());
+ //JSONObject billPayment = JSONObject.parseObject(map.getString("billPayment"));
+ String outTradeNo = map.getString("outTransId");
- if (!sign.equals(map.get("sign"))) {
- throw new IllegalArgumentException("閴存潈澶辫触");
- }
-// JSONObject billPayment = JSONObject.parseObject(map.getString("billPayment"));
-// String orderId = billPayment.get("merOrderId").toString().substring(4);
- String outTradeNo = map.get("merOrderId").toString();
- String orderId = outTradeNo.substring(4);
+ String orderId = outTradeNo;
String order = CommonCache.getAndRemoveValue(FeeDto.REDIS_PAY_OWE_FEE + orderId);
if (StringUtil.isEmpty(order)) {
--
Gitblit v1.8.0