zhujie
10 天以前 19428a49b4c07b14097615d48a7a72dbf941c4e7
src/main/java/com/mzl/flower/web/v2/pay/AlipayController.java
@@ -7,16 +7,25 @@
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
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.pay.PayQueryDTO;
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.pay.AlipayService;
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 +47,39 @@
    @Autowired
    AlipayClient alipayClient;
    @Autowired
    private ProductOrdersService productOrdersService;
    @Autowired
    private AlipayService alipayService;
    /**
     * 获取订单支付请求参数
     * @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());
@@ -81,6 +96,18 @@
        }
    }
    /**
     * 支付宝回调url
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/order/status")
    @ApiOperation(value = "订单状态")
    public AlipayTradeQueryResponse queryOrderByOutOrderNo(@Validated @RequestBody PayQueryDTO payQueryDTO, HttpServletRequest request) throws Exception{
        AlipayTradeQueryResponse response=alipayService.queryOrderByOutOrderNo(payQueryDTO.getOuterOrderNo());
        return response;
    }
    /**
     * 支付宝回调url
     * @param request
@@ -111,6 +138,9 @@
        // 查看验签结果
        System.out.println(rsa2);
        if(rsa2){
            // 更新支付状态
            productOrdersService.updateProductOrderStatus(params);
            return "success";
        }