Files
aida_back/src/main/java/com/ai/da/controller/AliPayController.java

117 lines
3.8 KiB
Java
Raw Normal View History

2024-02-14 12:10:15 +08:00
package com.ai.da.controller;
import com.ai.da.common.response.Response;
import com.ai.da.model.dto.ProductPurchaseDTO;
2024-02-14 12:10:15 +08:00
import com.ai.da.service.AliPayService;
2025-12-11 10:35:08 +08:00
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
2024-02-14 12:10:15 +08:00
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")
2025-12-11 10:35:08 +08:00
@Tag(name = "网站支付宝支付")
2024-02-14 12:10:15 +08:00
@Slf4j
public class AliPayController {
@Resource
private AliPayService aliPayService;
2025-12-11 10:35:08 +08:00
@Operation(summary = "统一收单下单并支付页面接口的调用")
@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表单包含自动提交的脚本
String formStr = aliPayService.tradeCreate(productPurchaseDTO, request);
2024-02-14 12:10:15 +08:00
//我们将form表单字符串返回给前端程序之后前端将会调用自动提交脚本进行表单的提交
//此时表单会自动提交到action属性所指向的支付宝开放平台中从而为用户展示一个支付页面
return Response.success(formStr);
}
2025-12-11 10:35:08 +08:00
@Operation(summary = "支付通知")
2024-02-14 12:10:15 +08:00
@PostMapping("/trade/notify")
public String tradeNotify(@RequestParam Map<String, String> params){
return aliPayService.tradeNotify(params);
2024-02-14 12:10:15 +08:00
}
/**
* 用户取消订单
* @param orderNo
* @return
*/
2025-12-11 10:35:08 +08:00
@Operation(summary = "用户取消订单")
2024-02-14 12:10:15 +08:00
@PostMapping("/trade/close/{orderNo}")
public Response<String> cancel(@PathVariable String orderNo){
log.info("取消订单");
aliPayService.cancelOrder(orderNo);
return Response.success("订单已取消");
}
/**
* 查询订单
* @param orderNo
* @return
*/
2025-12-11 10:35:08 +08:00
@Operation(summary = "查询订单:测试订单状态用")
2024-02-14 12:10:15 +08:00
@GetMapping("/trade/query/{orderNo}")
public Response<String> queryOrder(@PathVariable String orderNo) {
log.info("查询订单");
String result = aliPayService.queryOrder(orderNo);
return Response.success(result);
}
/**
* 不在页面提供申请退款接口
2024-02-14 12:10:15 +08:00
* @param orderNo
* @param reason
* @return
*/
2025-12-11 10:35:08 +08:00
@Operation(summary = "申请退款")
2024-02-14 12:10:15 +08:00
@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
*/
2025-12-11 10:35:08 +08:00
@Operation(summary = "查询退款:测试用")
2024-02-14 12:10:15 +08:00
@GetMapping("/trade/fastpay/refund/{orderNo}")
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
*/
2025-12-11 10:35:08 +08:00
@Operation(summary = "获取账单url")
2024-02-14 12:10:15 +08:00
@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);
}
}