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

+ 11 - 0
src/main/java/com/izouma/nineth/config/PayEaseProperties.java

@@ -0,0 +1,11 @@
+package com.izouma.nineth.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@Data
+@ConfigurationProperties(prefix = "payease")
+public class PayEaseProperties {
+    private String merchantId;
+    private String notifyUrl;
+}

+ 29 - 3
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -121,7 +121,7 @@ public class OrderPayService {
             throw new BusinessException("请先绑定银行卡");
         }
         return payEaseService.pay(order.getName(), orderId.toString(), order.getTotalPrice(),
-                order.getUserId().toString(), bindCardId);
+                order.getUserId().toString(), bindCardId, "order");
     }
 
     public void confirmOrderAgreement(String requestId, String paymentOrderId, String code) {
@@ -178,7 +178,7 @@ public class OrderPayService {
             throw new BusinessException("请先绑定银行卡");
         }
         return payEaseService.pay("转赠" + order.getAssetId(), orderId.toString(), order.getGasPrice(),
-                order.getUserId().toString(), bindCardId);
+                order.getUserId().toString(), bindCardId, "gift");
     }
 
     @Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
@@ -231,7 +231,7 @@ public class OrderPayService {
             throw new BusinessException("请先绑定银行卡");
         }
         return payEaseService.pay("铸造活动:" + order.getMintActivityId(), orderId.toString(), order.getGasPrice(),
-                order.getUserId().toString(), bindCardId);
+                order.getUserId().toString(), bindCardId, "mintOrder");
     }
 
     public String recharge(Long userId, BigDecimal amount) {
@@ -264,6 +264,32 @@ public class OrderPayService {
         throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
     }
 
+    public Map<String, Object> rechargeAgreement(Long userId, BigDecimal amount, String bindCardId) {
+        BigDecimal minAmount = sysConfigService.getBigDecimal("min_recharge_amount");
+        if (amount.compareTo(minAmount) < 0) {
+            throw new BusinessException("充值金额不能小于" + minAmount);
+        }
+        if (amount.compareTo(new BigDecimal("50000")) > 0) {
+            throw new BusinessException("充值金额不能大于50000");
+        }
+        RechargeOrder order = RechargeOrder.builder()
+                .id(snowflakeIdWorker.nextId())
+                .userId(userId)
+                .amount(amount)
+                .status(OrderStatus.NOT_PAID)
+                .build();
+        rechargeOrderRepo.save(order);
+        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.getId().toString(), order.getAmount(),
+                order.getUserId().toString(), bindCardId, "recharge");
+    }
+
     public JSONObject refund(String orderId, BigDecimal amount, String channel) {
         switch (channel) {
             case "sandPay": {

+ 14 - 11
src/main/java/com/izouma/nineth/service/PayEaseService.java

@@ -4,6 +4,8 @@ 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.HmPayProperties;
+import com.izouma.nineth.config.PayEaseProperties;
 import com.izouma.nineth.config.RedisKeys;
 import com.izouma.nineth.dto.BindCardRequest;
 import com.izouma.nineth.exception.BusinessException;
@@ -23,6 +25,7 @@ import com.upay.sdk.onlinepay.builder.OrderBuilder;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
@@ -36,12 +39,11 @@ import java.util.Objects;
 @Service
 @Slf4j
 @AllArgsConstructor
+@EnableConfigurationProperties({PayEaseProperties.class})
 public class PayEaseService {
 
-    public static final String merchantId = "896593123";
-
+    private PayEaseProperties             payEaseProperties;
     private RedisTemplate<String, Object> redisTemplate;
-    private GeneralProperties             generalProperties;
 
     public JSONObject request(String url, JSONObject requestData) {
         log.info("requestData: {}", JSON.toJSONString(requestData, true));
@@ -54,7 +56,7 @@ public class PayEaseService {
     }
 
     public String bindCard(BindCardRequest bindCardRequest) {
-        BindCardBuilder builder = new BindCardBuilder(merchantId);
+        BindCardBuilder builder = new BindCardBuilder(payEaseProperties.getMerchantId());
         builder.setMerchantUserId(bindCardRequest.getUserId())
                 .setBankCardNumber(bindCardRequest.getBankNo())
                 .setPhoneNumber(bindCardRequest.getPhone())
@@ -88,7 +90,7 @@ public class PayEaseService {
         BindCardRequest bindCardRequest = (BindCardRequest) obj;
 
 
-        BindCardConfirmBuilder builder = new BindCardConfirmBuilder(merchantId);
+        BindCardConfirmBuilder builder = new BindCardConfirmBuilder(payEaseProperties.getMerchantId());
         builder.setBindCardId(bindCardId)
                 .setMerchantUserId(bindCardRequest.getUserId())
                 .setKaptchaCode(code);
@@ -111,7 +113,7 @@ public class PayEaseService {
     }
 
     public void bindCardCaptcha(String bindCardId) {
-        BindCardKaptchaBuilder builder = new BindCardKaptchaBuilder(merchantId);
+        BindCardKaptchaBuilder builder = new BindCardKaptchaBuilder(payEaseProperties.getMerchantId());
         builder.setBindCardId(bindCardId);
         JSONObject response = request(ConfigurationUtils.getCashierBindCardKaptchaUrl(), builder.bothEncryptBuild());
         if (!"SUCCESS".equals(response.getString("status"))) {
@@ -123,7 +125,7 @@ public class PayEaseService {
 
     public void unbind(String userId, String bindCardId) {
 
-        UnBindCardBuilder builder = new UnBindCardBuilder(merchantId);
+        UnBindCardBuilder builder = new UnBindCardBuilder(payEaseProperties.getMerchantId());
         builder.setBindCardId(bindCardId)
                 .setMerchantUserId(userId);
         JSONObject response = request(ConfigurationUtils.getCashierUnBindCardUrl(), builder.bothEncryptBuild());
@@ -139,11 +141,12 @@ public class PayEaseService {
     }
 
 
-    public Map<String, Object> pay(String subject, String orderId, BigDecimal amount, String userId, String bindCardId) {
+    public Map<String, Object> pay(String subject, String orderId, BigDecimal amount, String userId, String bindCardId,
+                                   String type) {
         String amountStr = amount.multiply(new BigDecimal("100")).setScale(0, RoundingMode.FLOOR)
                 .stripTrailingZeros().toPlainString();
         //通知地址
-        String notifyUrl = "http://xiongzhu.frp.izouma.com/notify";
+        String notifyUrl = payEaseProperties.getNotifyUrl()  + "/" + type + "/" + orderId;
         //回调地址
         String callbackUrl = "https://www.raex.vip/9th/home";
         //备注
@@ -156,7 +159,7 @@ public class PayEaseService {
         productDetail.setQuantity(1L);
         productDetail.setAmount(Long.parseLong(amountStr));
 
-        OrderBuilder builder = new OrderBuilder(merchantId);
+        OrderBuilder builder = new OrderBuilder(payEaseProperties.getMerchantId());
         builder.setRequestId(orderId)
                 .setOrderAmount(amountStr)
                 .setOrderCurrency("CNY")
@@ -189,7 +192,7 @@ public class PayEaseService {
     }
 
     public void payConfirm(String orderId, String paymentOrderId, String code) {
-        ReceiptPaymentBuilder builder = new ReceiptPaymentBuilder(merchantId);
+        ReceiptPaymentBuilder builder = new ReceiptPaymentBuilder(payEaseProperties.getMerchantId());
         builder.setRequestId(orderId)
                 .setPaymentOrderId(paymentOrderId)
                 .setKaptchaCode(code);

+ 14 - 2
src/main/resources/application.yaml

@@ -238,7 +238,9 @@ hmpay:
   app-private-key: MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJCaYSAw8c2uk4gry+/uy5thmzgdg1tPr6TRRj25AKxa13hnhjMEzp/eD8++LHxyPXg0ZXlbotZ/g0ES1XHJMkmHA4fRZ6Ki35LxlY60Z8xRwaTZXIctlaCkjhJmURNncQzyB5XMFF2M6cgy1T0yr+czoVPelVEFbAWu4cg/kQ1tAgMBAAECgYAGQwktsbDm7UZqQStFqpuakPF9zplfnOXIR1+5UIec7xohlqoTD4Q7HAynPF8EzJWo3OwAA13b2A3BBaXElafdwod7J2H9zlGJiqfmsnSTMhapVYsBbqnXGYWFS33wAm1Wx4Y9hSQxUD6AsZ+A05RiolrTTfAAGMS9E4sGhh1O6QJBANGUbGUednN4/0A0KlH3pWgLKPT+JyMeZLFGXeFLJpwWf25Xj98JcGai5t9sDqPl6xSgkEnJHdLB7LNEnmqr5X8CQQCwoaZwsVd0jnW6RU6F3SZ+BY4YS7SAhMlElqaJbBTP7DbXH/Z3cS1V696bvKup6+HlI/l0YwTDdRJIR0hl9XsTAkEAwFpPWkepQ7ZL36uBJBX9FA8aGjGhzhO5KxOAWqTU3PGxJ57qBzTsmubsqybMERWWuynbBD24R5WBH8/c7d6zFQJAShIP9TQ5Y5SWRB3qVvKtwK1dsEyXDkohCRVQE1Lyy1rYiJBL0Dzy8RQvzwlox6I2odvbMXaQudKvbwYNk0xFZwJAAxAeFweoXqDWcYl7Oa4nmgbM9LVqAMCbjzkChquXvj5q5sE9LOXiSMfbnDalNlLonbApnuTx5YCJYB0jA0ml8g==
   app-public-key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQmmEgMPHNrpOIK8vv7subYZs4HYNbT6+k0UY9uQCsWtd4Z4YzBM6f3g/Pvix8cj14NGV5W6LWf4NBEtVxyTJJhwOH0Weiot+S8ZWOtGfMUcGk2VyHLZWgpI4SZlETZ3EM8geVzBRdjOnIMtU9Mq/nM6FT3pVRBWwFruHIP5ENbQIDAQAB
   hm-public-key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCLobxNslmsua5fnegILQSMioA5N0E5Kfg1hYLzhOuPdyJbFIImFkRF8RYt6Fp24LpDfpEEBhX8EGYIJSPpRWPZYVBzlGWOj1jS0FeF/JK+8a8ihgSxAU2JwsUySqGv+8aXIofJUus/j/KEPQZgjyVebi9J/ww75pbpGrymnAZUdwIDAQAB
-  notify-url: http://xiongzhu.frp.izouma.com/hmpay/notify
+  notify-url: http://raex.frp.izouma.com/hmpay/notify
+payease:
+  notify-url: http://raex.frp.izouma.com/payease/notify
 ---
 
 spring:
@@ -277,6 +279,8 @@ sandpay:
   notify-url: https://testorder.raex.vip/sandpay/notify
 hmpay:
   notify-url: https://testorder.raex.vip/hmpay/notify
+payease:
+  notify-url: https://testorder.raex.vip/payease/notify
 ---
 
 spring:
@@ -394,6 +398,8 @@ sandpay:
   notify-url: https://order.raex.vip/sandpay/notify
 hmpay:
   notify-url: https://order.raex.vip/hmpay/notify
+payease:
+  notify-url: https://order.raex.vip/payease/notify
 ---
 
 spring:
@@ -445,6 +451,8 @@ sandpay:
   notify-url: https://order.raex.vip/sandpay/notify
 hmpay:
   notify-url: https://order.raex.vip/hmpay/notify
+payease:
+  notify-url: https://order.raex.vip/payease/notify
 ---
 
 spring:
@@ -488,6 +496,8 @@ sandpay:
   notify-url: https://testorder.raex.vip/sandpay/notify
 hmpay:
   notify-url: https://testorder.raex.vip/hmpay/notify
+payease:
+  notify-url: https://testorder.raex.vip/payease/notify
 ---
 
 spring:
@@ -538,4 +548,6 @@ rocketmq:
 sandpay:
   notify-url: https://nfttest.raex.vip/sandpay/notify
 hmpay:
-  notify-url: https://nfttest.raex.vip/hmpay/notify
+  notify-url: https://nfttest.raex.vip/hmpay/notify
+payease:
+  notify-url: https://nfttest.raex.vip/payease/notify