|
@@ -1,23 +1,17 @@
|
|
|
-package com.zanxiang.sdk.service.Impl.pay;
|
|
|
+package com.zanxiang.sdk.service.pay;
|
|
|
|
|
|
import com.zanxiang.common.domain.ResultMap;
|
|
|
import com.zanxiang.common.enums.OrderStateEnum;
|
|
|
-import com.zanxiang.common.enums.PayWayEnum;
|
|
|
-import com.zanxiang.common.exception.BaseException;
|
|
|
-import com.zanxiang.common.utils.SpringUtils;
|
|
|
import com.zanxiang.mybatis.entity.GamePayWay;
|
|
|
import com.zanxiang.sdk.domain.bo.PlatformOrderBO;
|
|
|
import com.zanxiang.sdk.domain.bo.ProductPayAttachParamBO;
|
|
|
import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
|
|
|
import com.zanxiang.sdk.domain.dto.PlatformOrderDTO;
|
|
|
import com.zanxiang.sdk.service.GamePayWayService;
|
|
|
-import com.zanxiang.sdk.service.OrderPayService;
|
|
|
import com.zanxiang.sdk.service.PlatformOrderService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.jdom.JDOMException;
|
|
|
-import org.springframework.beans.BeansException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -26,18 +20,18 @@ import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
- * 支付调用
|
|
|
- *
|
|
|
- * @author xufeng
|
|
|
- * @date 2022/6/8 16:45
|
|
|
+ * @author : lingfeng
|
|
|
+ * @time : 2022-09-28
|
|
|
+ * @description : 支付超类
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-@Service
|
|
|
-public class PayService {
|
|
|
+public abstract class PayBaseService {
|
|
|
|
|
|
+ @Lazy
|
|
|
@Autowired
|
|
|
public PlatformOrderService platformOrderService;
|
|
|
|
|
|
+ @Lazy
|
|
|
@Autowired
|
|
|
public GamePayWayService gamePayWayService;
|
|
|
|
|
@@ -76,9 +70,7 @@ public class PayService {
|
|
|
attachBO.setGamePayWayId(payInfo.getId());
|
|
|
product.setAttach(attachBO);
|
|
|
this.attach = attachBO;
|
|
|
- String payCode = PayWayEnum.getCodeByNum(product.getPayWay());
|
|
|
- OrderPayService device = getDevice(payCode);
|
|
|
- ResultMap result = device.create(product);
|
|
|
+ ResultMap result = this.create(product);
|
|
|
log.info("订单支付参数生成 ProductPayParamBO:{},result:{}", product, result);
|
|
|
return result;
|
|
|
} catch (RuntimeException e) {
|
|
@@ -89,43 +81,23 @@ public class PayService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 支付异步回调
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @param response
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String notify(HttpServletRequest request, HttpServletResponse response, Integer payType) throws IOException, JDOMException {
|
|
|
- String payCode = PayWayEnum.getCodeByNum(payType);
|
|
|
- OrderPayService device = getDevice(payCode);
|
|
|
- return device.notify(request, response);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 同步消息通知
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultMap synNotify(HttpServletRequest request, Integer payType) {
|
|
|
- String payCode = PayWayEnum.getCodeByNum(payType);
|
|
|
- OrderPayService device = getDevice(payCode);
|
|
|
- return device.synNotify(request);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取支付驱动方式
|
|
|
+ * 支付成功逻辑
|
|
|
*
|
|
|
- * @param payCode
|
|
|
- * @return
|
|
|
+ * @param orderNo 订单号
|
|
|
+ * @param realAmount 真实金额
|
|
|
+ * @param merchantOrderNo 订单流水号
|
|
|
+ * @param gamePayWayId 具体游戏支付方式id
|
|
|
+ * @return : 返回支付状态
|
|
|
*/
|
|
|
- private static OrderPayService getDevice(String payCode) {
|
|
|
- try {
|
|
|
- log.error("获取支付驱动方式, payCode : {}", payCode);
|
|
|
- return SpringUtils.getBean(payCode + "Service");
|
|
|
- } catch (BeansException e) {
|
|
|
- throw new BaseException("支付方式不存在");
|
|
|
- }
|
|
|
+ public Boolean paySuccess(String orderNo, String realAmount, String merchantOrderNo, String gamePayWayId) {
|
|
|
+ PlatformOrderBO bo = new PlatformOrderBO();
|
|
|
+ bo.setId(orderNo);
|
|
|
+ bo.setRealAmount(new BigDecimal(realAmount));
|
|
|
+ bo.setMerchantOrderNo(merchantOrderNo);
|
|
|
+ bo.setStatus(OrderStateEnum.SUCCESS.getCode());
|
|
|
+ bo.setGamePaywayId(gamePayWayId);
|
|
|
+ bo.setPayTime(new Date());
|
|
|
+ return platformOrderService.pay(bo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -150,23 +122,37 @@ public class PayService {
|
|
|
return gamePayWayService.getInfo(gamePayWay).getPayConfig();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 支付成功逻辑
|
|
|
+ * 支付调起
|
|
|
*
|
|
|
- * @param orderNo 订单号
|
|
|
- * @param realAmount 真实金额
|
|
|
- * @param merchantOrderNo 订单流水号
|
|
|
- * @param gamePayWayId 具体游戏支付方式id
|
|
|
- * @return : 返回支付状态
|
|
|
+ * @param product : 调起支付的参数
|
|
|
+ * @return : 返回支付参数
|
|
|
*/
|
|
|
- public Boolean paySuccess(String orderNo, String realAmount, String merchantOrderNo, String gamePayWayId) {
|
|
|
- PlatformOrderBO bo = new PlatformOrderBO();
|
|
|
- bo.setId(orderNo);
|
|
|
- bo.setRealAmount(new BigDecimal(realAmount));
|
|
|
- bo.setMerchantOrderNo(merchantOrderNo);
|
|
|
- bo.setStatus(OrderStateEnum.SUCCESS.getCode());
|
|
|
- bo.setGamePaywayId(gamePayWayId);
|
|
|
- bo.setPayTime(new Date());
|
|
|
- return platformOrderService.pay(bo);
|
|
|
- }
|
|
|
+ public abstract ResultMap create(ProductPayParamBO product);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付异步回调
|
|
|
+ *
|
|
|
+ * @param request : 回调请求
|
|
|
+ * @param response : 回调返回
|
|
|
+ * @return : 返回回调结果
|
|
|
+ * @throws IOException : io异常
|
|
|
+ */
|
|
|
+ public abstract String notify(HttpServletRequest request, HttpServletResponse response) throws IOException;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付同步回调
|
|
|
+ *
|
|
|
+ * @param request : 回调参数
|
|
|
+ * @return : 返回回调结果
|
|
|
+ */
|
|
|
+ public abstract ResultMap synNotify(HttpServletRequest request);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 配置初始化
|
|
|
+ *
|
|
|
+ * @param obj : 配置参数
|
|
|
+ */
|
|
|
+ public abstract void configInit(String obj);
|
|
|
}
|