Переглянути джерело

fix : 米大师支付逻辑bug修改

bilingfeng 1 рік тому
батько
коміт
37ca39ce41

+ 29 - 0
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/rpc/IOrderServiceRpc.java

@@ -0,0 +1,29 @@
+package com.zanxiang.game.module.base.rpc;
+
+import java.util.Map;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-27
+ * @description : SDK订单接口
+ */
+public interface IOrderServiceRpc {
+
+    /**
+     * cp通知
+     *
+     * @param orderId 订单id
+     * @param payKey  支付关键
+     * @return boolean
+     */
+    boolean orderCpCall(String orderId, String payKey);
+
+    /**
+     * 米大师支付回调
+     *
+     * @param orderId 订单id
+     * @param payKey  支付关键
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    Map<String, Object> miPayNotify(String orderId, String payKey);
+}

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <dubbo升级3.0, 一大波修改上线> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <dubbo升级3.0, 米大师支付逻辑bug修改> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 0 - 27
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/PayController.java

@@ -1,17 +1,12 @@
 package com.zanxiang.game.module.sdk.controller;
 
 import com.zanxiang.game.module.base.pojo.enums.PayWayEnum;
-import com.zanxiang.game.module.mybatis.entity.GameExt;
 import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
 import com.zanxiang.game.module.sdk.annotation.ValidLogin;
-import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
 import com.zanxiang.game.module.sdk.pojo.param.ProductPayParam;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.pojo.vo.PayParamVO;
-import com.zanxiang.game.module.sdk.service.IGameExtService;
 import com.zanxiang.game.module.sdk.service.IOrderPayService;
-import com.zanxiang.game.module.sdk.service.IOrderService;
-import com.zanxiang.game.module.sdk.service.IPerformOrderService;
 import com.zanxiang.game.module.sdk.service.pay.MiPayService;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.pojo.ResultVO;
@@ -22,12 +17,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.Map;
-import java.util.Objects;
 
 /**
  * 支付公共入口
@@ -99,24 +92,4 @@ public class PayController {
     public ResultVO<Boolean> getResult(@RequestParam String orderId) {
         return ResultVO.ok(orderPayService.payResult(orderId));
     }
-
-    @Autowired
-    private IPerformOrderService performOrderService;
-
-    @Resource
-    private IOrderService orderService;
-
-    @Autowired
-    private IGameExtService gameExtService;
-
-    @UnSignCheck
-    @GetMapping(value = "/get/budan")
-    public ResultVO<Boolean> budan(@RequestParam String orderId) {
-        PlatformOrderDTO platformOrderDTO = orderService.getByOrderId(orderId);
-        GameExt gameExt = gameExtService.getByGameId(platformOrderDTO.getGameId());
-        if (Objects.equals(gameExt.getCustomerPhone(), orderId)) {
-            performOrderService.pushCp(platformOrderDTO);
-        }
-        return ResultVO.ok(true);
-    }
 }

+ 58 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/rpc/impl/OrderServiceRpcImpl.java

@@ -0,0 +1,58 @@
+package com.zanxiang.game.module.sdk.rpc.impl;
+
+import com.zanxiang.game.module.base.rpc.IOrderServiceRpc;
+import com.zanxiang.game.module.mybatis.entity.GameExt;
+import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
+import com.zanxiang.game.module.sdk.service.IGameExtService;
+import com.zanxiang.game.module.sdk.service.IOrderService;
+import com.zanxiang.game.module.sdk.service.IPerformOrderService;
+import com.zanxiang.game.module.sdk.service.pay.MiPayService;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.annotation.Resource;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-27
+ * @description : 游戏订单
+ */
+@DubboService
+public class OrderServiceRpcImpl implements IOrderServiceRpc {
+
+    @Autowired
+    private IPerformOrderService performOrderService;
+
+    @Resource
+    private IOrderService orderService;
+
+    @Autowired
+    private IGameExtService gameExtService;
+
+    @Autowired
+    private MiPayService miPayService;
+
+    @Override
+    public boolean orderCpCall(String orderId, String payKey) {
+        PlatformOrderDTO platformOrderDTO = orderService.getByOrderId(orderId);
+        GameExt gameExt = gameExtService.getByGameId(platformOrderDTO.getGameId());
+        if (Objects.equals(gameExt.getPayKey(), payKey)) {
+            return performOrderService.pushCp(platformOrderDTO);
+        }
+        return false;
+    }
+
+    @Override
+    public Map<String, Object> miPayNotify(String orderId, String payKey) {
+        PlatformOrderDTO platformOrderDTO = orderService.getByOrderId(orderId);
+        GameExt gameExt = gameExtService.getByGameId(platformOrderDTO.getGameId());
+        if (Objects.equals(gameExt.getPayKey(), payKey)) {
+            return miPayService.notify(orderId);
+        }
+        return Collections.emptyMap();
+    }
+
+}

+ 2 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/CallBackServiceImpl.java

@@ -206,6 +206,7 @@ public class CallBackServiceImpl implements ICallBackService {
                 .orderStatus(platformOrderDTO.getStatus())
                 .payTime(platformOrderDTO.getPayTime())
                 .userActionSetId(agent.getUserActionSetId())
+                .roleName(platformOrderDTO.getRoleName())
                 .build();
     }
 
@@ -228,6 +229,7 @@ public class CallBackServiceImpl implements ICallBackService {
                 .createTime(platformOrderDTO.getCreateTime())
                 .payTime(platformOrderDTO.getPayTime())
                 .regTime(regTime)
+                .roleName(platformOrderDTO.getRoleName())
                 .build();
     }
 }

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/pay/AliPayService.java

