From 8db5d3eafb1cc5352b1bdf2c281c54c7fa80db93 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 14 二月 2025 18:07:04 +0800
Subject: [PATCH] 补充
---
UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java | 52 ++++++++++++++++++++++++++++++++++++----------------
1 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java b/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java
index 093b38d..5d768f1 100644
--- a/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java
+++ b/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java
@@ -64,6 +64,9 @@
@Value("${wx.appid}")
private String appid;//微信appid
+ @Value("${wx.appletsAppid}")
+ private String appletsAppid;//微信小程序appid
+
@Value("${wx.mchId}")
private String mchId;//微信商户号
@@ -221,7 +224,7 @@
* @param tradeType 交易类型
* @return
*/
- public ResultUtil weixinpay(String body, String attach, String out_trade_no, String total_fee, String notify_url, String tradeType) throws Exception{
+ public ResultUtil weixinpay(String body, String attach, String out_trade_no, String total_fee, String notify_url, String tradeType, String openId) throws Exception{
int i = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
String hostAddress = null;
try {
@@ -231,7 +234,7 @@
}
String nonce_str = UUIDUtil.getRandomCode(16);
Map<String, Object> map = new HashMap<>();
- map.put("appid", appid);
+ map.put("appid", "APP".equals(tradeType) ? appid : appletsAppid);
map.put("mch_id", mchId);
map.put("nonce_str", nonce_str);
map.put("body", body);
@@ -241,6 +244,9 @@
map.put("spbill_create_ip", hostAddress);
map.put("notify_url", callbackPath + notify_url);
map.put("trade_type", tradeType);
+ if("JSAPI".equals(tradeType)){
+ map.put("openid", openId);
+ }
String s = this.weixinSignature(map);
map.put("sign", s);
@@ -276,26 +282,40 @@
String result_code = map1.get("result_code");
if("SUCCESS".equals(result_code)){
String type = map1.get("trade_type");
+ String prepay_id = map1.get("prepay_id");
switch (type){
case "JSAPI":
- break;
+ //重新进行签名后返回给前端
+ Map<String, Object> map2 = new HashMap<>();
+ map2.put("appId", map1.get("appid"));
+ map2.put("nonceStr", map1.get("nonce_str"));
+ map2.put("package", "prepay_id=" + prepay_id);
+ map2.put("signType", "MD5");
+ map2.put("timeStamp", new Date().getTime() + "");
+ String s2 = this.weixinSignature(map2);
+
+ map2.put("prepay_id", prepay_id);
+ map2.put("mch_id", map1.get("mch_id"));
+ map2.put("trade_type", map1.get("trade_type"));
+
+ map2.put("sign", s2);
+ return ResultUtil.success(map2);
case "NATIVE":
String code_url = map1.get("code_url");
return ResultUtil.success(code_url);
case "APP":
- String prepay_id = map1.get("prepay_id");
//重新进行签名后返回给前端
- Map<String, Object> map2 = new HashMap<>();
- map2.put("appid", appid);
- map2.put("noncestr", nonce_str);
- map2.put("package", "Sign=WXPay");
- map2.put("partnerid", mchId);
- map2.put("prepayid", prepay_id);
- map2.put("timestamp", new Date().getTime() / 1000);
- String s1 = this.weixinSignature(map2);
- map2.put("sign", s1);
- System.err.println(map2);
- return ResultUtil.success(map2);
+ Map<String, Object> map3 = new HashMap<>();
+ map3.put("appid", appid);
+ map3.put("noncestr", nonce_str);
+ map3.put("package", "Sign=WXPay");
+ map3.put("partnerid", mchId);
+ map3.put("prepayid", prepay_id);
+ map3.put("timestamp", new Date().getTime() / 1000);
+ String s1 = this.weixinSignature(map3);
+ map3.put("sign", s1);
+ System.err.println(map3);
+ return ResultUtil.success(map3);
}
return null;
}else{
@@ -328,7 +348,7 @@
if("SUCCESS".equals(result_code)){
Map<String, String> map1 = new HashedMap();
map1.put("nonce_str", map.get("nonce_str"));
- map1.put("out_trade_no", map.get("out_trade_no").split("_")[1]);//存储的订单code
+ map1.put("out_trade_no", map.get("out_trade_no"));//存储的订单code
map1.put("attach", map.get("attach"));//存储订单id
map1.put("total_fee", map.get("total_fee"));
map1.put("transaction_id", map.get("transaction_id"));//微信支付订单号
--
Gitblit v1.7.1