From 4f8b61980b0db5995c16139d8eb9542b66da8a9f Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期二, 27 六月 2023 11:58:21 +0800
Subject: [PATCH] 修改bug
---
driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/PayMoneyUtil.java | 128 ++++++++++++++++++++++++++++++++----------
1 files changed, 97 insertions(+), 31 deletions(-)
diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/PayMoneyUtil.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/PayMoneyUtil.java
index cd83b5a..cc801eb 100644
--- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/PayMoneyUtil.java
+++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/PayMoneyUtil.java
@@ -15,13 +15,20 @@
import com.alipay.api.response.AlipayTradePrecreateResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
+import com.supersavedriving.driver.modular.system.util.httpClinet.HttpClientUtil;
+import com.wechat.pay.java.core.RSAConfig;
+import com.wechat.pay.java.core.cipher.PrivacyEncryptor;
+import com.wechat.pay.java.core.cipher.RSAPrivacyEncryptor;
+import com.wechat.pay.java.service.transferbatch.TransferBatchService;
+import com.wechat.pay.java.service.transferbatch.model.InitiateBatchTransferRequest;
+import com.wechat.pay.java.service.transferbatch.model.InitiateBatchTransferResponse;
+import com.wechat.pay.java.service.transferbatch.model.TransferDetailInput;
import org.apache.commons.collections.map.HashedMap;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -37,10 +44,7 @@
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Security;
+import java.security.*;
import java.util.*;
/**
@@ -73,10 +77,11 @@
@Value("${callbackPath}")
private String callbackPath;//支付回调网关地址
- @Autowired
- private HttpClientUtil httpClientUtil;
+ private String wechatPayCertificatesFromPath = "/usr/local/server/app/cert/weixin/apiclient_cert.p12";//微信支付证书地址
- private Map<String, JSONObject> order = new HashMap<>();//存储支付订单用于主动查询支付结果
+ private String privateKeyFromPath = "/usr/local/server/app/cert/weixin/apiclient_cert.pem";//微信私钥证书地址
+
+
/**
@@ -260,7 +265,7 @@
xmlString.append("</xml>");
Map<String, String> map1 = null;
- String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>());
+ String body1 = HttpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
//将结果xml解析成map
body1 = body1.replaceAll("<!\\[CDATA\\[","");
body1 = body1.replaceAll("]]>", "");
@@ -404,7 +409,12 @@
xmlString.append("</xml>");
Map<String, String> map1 = null;
- String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>());
+ String body1 = null;
+ try {
+ body1 = HttpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
//将结果xml解析成map
body1 = body1.replaceAll("<!\\[CDATA\\[","");
body1 = body1.replaceAll("]]>", "");
@@ -506,7 +516,12 @@
xmlString.append("</xml>");
Map<String, String> map1 = null;
- String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>());
+ String body1 = null;
+ try {
+ body1 = HttpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
//将结果xml解析成map
body1 = body1.replaceAll("<!\\[CDATA\\[","");
body1 = body1.replaceAll("]]>", "");
@@ -621,13 +636,14 @@
* @return
* @throws Exception
*/
- public ResultUtil queryWXOrder() throws Exception{
+ public ResultUtil<Map<String, String>> queryWXOrder(String out_trade_no, String transaction_id) throws Exception{
String url = "https://api.mch.weixin.qq.com/pay/orderquery";
String nonce_str = UUIDUtil.getRandomCode(16);
Map<String, Object> map = new HashMap<>();
map.put("appid", appid);
map.put("mch_id", mchId);
- map.put("transaction_id", nonce_str);//微信订单号
+ map.put("out_trade_no", out_trade_no);//商户订单号
+ map.put("transaction_id", transaction_id);//微信订单号
map.put("nonce_str", nonce_str);//随机字符串
String s = this.weixinSignature(map);
map.put("sign", s);
@@ -647,7 +663,7 @@
xmlString.append("</xml>");
Map<String, String> map1 = null;
- String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>());
+ String body1 = HttpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
//将结果xml解析成map
body1 = body1.replaceAll("<!\\[CDATA\\[","");
body1 = body1.replaceAll("]]>", "");
@@ -662,31 +678,71 @@
if("SUCCESS".equals(return_code)){
String result_code = map1.get("result_code");
if("SUCCESS".equals(result_code)){
- String type = map1.get("trade_type");
- switch (type){
- case "JSAPI":
- break;
- case "NATIVE":
- String code_url = map1.get("code_url");
- return ResultUtil.success(code_url);
- case "APP":
- String trade_state = map1.get("trade_state");
- String time_end = map1.get("time_end");
- Map<String, Object> map2 = new HashMap<>();
- map2.put("trade_state", trade_state);//订单状态SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败)
- map2.put("time_end", time_end);//订单支付时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。
- return ResultUtil.success(map2);
- }
- return null;
+ Map<String, String> map2 = new HashMap<>();
+ map2.put("trade_type", map1.get("trade_type"));
+ map2.put("trade_state", map1.get("trade_state"));//订单状态SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败)
+ map2.put("transaction_id", map1.get("transaction_id"));
+ return ResultUtil.success(map2);
}else{
System.err.println(map1.get("err_code_des"));
return ResultUtil.error(map1.get("err_code_des"));
}
}else{
System.err.println(map1.get("return_msg") + appid + "----" + mchId);
- return ResultUtil.error(map1.get("return_msg"), new JSONObject());
+ return ResultUtil.error(map1.get("return_msg"));
}
}
+
+
+ /**
+ * 微信商户转账零钱
+ * @param outDetailNo 商家流水号
+ * @param amount 转账金额
+ * @param openid 收款openid
+ * @param userName 收款用户姓名
+ * @param remark 备注
+ * @return
+ */
+ public String weixinTransferMoney(String outDetailNo, Double amount, String openid, String userName, String remark){
+ RSAConfig config =
+ new RSAConfig.Builder()
+ .merchantId(mchId)
+ .privateKeyFromPath(privateKeyFromPath)
+ .merchantSerialNumber("7630124B15BA87F2CF0F35883988DE34D62089DA")
+ .wechatPayCertificatesFromPath(wechatPayCertificatesFromPath)
+ .build();
+ TransferBatchService service = new TransferBatchService.Builder().config(config).build();
+ InitiateBatchTransferRequest initiateBatchTransferRequest =
+ new InitiateBatchTransferRequest();
+ initiateBatchTransferRequest.setAppid(appid);
+ initiateBatchTransferRequest.setOutBatchNo(outDetailNo);
+ initiateBatchTransferRequest.setBatchName("付款");
+ initiateBatchTransferRequest.setBatchRemark(remark);
+ initiateBatchTransferRequest.setTotalAmount(amount.longValue() * 100);
+ initiateBatchTransferRequest.setTotalNum(1);
+ {
+ List<TransferDetailInput> transferDetailListList = new ArrayList<>();
+ {
+ TransferDetailInput transferDetailInput = new TransferDetailInput();
+ transferDetailInput.setOutDetailNo(outDetailNo);
+ transferDetailInput.setTransferAmount(amount.longValue() * 100);
+ transferDetailInput.setTransferRemark(remark);
+ transferDetailInput.setOpenid(openid);
+ if(amount > 0.3){
+ transferDetailInput.setUserName(userName);
+ }
+ transferDetailListList.add(transferDetailInput);
+ }
+ initiateBatchTransferRequest.setTransferDetailList(
+ transferDetailListList);
+ }
+ initiateBatchTransferRequest.setTransferSceneId("1000");
+ InitiateBatchTransferResponse response =
+ service.initiateBatchTransfer(initiateBatchTransferRequest);
+ return response.getBatchId();
+ }
+
+
@@ -747,6 +803,16 @@
return null;
}
+ public String RSAPrivacyEncryptor(){
+ // 微信支付平台证书中的公钥
+ PublicKey wechatPayPublicKey = null;
+ String plaintext = "";
+ PrivacyEncryptor encryptor = new RSAPrivacyEncryptor(wechatPayPublicKey, "");
+ String ciphertext = encryptor.encrypt(plaintext);
+ return ciphertext;
+ }
+
+
/**
* 微信退款成功后的解密
--
Gitblit v1.7.1