소스 검색

首信易

xiongzhu 3 년 전
부모
커밋
d1bd799e26

+ 40 - 2
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 
@@ -107,7 +108,7 @@ public class OrderPayService {
     }
 
     @Cacheable(value = "payOrder", key = "'order#'+#orderId")
-    public Object payOrderAgreement(Long orderId, String bindCardId) {
+    public Map<String, Object> payOrderAgreement(Long orderId, String bindCardId) {
         Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
         if (order.getStatus() != OrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");
@@ -119,10 +120,13 @@ public class OrderPayService {
         if (StringUtils.isEmpty(bindCardId)) {
             throw new BusinessException("请先绑定银行卡");
         }
-       return payEaseService.pay(order.getName(), orderId.toString(), order.getTotalPrice(),
+        return payEaseService.pay(order.getName(), orderId.toString(), order.getTotalPrice(),
                 order.getUserId().toString(), bindCardId);
     }
 
+    public void confirmOrderAgreement(String requestId, String paymentOrderId, String code) {
+        payEaseService.payConfirm(requestId, paymentOrderId, code);
+    }
 
     @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
     public String payGiftOrder(Long orderId) {
@@ -160,6 +164,23 @@ public class OrderPayService {
         giftOrderService.giftNotify(orderId, PayMethod.BALANCE, record.getId().toString());
     }
 
+    @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
+    public Map<String, Object> payGiftOrderAgreement(Long orderId, String bindCardId) {
+        GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != OrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+        if (StringUtils.isEmpty(bindCardId)) {
+            bindCardId = userBankCardRepo.findByUserId(order.getUserId())
+                    .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
+        }
+        if (StringUtils.isEmpty(bindCardId)) {
+            throw new BusinessException("请先绑定银行卡");
+        }
+        return payEaseService.pay("转赠" + order.getAssetId(), orderId.toString(), order.getGasPrice(),
+                order.getUserId().toString(), bindCardId);
+    }
+
     @Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
     public String payMintOrder(Long orderId) {
         MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
@@ -196,6 +217,23 @@ public class OrderPayService {
         giftOrderService.giftNotify(orderId, PayMethod.BALANCE, record.getId().toString());
     }
 
+    @Cacheable(value = "payOrder", key = "'mint#'+#orderId")
+    public Map<String, Object> payMintOrderAgreement(Long orderId, String bindCardId) {
+        MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != MintOrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+        if (StringUtils.isEmpty(bindCardId)) {
+            bindCardId = userBankCardRepo.findByUserId(order.getUserId())
+                    .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
+        }
+        if (StringUtils.isEmpty(bindCardId)) {
+            throw new BusinessException("请先绑定银行卡");
+        }
+        return payEaseService.pay("铸造活动:" + order.getMintActivityId(), orderId.toString(), order.getGasPrice(),
+                order.getUserId().toString(), bindCardId);
+    }
+
     public String recharge(Long userId, BigDecimal amount) {
         BigDecimal minAmount = sysConfigService.getBigDecimal("min_recharge_amount");
         if (amount.compareTo(minAmount) < 0) {

+ 3 - 0
src/main/java/com/izouma/nineth/service/PayEaseService.java

@@ -3,6 +3,7 @@ package com.izouma.nineth.service;
 import com.alibaba.fastjson15.JSON;
 import com.alibaba.fastjson15.JSONObject;
 import com.alibaba.fastjson15.parser.Feature;
+import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.config.RedisKeys;
 import com.izouma.nineth.dto.BindCardRequest;
 import com.izouma.nineth.exception.BusinessException;
@@ -40,6 +41,7 @@ public class PayEaseService {
     public static final String merchantId = "896593123";
 
     private RedisTemplate<String, Object> redisTemplate;
+    private GeneralProperties             generalProperties;
 
     public JSONObject request(String url, JSONObject requestData) {
         log.info("requestData: {}", JSON.toJSONString(requestData, true));
@@ -114,6 +116,7 @@ public class PayEaseService {
         JSONObject response = request(ConfigurationUtils.getCashierBindCardKaptchaUrl(), builder.bothEncryptBuild());
         if (!"SUCCESS".equals(response.getString("status"))) {
             String error = response.getString("error");
+            String cause = response.getString("cause");
             throw new BusinessException(error);
         }
     }

+ 22 - 0
src/main/java/com/izouma/nineth/web/OrderPayControllerV2.java

@@ -24,6 +24,7 @@ import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
+import java.util.Map;
 import java.util.regex.Pattern;
 
 @Controller
@@ -66,6 +67,21 @@ public class OrderPayControllerV2 {
         return sandPayService.payOrderQuick(id);
     }
 
+    @ApiOperation("首信易协议支付")
+    @RequestMapping(value = "/agreement", produces = "text/html")
+    @ResponseBody
+    public Map<String, Object> agreement(@RequestParam Long id, String bindCardId) {
+        return orderPayService.payOrderAgreement(id, bindCardId);
+    }
+
+    @ApiOperation("首信易协议支付确认(通用)")
+    @RequestMapping(value = "/confirmAgreement", produces = "text/html")
+    @ResponseBody
+    public void confirmAgreement(@RequestParam String requestId, @RequestParam String paymentOrderId,
+                                 @RequestParam String code) {
+        orderPayService.confirmOrderAgreement(requestId, paymentOrderId, code);
+    }
+
     @RequestMapping(value = "/gift/alipay")
     @ResponseBody
     public String payGiftOrderAlipayH5(Long id) {
@@ -91,6 +107,12 @@ public class OrderPayControllerV2 {
         return sandPayService.payGiftQuick(id);
     }
 
+    @RequestMapping(value = "/gift/agreement", produces = "text/html")
+    @ResponseBody
+    public Map<String, Object> payGiftAgreement(@RequestParam Long id, String bindCardId) {
+        return orderPayService.payGiftOrderAgreement(id, bindCardId);
+    }
+
     @RequestMapping(value = "/mint/alipay")
     @ResponseBody
     public String payMintOrderAlipayH5(Long id) {

+ 3 - 3
src/test/java/com/izouma/nineth/PayEaseTest.java

@@ -38,9 +38,9 @@ public class PayEaseTest {
         //商户会员id
         String merchantUserId = "9850";
         //	银⾏卡号
-        String bankCardNumber = "6228270397009469879";
+        String bankCardNumber = "6217001370031997059";
         //预留⼿机号
-        String phoneNumber = "15077886171";
+        String phoneNumber = "13365135976";
         //	持卡⼈姓名
         String name = "潘惠";
         //	身份证号
@@ -84,7 +84,7 @@ public class PayEaseTest {
 
     @Test
     public void bindCardCaptcha() {
-        String bindCardId = "20220519038583712044350867390464";
+        String bindCardId = "20220519435026712047423086018560";
 
         BindCardKaptchaBuilder builder = new BindCardKaptchaBuilder(merchantId);
         builder.setBindCardId(bindCardId);