集成支付宝支付功能
新增支付宝支付控制器中的异步通知处理,并添加必要的依赖项。实现基本的支付通知逻辑,以便接收和验证支付宝的支付回调。 - 在`PaymentController`中添加处理支付宝支付通知的方法。 - 引入`alipay-easysdk`依赖项以支持支付宝支付功能。 - 实现支付回调的基本日志记录和参数处理。 - 注释和文档无重大变化,保持清晰。master
parent
099e3f1452
commit
c2e5a0611a
10
pom.xml
10
pom.xml
|
@ -17,6 +17,16 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
|
||||
|
||||
<!--引入支付宝支付 -->
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay-easysdk</artifactId>
|
||||
<version>2.2.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay-sdk-java</artifactId>
|
||||
|
|
|
@ -6,16 +6,21 @@ import com.alipay.api.AlipayClient;
|
|||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipayTradePagePayRequest;
|
||||
import com.alipay.api.response.AlipayTradePagePayResponse;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.PaymentParam;
|
||||
import com.muyu.config.util.SfUtil;
|
||||
import com.muyu.config.util.StandingRes;
|
||||
import com.muyu.system.service.SysUserService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/8/25 下午3:21
|
||||
|
@ -77,6 +82,38 @@ public class PaymentController {
|
|||
return Result.success(response.getBody());
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/notify") // 注意这里必须是POST接口
|
||||
public String payNotify(HttpServletRequest request) throws Exception {
|
||||
if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
|
||||
System.out.println("=========支付宝异步回调========");
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
Map<String, String[]> requestParams = request.getParameterMap();
|
||||
for (String name : requestParams.keySet()) {
|
||||
params.put(name, request.getParameter(name));
|
||||
// System.out.println(name + " = " + request.getParameter(name));
|
||||
}
|
||||
|
||||
String tradeNo = params.get("out_trade_no");
|
||||
String gmtPayment = params.get("gmt_payment");
|
||||
String alipayTradeNo = params.get("trade_no");
|
||||
// 支付宝验签
|
||||
if (Factory.Payment.Common().verifyNotify(params)) {
|
||||
// 验签通过
|
||||
System.out.println("交易名称: " + params.get("subject"));
|
||||
System.out.println("交易状态: " + params.get("trade_status"));
|
||||
System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
|
||||
System.out.println("商户订单号: " + params.get("out_trade_no"));
|
||||
System.out.println("交易金额: " + params.get("total_amount"));
|
||||
System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
|
||||
System.out.println("买家付款时间: " + params.get("gmt_payment"));
|
||||
System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
|
||||
}
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SysUserService userService;
|
||||
//TODO 充值记录添加
|
||||
|
|
Loading…
Reference in New Issue