فهرست منبع

H5下单封装

skyfffire 1 ماه پیش
والد
کامیت
5cf04b6670

+ 5 - 5
src/main/java/common/utils/wechat/WeChatConfig.java

@@ -6,11 +6,11 @@ import com.wechat.pay.java.core.notification.NotificationConfig;
 import com.wechat.pay.java.service.payments.h5.H5Service;
 
 public class WeChatConfig {
-    static String merchantId = System.getenv("WX_MERCHANT_ID");
-    static String privateKeyPath = System.getenv("WX_PRIVATE_KEY_PATH");
-    static String merchantSerialNumber = System.getenv("WX_MERCHANT_SERIAL_NUMBER");
-    static String apiV3Key = System.getenv("WX_API_V3_KEY");
-    // static String appId = System.getenv("WX_APP_ID");
+    public static String merchantId = System.getenv("WX_MERCHANT_ID");
+    public static String privateKeyPath = System.getenv("WX_PRIVATE_KEY_PATH");
+    public static String merchantSerialNumber = System.getenv("WX_MERCHANT_SERIAL_NUMBER");
+    public static String apiV3Key = System.getenv("WX_API_V3_KEY");
+    public static String appId = System.getenv("WX_APP_ID");
     
     private static Config config;
     private static NotificationConfig nConfig;

+ 23 - 3
src/main/java/common/utils/wechat/WeChatService.java

@@ -3,6 +3,7 @@ package common.utils.wechat;
 import com.wechat.pay.java.core.notification.NotificationConfig;
 import com.wechat.pay.java.core.notification.NotificationParser;
 import com.wechat.pay.java.core.notification.RequestParam;
+import com.wechat.pay.java.service.payments.h5.model.Amount;
 import com.wechat.pay.java.service.payments.h5.model.PrepayRequest;
 import com.wechat.pay.java.service.payments.h5.model.PrepayResponse;
 import com.wechat.pay.java.service.payments.h5.H5Service;
@@ -11,10 +12,29 @@ import com.wechat.pay.java.service.payments.model.Transaction;
 public class WeChatService {
     static H5Service h5Service = WeChatConfig.getService();
 
-    /** H5支付下单 */
-    public static PrepayResponse prepay() {
+    /**
+     * H5支付下单
+     * 
+     * @param amount        订单数量
+     * @param outTradeNo    内部订单号
+     * @param notifyUrl     支付通知url
+     * @return              结果,主要是H5Url
+     */
+    public static PrepayResponse prepay(Integer amount, String outTradeNo, String notifyUrl) {
         PrepayRequest request = new PrepayRequest();
-        // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+        
+        // 交易数量
+        Amount amountM = new Amount();
+        amountM.setTotal(amount);
+        
+        // 参数配置
+        request.setAmount(amountM);
+        request.setAppid(WeChatConfig.appId);
+        request.setMchid(WeChatConfig.merchantId);
+        request.setDescription("购买ID:" + outTradeNo);
+        request.setNotifyUrl(notifyUrl);
+        request.setOutTradeNo(outTradeNo);
+        
         // 调用接口
         return h5Service.prepay(request);
     }

+ 5 - 0
src/main/java/modules/deposit/DepositController.java

@@ -123,4 +123,9 @@ public class DepositController extends MyController {
             renderJson(responseJson);
         }
     }
+    
+    // 创建微信支付订单
+    public void create() {
+        
+    }
 }