From a50197bd1a429d903718e40b54685bb2a241bd4a Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期二, 14 一月 2025 19:37:20 +0800
Subject: [PATCH] 修改

---
 UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java |   50 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 35 insertions(+), 15 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..1c69d88 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{

--
Gitblit v1.7.1