xiongzhu 4 лет назад
Родитель
Сommit
e5036b14c0

+ 62 - 20
src/main/java/com/izouma/nineth/service/SandPayService.java

@@ -2,6 +2,7 @@ package com.izouma.nineth.service;
 
 import cn.com.sandpay.cashier.sdk.*;
 import com.alibaba.fastjson.JSONObject;
+import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.config.SandPayProperties;
 import com.izouma.nineth.domain.GiftOrder;
 import com.izouma.nineth.domain.MintOrder;
@@ -43,6 +44,7 @@ public class SandPayService {
     private final SandPayProperties sandPayProperties;
     private final MintOrderRepo     mintOrderRepo;
     private final SnowflakeIdWorker snowflakeIdWorker;
+    private final GeneralProperties generalProperties;
 
     public String getReqTime() {
         return DateTimeUtils.format(LocalDateTime.now(), "yyyyMMddHHmmss");
@@ -121,37 +123,77 @@ public class SandPayService {
     }
 
     public JSONObject requestAlipay(String orderId, BigDecimal amount, String subject, String desc,
-                                    LocalDateTime timeout, String extend) {
+                                    int timeout, String extend) {
         if (orderId.length() < 12) {
             for (int i = orderId.length(); i < 12; i++) {
                 orderId = "0" + orderId;
             }
         }
         JSONObject header = new JSONObject();
-        header.put("version", "1.0");            //版本号
+        header.put("version", "1.0");                      //版本号
         header.put("method", "sandpay.trade.precreate");   //接口名称:统一下单并支付
-        header.put("productId", "00000006");     //产品编码
+        header.put("productId", "00000006");               //产品编码
         header.put("mid", sandPayProperties.getMid());     //商户号
-        header.put("accessType", "1");           //接入类型设置为普通商户接入
-        header.put("channelType", "07");         //渠道类型:07-互联网   08-移动端
-        header.put("reqTime", getReqTime());     //请求时间
+        header.put("accessType", "1");                     //接入类型设置为普通商户接入
+        header.put("channelType", "07");                   //渠道类型:07-互联网   08-移动端
+        header.put("reqTime", getReqTime());               //请求时间
 
         JSONObject body = new JSONObject();
-        body.put("payTool", "0401");             //支付工具: 固定填写0401
-        body.put("orderCode", orderId);          //商户订单号
-        body.put("totalAmount", convertAmount(amount));  //订单金额 12位长度,精确到分
-        //body.put("limitPay", "5");             //限定支付方式 送1-限定不能使用贷记卡	送4-限定不能使用花呗	送5-限定不能使用贷记卡+花呗
-        body.put("subject", subject);            //订单标题
-        body.put("body", desc);                  //订单描述
-        body.put("txnTimeOut", getTimeout(180));    //订单超时时间
-        body.put("notifyUrl", sandPayProperties.getNotifyUrl());//异步通知地址
-        body.put("bizExtendParams", "");         //业务扩展参数
-        body.put("merchExtendParams", "");       //商户扩展参数
-        body.put("extend", extend);              //扩展域
+        body.put("payTool", "0401");                                  //支付工具: 固定填写0401
+        body.put("orderCode", orderId);                               //商户订单号
+        body.put("totalAmount", convertAmount(amount));               //订单金额 12位长度,精确到分
+        //body.put("limitPay", "5");                                  //限定支付方式 送1-限定不能使用贷记卡	送4-限定不能使用花呗	送5-限定不能使用贷记卡+花呗
+        body.put("subject", subject);                                 //订单标题
+        body.put("body", desc);                                       //订单描述
+        body.put("txnTimeOut", getTimeout(180));              //订单超时时间
+        body.put("notifyUrl", sandPayProperties.getNotifyUrl());      //异步通知地址
+        body.put("bizExtendParams", "");                              //业务扩展参数
+        body.put("merchExtendParams", "");                            //商户扩展参数
+        body.put("extend", extend);                                   //扩展域
 
         return requestServer(header, body, "https://cashier.sandpay.com.cn/qr/api/order/create");
     }
 
+    public JSONObject requestUnion(String orderId, BigDecimal amount, String subject, String desc,
+                                   int timeout, String extend, String frontUrl) {
+        if (orderId.length() < 12) {
+            for (int i = orderId.length(); i < 12; i++) {
+                orderId = "0" + orderId;
+            }
+        }
+        JSONObject header = new JSONObject();
+        header.put("version", "1.0");                         //版本号
+        header.put("method", "sandpay.trade.pay");            //接口名称:统一下单
+        header.put("mid", SDKConfig.getConfig().getMid());    //商户号
+        header.put("accessType", "1");                        //接入类型设置为平台商户接入		//接入类型设置为普通商户接入
+        header.put("channelType", "07");                      //渠道类型:07-互联网   08-移动端
+        header.put("reqTime", getReqTime());                  //请求时间
+        header.put("productId", "00000030");                  //产品编码
+
+        JSONObject body = new JSONObject();
+        body.put("orderCode", orderId);                                           //商户订单号
+        body.put("totalAmount", convertAmount(amount));                           //订单金额
+        body.put("subject", subject);                                             //订单标题
+        body.put("body", desc);                                                   //订单描述
+        body.put("txnTimeOut", getTimeout(timeout));                              //订单超时时间
+        body.put("clientIp", "192.168.22.55");                                    //客户端IP
+        body.put("limitPay", "");                                                 //限定支付方式	送1-限定不能使用贷记卡送	4-限定不能使用花呗	送5-限定不能使用贷记卡+花呗
+        body.put("notifyUrl", sandPayProperties.getNotifyUrl());                  //异步通知地址
+        body.put("frontUrl", frontUrl);                                           //前台通知地址
+        body.put("storeId", "");                                                  //商户门店编号
+        body.put("terminalId", "");                                               //商户终端编号
+        body.put("operatorId", "");                                               //操作员编号
+        body.put("clearCycle", "");                                               //清算模式
+        body.put("royaltyInfo", "");                                              //分账信息
+        body.put("riskRateInfo", "");                                             //风控信息域
+        body.put("bizExtendParams", "");                                          //业务扩展参数
+        body.put("merchExtendParams", "");                                        //商户扩展参数
+        body.put("extend", extend);                                               //扩展域
+        body.put("payMode", "sand_upsdk");                                        //支付模式
+
+        return requestServer(header, body, "https://cashier.sandpay.com.cn/gateway/api/order/pay");
+    }
+
     public JSONObject query(String orderId) {
         JSONObject header = new JSONObject();
         header.put("version", "1.0");                     //版本号
@@ -201,7 +243,7 @@ public class SandPayService {
         extend.put("id", orderId);
 
         JSONObject res = requestAlipay(orderId.toString(), order.getTotalPrice(), order.getName(), order.getName(),
-                order.getCreatedAt().plusMinutes(3), extend.toJSONString());
+                180, extend.toJSONString());
         if (res == null)
             throw new BusinessException("下单失败,请稍后再试");
 
@@ -230,7 +272,7 @@ public class SandPayService {
         extend.put("id", orderId);
 
         JSONObject res = requestAlipay(orderId.toString(), order.getGasPrice(), "转增" + order.getAssetId(), "转增" + order.getAssetId(),
-                order.getCreatedAt().plusMinutes(3), extend.toJSONString());
+                180, extend.toJSONString());
         if (res == null)
             throw new BusinessException("下单失败,请稍后再试");
 
@@ -259,7 +301,7 @@ public class SandPayService {
         extend.put("id", orderId);
 
         JSONObject res = requestAlipay(orderId.toString(), order.getGasPrice(), "铸造活动:" + order.getMintActivityId(),
-                "铸造活动:" + order.getMintActivityId(), order.getCreatedAt().plusMinutes(3), extend.toJSONString());
+                "铸造活动:" + order.getMintActivityId(), 180, extend.toJSONString());
         if (res == null)
             throw new BusinessException("下单失败,请稍后再试");
 

+ 11 - 0
src/main/java/com/izouma/nineth/web/SandPayController.java

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.enums.PayMethod;
 import com.izouma.nineth.event.OrderNotifyEvent;
+import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.service.GiftOrderService;
 import com.izouma.nineth.service.MintOrderService;
 import com.izouma.nineth.service.OrderService;
@@ -39,6 +40,16 @@ public class SandPayController {
     private GiftOrderService  giftOrderService;
     private MintOrderService  mintOrderService;
 
+    @GetMapping(value = "/testUnion", produces = "text/html")
+    public String testUnion() {
+        JSONObject res = sandPayService.requestUnion(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
+                "话费充值", "话费充值", 180, "", "https://test.raex.vip/9th/home");
+        if (res.getJSONObject("head").getString("respCode").equals("000000")) {
+            return res.getJSONObject("body").getString("credential");
+        }
+        throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付。");
+    }
+
     @PostMapping("/notify")
     public Object notifyOrder(HttpServletRequest req, HttpServletResponse resp) {
         String data = req.getParameter("data");

+ 1 - 1
src/main/java/com/izouma/nineth/web/SandPayTestController.java

@@ -27,7 +27,7 @@ public class SandPayTestController {
         extend.put("type", "test");
         extend.put("id", 1);
         JSONObject res = sandPayService.requestAlipay(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
-                "话费充值", "话费充值", LocalDateTime.now().plusMinutes(3), extend.toJSONString());
+                "话费充值", "话费充值", 180, extend.toJSONString());
         String qrCode = res.getJSONObject("body").getString("qrCode");
         return "<html><body><a style=\"font-size:28px;\" href=\"" + qrCode + "\">" + qrCode + "</a></body></html>";
     }

+ 1 - 1
src/test/java/com/izouma/nineth/service/SandPayServiceTest.java

@@ -20,7 +20,7 @@ class SandPayServiceTest extends ApplicationTests {
     @Test
     void requestAlipay() {
         JSONObject jsonObject = sandPayService.requestAlipay(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
-                "话费充值", "话费充值", LocalDateTime.now().plusMinutes(2), "");
+                "话费充值", "话费充值", 180, "");
         System.out.println(JSONObject.toJSONString(jsonObject, true));
     }