123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package com.zanxiang.sdk.controller;
- import com.zanxiang.common.domain.ResultMap;
- import com.zanxiang.common.domain.ResultVO;
- import com.zanxiang.common.enums.PayWayEnum;
- import com.zanxiang.common.utils.StringUtils;
- import com.zanxiang.sdk.annotation.UnSignCheck;
- import com.zanxiang.sdk.annotation.ValidLogin;
- import com.zanxiang.sdk.domain.bo.PlatformOrderBO;
- import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
- import com.zanxiang.sdk.domain.params.ProductPayParam;
- import com.zanxiang.sdk.domain.params.UserData;
- import com.zanxiang.sdk.service.OrderPayService;
- import com.zanxiang.sdk.service.PlatformOrderService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- 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;
- /**
- * 支付公共入口
- *
- * @author xufeng
- * @date 2022/6/8 14:49
- */
- @Api(tags = "支付公共入口")
- @RestController
- @RequestMapping(value = "/api/pay")
- @Slf4j
- public class PayController {
- @Resource
- private OrderPayService orderPayService;
- @Autowired
- private PlatformOrderService platformOrderService;
- @ApiOperation(value = "支付参数生成")
- @PostMapping(value = "/create")
- public ResultMap create(@Validated @RequestBody ProductPayParam product, @ValidLogin UserData userData) {
- String userId = String.valueOf(userData.getUserId());
- String cpId = "1";
- if (StringUtils.isEmpty(product.getOrderId())) {
- PlatformOrderBO orderBO = new PlatformOrderBO();
- orderBO.setAmount(product.getAmount());
- orderBO.setProductName(product.getProductName());
- orderBO.setProductId(product.getProductId());
- orderBO.setMgUserId(userData.getUserId());
- orderBO.setUserId(userId);
- orderBO.setGameId(userData.getGameId());
- orderBO.setCpId(cpId);
- orderBO.setFromDevice(userData.getDeviceSystem());
- orderBO.setPayDevice(userData.getDeviceType().toString());
- String orderId = platformOrderService.create(orderBO);
- product.setOrderId(orderId);
- }
- ProductPayParamBO bo = new ProductPayParamBO();
- bo.setGameId(userData.getGameId().toString());
- bo.setUserId(userId);
- bo.setPayDevice(product.getPayDevice() == null ? userData.getDeviceType() : product.getPayDevice());
- bo.setDeviceSystem(userData.getDeviceSystem());
- bo.setSpbillCreateIp(userData.getIp());
- bo.setOutTradeNo(product.getOrderId());
- bo.setPayWay(product.getPayWay());
- bo.setCode(product.getCode());
- return orderPayService.payCreate(bo);
- }
- @UnSignCheck
- @ApiOperation(value = "支付宝支付异步回调(二维码、H5、网站)")
- @RequestMapping(value = "/notify", method = RequestMethod.POST)
- public String aliPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
- return orderPayService.notify(request, response, PayWayEnum.ALIPAY.getNum());
- }
- @UnSignCheck
- @ApiOperation(value = "微信支付")
- @RequestMapping(value = "/wxPayNotify", method = RequestMethod.POST)
- public String wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
- return orderPayService.notify(request, response, PayWayEnum.WXPAY.getNum());
- }
- @UnSignCheck
- @ApiOperation(value = "支付宝支付同步回调(二维码、H5、网站)")
- @RequestMapping(value = "/alipaySynNotify", method = RequestMethod.GET)
- public ResultMap synNotify(HttpServletRequest request) {
- return orderPayService.synNotify(request, PayWayEnum.ALIPAY.getNum());
- }
- @ApiOperation(value = "获取订单支付结果")
- @RequestMapping(value = "/get/result", method = RequestMethod.GET)
- public ResultVO<Boolean> getResult(String orderId) {
- return ResultVO.ok(orderPayService.payResult(orderId));
- }
- }
|