xiongzhu 3 tahun lalu
induk
melakukan
7548dbfc75

+ 5 - 0
src/main/java/com/izouma/nineth/config/CacheConfig.java

@@ -129,6 +129,11 @@ public class CacheConfig {
                 .entryTtl(Duration.ofDays(7))
                 .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisTemplate.getValueSerializer()));
 
+        cacheNamesConfigurationMap.put("payOrder", RedisCacheConfiguration.defaultCacheConfig()
+                .entryTtl(Duration.ofHours(1))
+                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisTemplate.getValueSerializer())));
+
+
         RedisCacheManager redisCacheManager = RedisCacheManager.builder()
                 .cacheWriter(RedisCacheWriter.nonLockingRedisCacheWriter(redisTemplate.getConnectionFactory()))
                 .withInitialCacheConfigurations(cacheNamesConfigurationMap)

+ 1 - 0
src/main/java/com/izouma/nineth/security/WebSecurityConfig.java

@@ -119,6 +119,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/testClass/**").permitAll()
                 .antMatchers("/appVersion/**").permitAll()
                 .antMatchers("/sandpay/**").permitAll()
+                .antMatchers("/hmpay/**").permitAll()
                 .antMatchers("/order/calcSettle").permitAll()
                 // all other requests need to be authenticated
                 .anyRequest().authenticated().and()

+ 13 - 5
src/main/java/com/izouma/nineth/service/HMPayService.java

@@ -7,8 +7,8 @@ import com.alipay.api.internal.util.AlipaySignature;
 import com.github.kevinsawicki.http.HttpRequest;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.config.HmPayProperties;
+import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.utils.DateTimeUtils;
-import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -65,8 +65,8 @@ public class HMPayService {
         return DateTimeUtils.format(LocalDateTime.now().plusSeconds(seconds), "yyyyMMddHHmmss");
     }
 
-    public String requestAlipay(String orderId, BigDecimal amount, String subject, String desc,
-                                int timeout, String extend, String returnUrl) {
+    public JSONObject requestAlipayRaw(String orderId, BigDecimal amount, String subject,
+                                       int timeout, String type, String returnUrl) {
         if (orderId.length() < 12) {
             for (int i = orderId.length(); i < 12; i++) {
                 orderId = "0" + orderId;
@@ -100,8 +100,16 @@ public class HMPayService {
                 .send(JSON.toJSONString(params)).body();
         JSONObject res = JSON.parseObject(body);
         log.info("支付请求结果: {}", JSON.toJSONString(res, true));
+        return res;
+    }
 
-
-        return null;
+    public String requestAlipay(String orderId, BigDecimal amount, String subject,
+                                int timeout, String type, String returnUrl) {
+        JSONObject res = requestAlipayRaw(orderId, amount, subject, timeout, type, returnUrl);
+        if ("000000".equals(res.getString("ret_code"))) {
+            return res.getJSONObject("data").getString("token_id");
+        }
+        throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
     }
+
 }

+ 48 - 0
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -0,0 +1,48 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.config.GeneralProperties;
+import com.izouma.nineth.domain.Order;
+import com.izouma.nineth.enums.OrderStatus;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.GiftOrderRepo;
+import com.izouma.nineth.repo.MintOrderRepo;
+import com.izouma.nineth.repo.OrderRepo;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+@AllArgsConstructor
+public class OrderPayService {
+    private static String PAY_CHANNEL = "sandPay";
+
+    private final OrderRepo         orderRepo;
+    private final MintOrderRepo     mintOrderRepo;
+    private final GiftOrderRepo     giftOrderRepo;
+    private final SandPayService    sandPayService;
+    private final HMPayService      hmPayService;
+    private final GeneralProperties generalProperties;
+
+    public static void setPayChannel(String payChannel) {
+        PAY_CHANNEL = payChannel;
+    }
+
+    @Cacheable(value = "payOrder", key = "#orderId")
+    public String payOrder(Long orderId) {
+        Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != OrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+        switch (PAY_CHANNEL) {
+            case "sandPay":
+                return sandPayService.requestAlipay(orderId + "", order.getTotalPrice(), order.getName(),
+                        order.getName(), 180, "{\"type\":\"order\",\"id\":\"" + orderId + "\"}");
+            case "hmPay":
+                return hmPayService.requestAlipay(orderId + "", order.getTotalPrice(), order.getName(), 180,
+                        "order", generalProperties.getHost() + "/9th/orderDetail?id=" + orderId);
+        }
+        return null;
+    }
+}

+ 15 - 6
src/main/java/com/izouma/nineth/service/SandPayService.java

@@ -119,8 +119,17 @@ public class SandPayService {
         }
     }
 
-    public JSONObject requestAlipay(String orderId, BigDecimal amount, String subject, String desc,
-                                    int timeout, String extend) {
+    public String requestAlipay(String orderId, BigDecimal amount, String subject, String desc,
+                                int timeout, String extend) {
+        JSONObject res = requestAlipayRaw(orderId, amount, subject, desc, timeout, extend);
+        if ("000000".equals(res.getJSONObject("head").getString("respCode"))) {
+            return "alipays://platformapi/startapp?saId=10000007&qrcode=" + res.getJSONObject("body").getString("qrCode");
+        }
+        throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
+    }
+
+    public JSONObject requestAlipayRaw(String orderId, BigDecimal amount, String subject, String desc,
+                                       int timeout, String extend) {
         if (orderId.length() < 12) {
             for (int i = orderId.length(); i < 12; i++) {
                 orderId = "0" + orderId;
@@ -142,7 +151,7 @@ public class SandPayService {
         //body.put("limitPay", "5");                                  //限定支付方式 送1-限定不能使用贷记卡	送4-限定不能使用花呗	送5-限定不能使用贷记卡+花呗
         body.put("subject", subject);                                 //订单标题
         body.put("body", desc);                                       //订单描述
-        body.put("txnTimeOut", getTimeout(timeout));              //订单超时时间
+        body.put("txnTimeOut", getTimeout(timeout));                  //订单超时时间
         body.put("notifyUrl", sandPayProperties.getNotifyUrl());      //异步通知地址
         body.put("bizExtendParams", "");                              //业务扩展参数
         body.put("merchExtendParams", "");                            //商户扩展参数
@@ -239,7 +248,7 @@ public class SandPayService {
         extend.put("type", "order");
         extend.put("id", orderId);
 
-        JSONObject res = requestAlipay(orderId.toString(), order.getTotalPrice(), order.getName(), order.getName(),
+        JSONObject res = requestAlipayRaw(orderId.toString(), order.getTotalPrice(), order.getName(), order.getName(),
                 180, extend.toJSONString());
         if (res == null)
             throw new BusinessException("下单失败,请稍后再试");
@@ -296,7 +305,7 @@ public class SandPayService {
         extend.put("type", "gift");
         extend.put("id", orderId);
 
-        JSONObject res = requestAlipay(orderId.toString(), order.getGasPrice(), "转增" + order.getAssetId(), "转增" + order.getAssetId(),
+        JSONObject res = requestAlipayRaw(orderId.toString(), order.getGasPrice(), "转增" + order.getAssetId(), "转增" + order.getAssetId(),
                 180, extend.toJSONString());
         if (res == null)
             throw new BusinessException("下单失败,请稍后再试");
@@ -325,7 +334,7 @@ public class SandPayService {
         extend.put("type", "mintOrder");
         extend.put("id", orderId);
 
-        JSONObject res = requestAlipay(orderId.toString(), order.getGasPrice(), "铸造活动:" + order.getMintActivityId(),
+        JSONObject res = requestAlipayRaw(orderId.toString(), order.getGasPrice(), "铸造活动:" + order.getMintActivityId(),
                 "铸造活动:" + order.getMintActivityId(), 180, extend.toJSONString());
         if (res == null)
             throw new BusinessException("下单失败,请稍后再试");

+ 3 - 7
src/main/java/com/izouma/nineth/service/UserBalanceService.java

@@ -365,14 +365,10 @@ public class UserBalanceService {
                     record.setCurrentUserId(userBalance.getUserId());
                     autoWithdrawRecordRepo.saveAndFlush(record);
 
-
                     if (!success) {
-                        msg = msg == null ? "" : msg;
-                        if (msg.contains("风控") || Pattern.matches(".*\\[.*\\]", msg)) {
-                            userBalance.setLocked(true);
-                            userBalance.setLockReason(msg);
-                            userBalance.setLockTime(LocalDateTime.now());
-                        }
+                        userBalance.setLocked(true);
+                        userBalance.setLockReason(msg);
+                        userBalance.setLockTime(LocalDateTime.now());
                     }
                 }
             });

+ 10 - 1
src/main/java/com/izouma/nineth/service/UserService.java

@@ -145,7 +145,16 @@ public class UserService {
         if (level != null) {
             user.setLevel(level);
         }
-        return save(user);
+        user = save(user);
+        userRepo.updateAssetMinter(userId);
+        userRepo.updateAssetOwner(userId);
+        userRepo.updateCollectionMinter(userId);
+        userRepo.updateCollectionOwner(userId);
+        userRepo.updateOrderMinter(userId);
+        userRepo.updateHistoryFromUser(userId);
+        userRepo.updateHistoryToUser(userId);
+        userRepo.updateShowroomToUser(userId);
+        return user;
     }
 
     @Cacheable(value = "userList", key = "#pageQuery.hashCode()")

+ 20 - 0
src/main/java/com/izouma/nineth/web/HmPayController.java

@@ -0,0 +1,20 @@
+package com.izouma.nineth.web;
+
+import com.izouma.nineth.service.HMPayService;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/hmPay")
+@AllArgsConstructor
+public class HmPayController extends BaseController {
+    private final HMPayService hmPayService;
+
+    @PostMapping("/notify/{type}/{orderId}")
+    public String orderNotify(@PathVariable String type, @PathVariable String orderId) {
+        return "respCode=000000";
+    }
+}

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

@@ -35,16 +35,6 @@ public class SandPayController {
     private GiftOrderService  giftOrderService;
     private MintOrderService  mintOrderService;
 
-    @GetMapping(value = "/testUnion", produces = "text/html")
-    public String testUnion() {
-        JSONObject res = sandPayService.requestQuick(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");

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

@@ -5,36 +5,35 @@ import com.alibaba.fastjson.JSONObject;
 import com.izouma.nineth.service.SandPayService;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
 
 @RestController
-@RequestMapping("/sandPayTest")
+@RequestMapping("/sandPayMgr")
 @AllArgsConstructor
+@PreAuthorize("hasRole('ADMIN')")
 public class SandPayTestController {
     private final SandPayService    sandPayService;
     private final SnowflakeIdWorker snowflakeIdWorker;
 
-    @GetMapping(value = "/pay", produces = "text/html")
-    private String testpay() {
+    @GetMapping(value = "/pay")
+    private String pay() {
         JSONObject extend = new JSONObject();
         extend.put("type", "test");
         extend.put("id", 1);
-        JSONObject res = sandPayService.requestAlipay(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
+        JSONObject res = sandPayService.requestAlipayRaw(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
                 "话费充值", "话费充值", 180, extend.toJSONString());
-        String qrCode = res.getJSONObject("body").getString("qrCode");
-        return "<html><body><a style=\"font-size:28px;\" href=\"" + qrCode + "\">" + qrCode + "</a></body></html>";
+        return JSON.toJSONString(res, true);
     }
 
     @GetMapping(value = "/transfer")
     private String testTransfer(@RequestParam String name, @RequestParam String bank, @RequestParam BigDecimal amount) {
         return JSON.toJSONString(sandPayService.transfer(snowflakeIdWorker.nextId() + "", name, bank, amount), true);
-
     }
 
     @GetMapping(value = "/refund")

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

@@ -7,9 +7,6 @@ import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
-
-import static org.junit.jupiter.api.Assertions.*;
 
 class SandPayServiceTest extends ApplicationTests {
     @Autowired
@@ -19,7 +16,7 @@ class SandPayServiceTest extends ApplicationTests {
 
     @Test
     void requestAlipay() {
-        JSONObject jsonObject = sandPayService.requestAlipay(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
+        JSONObject jsonObject = sandPayService.requestAlipayRaw(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
                 "话费充值", "话费充值", 180, "");
         System.out.println(JSONObject.toJSONString(jsonObject, true));
     }