2024-02-14 12:10:15 +08:00
|
|
|
|
package com.ai.da.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.ai.da.common.response.Response;
|
2025-01-07 14:31:43 +08:00
|
|
|
|
import com.ai.da.model.dto.ProductPurchaseDTO;
|
2024-02-14 12:10:15 +08:00
|
|
|
|
import com.ai.da.service.AliPayService;
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
2025-11-25 16:46:05 +08:00
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import jakarta.validation.Valid;
|
2024-02-14 12:10:15 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/api/ali-pay")
|
|
|
|
|
|
@Api(tags = "网站支付宝支付")
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
public class AliPayController {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private AliPayService aliPayService;
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("统一收单下单并支付页面接口的调用")
|
2025-01-07 14:31:43 +08:00
|
|
|
|
@PostMapping("/trade/page/pay")
|
|
|
|
|
|
public Response<String> tradePagePay(@Valid @RequestBody ProductPurchaseDTO productPurchaseDTO, HttpServletRequest request){
|
2024-02-14 12:10:15 +08:00
|
|
|
|
log.info("统一收单下单并支付页面接口的调用");
|
|
|
|
|
|
//支付宝开放平台接受 request 请求对象后
|
|
|
|
|
|
// 会为开发者生成一个html 形式的 form表单,包含自动提交的脚本
|
2025-01-07 14:31:43 +08:00
|
|
|
|
String formStr = aliPayService.tradeCreate(productPurchaseDTO, request);
|
2024-02-14 12:10:15 +08:00
|
|
|
|
//我们将form表单字符串返回给前端程序,之后前端将会调用自动提交脚本,进行表单的提交
|
|
|
|
|
|
//此时,表单会自动提交到action属性所指向的支付宝开放平台中,从而为用户展示一个支付页面
|
|
|
|
|
|
return Response.success(formStr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("支付通知")
|
|
|
|
|
|
@PostMapping("/trade/notify")
|
|
|
|
|
|
public String tradeNotify(@RequestParam Map<String, String> params){
|
2024-03-01 17:31:26 +08:00
|
|
|
|
return aliPayService.tradeNotify(params);
|
2024-02-14 12:10:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用户取消订单
|
|
|
|
|
|
* @param orderNo
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@ApiOperation("用户取消订单")
|
|
|
|
|
|
@PostMapping("/trade/close/{orderNo}")
|
|
|
|
|
|
public Response<String> cancel(@PathVariable String orderNo){
|
|
|
|
|
|
log.info("取消订单");
|
|
|
|
|
|
aliPayService.cancelOrder(orderNo);
|
|
|
|
|
|
return Response.success("订单已取消");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询订单
|
|
|
|
|
|
* @param orderNo
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@ApiOperation("查询订单:测试订单状态用")
|
|
|
|
|
|
@GetMapping("/trade/query/{orderNo}")
|
|
|
|
|
|
public Response<String> queryOrder(@PathVariable String orderNo) {
|
|
|
|
|
|
log.info("查询订单");
|
|
|
|
|
|
String result = aliPayService.queryOrder(orderNo);
|
|
|
|
|
|
return Response.success(result);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2024-03-15 15:38:56 +08:00
|
|
|
|
* 不在页面提供申请退款接口
|
2024-02-14 12:10:15 +08:00
|
|
|
|
* @param orderNo
|
|
|
|
|
|
* @param reason
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@ApiOperation("申请退款")
|
|
|
|
|
|
@PostMapping("/trade/refund/{orderNo}/{reason}")
|
|
|
|
|
|
public Response<String> refunds(@PathVariable String orderNo, @PathVariable String reason){
|
|
|
|
|
|
log.info("申请退款");
|
|
|
|
|
|
aliPayService.refund(orderNo, reason);
|
|
|
|
|
|
return Response.success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询退款
|
|
|
|
|
|
* @param orderNo
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
@ApiOperation("查询退款:测试用")
|
|
|
|
|
|
@GetMapping("/trade/fastpay/refund/{orderNo}")
|
2024-03-01 17:31:26 +08:00
|
|
|
|
public Response<String> queryRefund(@PathVariable String orderNo) {
|
2024-02-14 12:10:15 +08:00
|
|
|
|
log.info("查询退款");
|
|
|
|
|
|
String result = aliPayService.queryRefund(orderNo);
|
|
|
|
|
|
return Response.success(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据账单类型和日期获取账单url地址
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param billDate
|
|
|
|
|
|
* @param type
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@ApiOperation("获取账单url")
|
|
|
|
|
|
@GetMapping("/bill/downloadurl/query/{billDate}/{type}")
|
|
|
|
|
|
public Response<String> queryTradeBill(
|
|
|
|
|
|
@PathVariable String billDate,
|
|
|
|
|
|
@PathVariable String type) {
|
|
|
|
|
|
log.info("获取账单url");
|
|
|
|
|
|
String downloadUrl = aliPayService.queryBill(billDate, type);
|
|
|
|
|
|
return Response.success(downloadUrl);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|