@@ -70,7 +70,7 @@ public class AliPayService extends PayBaseService {
     /**
      * 订单超时自动关闭时间
      */
-    private static final long TIME_EXPIRE = 2L;
+    private static final long TIME_EXPIRE = 5L;
 
     /**
      * 同步回调地址配置

+ 24 - 31
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/pay/MiPayService.java

@@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
+import reactor.util.function.Tuple2;
+import reactor.util.function.Tuples;
 
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
@@ -87,33 +89,23 @@ public class MiPayService extends PayBaseService {
         String sessionKey = userDTO.getSessionKey();
         //获取米大师钱包余额
         Long balance = this.midasGetBalance(openId, sessionKey);
-        //返回参数
+        //返回充值参数
         Map<String, Object> payParamMap = new HashMap<>(9);
-        //余额充足, 直接扣除
-        if (balance >= orderInfo.getAmount().longValue()) {
-            String billNo = this.midasPay(openId, sessionKey, orderInfo.getAmount(), orderInfo.getOrderId());
-            payParamMap.put("status", "0");
-            payParamMap.put("billNo", billNo);
-            //支付成功
-            this.paySuccess(product.getOutTradeNo(), orderInfo.getAmount().toString(), config.getAppId());
-        } else {
-            //余额不足, 返回订单id, 前端调充值接口, 充值完后再继续支付
-            payParamMap.put("currencyType", "CNY");
-            payParamMap.put("mode", "game");
-            payParamMap.put("zoneId", "1");
-            payParamMap.put("offerId", config.getOfferId());
-            payParamMap.put("env", String.valueOf(this.isSand));
-            payParamMap.put("buyQuantity", orderInfo.getAmount().intValue());
-            payParamMap.put("status", "1");
-            payParamMap.put("balance", String.valueOf(balance));
-            payParamMap.put("orderId", product.getOutTradeNo());
-            payParamMap.put("platform", "android");
-            //更新订单商户信息
-            orderService.update(new LambdaUpdateWrapper<Order>()
-                    .set(Order::getMerchantNo, config.getOfferId())
-                    .set(Order::getStatus, OrderStateEnum.WAIT_PAY.getCode())
-                    .eq(Order::getOrderId, product.getOutTradeNo()));
-        }
+        payParamMap.put("currencyType", "CNY");
+        payParamMap.put("mode", "game");
+        payParamMap.put("zoneId", "1");
+        payParamMap.put("offerId", config.getOfferId());
+        payParamMap.put("env", String.valueOf(this.isSand));
+        payParamMap.put("buyQuantity", orderInfo.getAmount().intValue());
+        payParamMap.put("status", "1");
+        payParamMap.put("balance", String.valueOf(balance));
+        payParamMap.put("orderId", product.getOutTradeNo());
+        payParamMap.put("platform", "android");
+        //更新订单商户信息
+        orderService.update(new LambdaUpdateWrapper<Order>()
+                .set(Order::getMerchantNo, config.getOfferId())
+                .set(Order::getStatus, OrderStateEnum.WAIT_PAY.getCode())
+                .eq(Order::getOrderId, product.getOutTradeNo()));
         log.error("米大师支付返回参数 payParamMap : {}", JsonUtil.toString(payParamMap));
         return payParamMap;
     }
@@ -144,7 +136,7 @@ public class MiPayService extends PayBaseService {
         return Long.valueOf(resultMap.get("balance"));
     }
 
-    private String midasPay(String openId, String sessionKey, BigDecimal amount, String orderId) {
+    private Tuple2<Long, String> midasPay(String openId, String sessionKey, BigDecimal amount, String orderId) {
         //接口参数
         Map<String, Object> postBodyMap = new HashMap<>(7);
         postBodyMap.put("openid", openId);
@@ -169,7 +161,8 @@ public class MiPayService extends PayBaseService {
         //调接口返回
         String url = URIUtil.fillUrlParams(MiPayService.MI_PAY_HOST + MiPayService.PAY_URL, headParamMap, Boolean.FALSE);
         Map<String, String> resultMap = this.miPayApi(url, postBody);
-        return resultMap.get("bill_no");
+        //返回扣款参数
+        return Tuples.of(Long.valueOf(resultMap.get("balance")), resultMap.get("bill_no"));
     }
 
     private Map<String, String> miPayApi(String url, String postBody) {
@@ -264,13 +257,13 @@ public class MiPayService extends PayBaseService {
             throw new BaseException("米大师游戏币不足, 无法扣除!");
         }
         //余额充足, 直接扣除
-        String billNo = this.midasPay(openId, sessionKey, platformOrderDTO.getAmount(), platformOrderDTO.getOrderId());
+        Tuple2<Long, String> tuple2 = this.midasPay(openId, sessionKey, platformOrderDTO.getAmount(), platformOrderDTO.getOrderId());
         //支付成功
-        this.paySuccess(platformOrderDTO.getOrderId(), platformOrderDTO.getAmount().toString(), config.getAppId());
+        this.paySuccess(platformOrderDTO.getOrderId(), platformOrderDTO.getAmount().toString(), tuple2.getT2());
         //返回参数
         Map<String, Object> payParamMap = new HashMap<>(2);
         payParamMap.put("status", "0");
-        payParamMap.put("billNo", billNo);
+        payParamMap.put("billNo", tuple2.getT2());
         return payParamMap;
     }
 

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/pay/PayBaseService.java

@@ -129,7 +129,7 @@ public abstract class PayBaseService {
      */
     public void orderExpire(String orderId) {
         //过期时间
-        double expire = (double) DateUtil.localDateTimeToMilli(LocalDateTime.now().plusMinutes(5));
+        double expire = (double) DateUtil.localDateTimeToMilli(LocalDateTime.now().plusMinutes(10));
         //设置缓存
         redisUtil.addZSet(RedisKeyConstant.ORDER_EXPIRE, orderId, expire);
         log.error("订单添加过期缓存, orderId : {}, expire : {}", orderId, expire);