tj
2025-04-01 16c60b7e3b834b05599882ab1ffe99ec78664762
src/main/java/com/mzl/flower/web/v2/pay/AlipayController.java
@@ -10,13 +10,19 @@
import com.mzl.flower.base.BaseController;
import com.mzl.flower.base.R;
import com.mzl.flower.config.pay.AlipayProperties;
import com.mzl.flower.dto.request.productOrders.ProductOrdersCreateDTO;
import com.mzl.flower.entity.productOrders.ProductOrdersDO;
import com.mzl.flower.enums.PayTypeEnum;
import com.mzl.flower.service.productOrders.ProductOrdersService;
import com.mzl.flower.utils.alipay.OrderInfoUtil2_0;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@@ -38,33 +44,36 @@
    @Autowired
    AlipayClient alipayClient;
    @Autowired
    private ProductOrdersService productOrdersService;
    /**
     * 获取订单支付请求参数
     * @param
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/pay-order-info")
    @PostMapping(value = "/pay-order-info")
    @ApiOperation(value = "获取订单支付请求参数")
    public ResponseEntity getPayOrderInfo() throws Exception {
    public ResponseEntity getPayOrderInfo(@Validated @RequestBody ProductOrdersCreateDTO productOrdersCreateDTO) throws Exception {
        String orderId=" ";
        String totalAmount="0.01";
        String subject="测试支付";
        String body="我是测试支付";
//        创建订单
//        createAlipayOrder(orderId,totalAmount,subject);
        // 创建订单
        // 当前的支付类型是微信支付
        ProductOrdersDO productOrdersDTO=new ProductOrdersDO();
        BeanUtils.copyProperties(productOrdersCreateDTO,productOrdersDTO);
        productOrdersDTO.setPaymentMethod(PayTypeEnum.ALIPAY.getName());
        ProductOrdersDO productOrdersDO=productOrdersService.createProductOrders(productOrdersDTO);
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
        //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setBody("我是测试数据");
        model.setSubject("App支付测试Java");
        model.setOutTradeNo(OrderInfoUtil2_0.getOutTradeNo());
//        model.setOutTradeNo(orderId);
        model.setBody(productOrdersDO.getOrderType()+"_"+productOrdersDO.getCurrentPrice());
        model.setSubject(productOrdersDO.getOrderName());
        model.setOutTradeNo(productOrdersDO.getOrderNo());
        model.setTotalAmount(productOrdersDO.getCurrentPrice()+"");
        model.setTimeoutExpress("30m");
        model.setTotalAmount("0.01");
        model.setProductCode("QUICK_MSECURITY_PAY");
        request.setBizModel(model);
        request.setNotifyUrl(alipayProperties.getNotifyUrl());
@@ -111,6 +120,9 @@
        // 查看验签结果
        System.out.println(rsa2);
        if(rsa2){
            // 更新支付状态
            productOrdersService.updateProductOrderStatus(params);
            return "success";
        }