xiongzhu 3 anni fa
parent
commit
40362f4f17

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

@@ -120,6 +120,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/appVersion/**").permitAll()
                 .antMatchers("/sandpay/**").permitAll()
                 .antMatchers("/hmpay/**").permitAll()
+                .antMatchers("/payease/**").permitAll()
                 .antMatchers("/order/calcSettle").permitAll()
                 .antMatchers("/ossNotify").permitAll()
                 .antMatchers("/priceList/list").permitAll()

+ 66 - 0
src/main/java/com/izouma/nineth/web/PayEaseController.java

@@ -0,0 +1,66 @@
+package com.izouma.nineth.web;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson15.JSONObject;
+import com.izouma.nineth.config.GeneralProperties;
+import com.izouma.nineth.enums.PayMethod;
+import com.izouma.nineth.event.OrderNotifyEvent;
+import com.izouma.nineth.service.GiftOrderService;
+import com.izouma.nineth.service.MintOrderService;
+import com.izouma.nineth.service.UserBalanceService;
+import com.upay.sdk.CipherWrapper;
+import com.upay.sdk.executer.ResultListenerAdpater;
+import com.upay.sdk.onlinepay.executer.OnlinePayOrderExecuter;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/payease")
+@Slf4j
+@AllArgsConstructor
+public class PayEaseController {
+    private final GeneralProperties  generalProperties;
+    private final RocketMQTemplate   rocketMQTemplate;
+    private final GiftOrderService   giftOrderService;
+    private final MintOrderService   mintOrderService;
+    private final UserBalanceService userBalanceService;
+
+    @PostMapping("/notify/{type}/{id}")
+    public String notify(@PathVariable String type, @PathVariable Long id, @RequestHeader String encryptKey,
+                         @RequestHeader String merchantId, @RequestBody JSONObject rawData) {
+        rawData.put("encryptKey", encryptKey);
+        rawData.put("merchantId", merchantId);
+        JSONObject data = CipherWrapper.bothDecryptWrap(rawData);
+        log.info("payEase回调 type={}, orderId={}, 参数={}", type, id, JSON.toJSONString(data, true));
+        OnlinePayOrderExecuter executor = new OnlinePayOrderExecuter();
+        executor.bothVerifyHmacOrder(data);
+
+        String status = data.getString("status");
+        if ("SUCCESS".equals(status)) {
+            String serialNumber = data.getString("serialNumber");
+            switch (type) {
+                case "order":
+                    rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
+                            new OrderNotifyEvent(id, PayMethod.PAYEASE, serialNumber, System.currentTimeMillis()));
+                    break;
+                case "gift":
+                    giftOrderService.giftNotify(id, PayMethod.PAYEASE, serialNumber);
+                    break;
+                case "mintOrder":
+                    mintOrderService.mintNotify(id, PayMethod.PAYEASE, serialNumber);
+                    break;
+                case "recharge":
+                    userBalanceService.recharge(id, PayMethod.PAYEASE, serialNumber);
+                    break;
+            }
+        }
+        return "SUCCESS";
+    }
+}

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

@@ -110,7 +110,7 @@ public class PayEaseTest {
         //订单金额
         String orderAmount = "1";
         //通知地址
-        String notifyUrl = "http://xiongzhu.frp.izouma.com/notify";
+        String notifyUrl = "http://xiongzhu.frp.izouma.com/payease/notify/test/" + requestId;
         //回调地址
         String callbackUrl = "https://www.raex.vip/9th/home";
         //备注
@@ -153,9 +153,9 @@ public class PayEaseTest {
 
     @Test
     public void payConfirm() {
-        String requestId = "976921447282769920";
-        String paymentOrderId = "eab03eb192c5456b8d802eed2b455bf8";
-        String kaptchaCode = "979671";
+        String requestId = "976931476920598528";
+        String paymentOrderId = "cd52f2434aaa4e5aa1059b9689f1d28d";
+        String kaptchaCode = "221600";
         ReceiptPaymentBuilder builder = new ReceiptPaymentBuilder(merchantId);
         builder.setRequestId(requestId)
                 .setPaymentOrderId(paymentOrderId)