9.3 李雨欣测试购买记录接口 14:38

master
liyuxin 2024-09-03 14:38:23 +08:00
parent c7fcfa41de
commit ed87ca39c5
2 changed files with 6 additions and 11 deletions

View File

@ -12,14 +12,10 @@ import javax.annotation.PostConstruct;
@Component @Component
@ConfigurationProperties(prefix = "alipay") @ConfigurationProperties(prefix = "alipay")
public class MyAliPayConfig { public class MyAliPayConfig {
private String appId; private String appId;
private String appPrivateKey; private String appPrivateKey;
private String alipayPublicKey; private String alipayPublicKey;
private String notifyUrl; private String notifyUrl;
//支付成功后的回调地址
private String returnUrl;
@PostConstruct @PostConstruct
public void init() { public void init() {

View File

@ -5,15 +5,16 @@ import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient; import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest; import com.alipay.api.request.AlipayTradePagePayRequest;
import com.muyu.market.server.config.MyAliPayConfig;
import com.muyu.data.AliPay; import com.muyu.data.AliPay;
import com.muyu.market.server.config.MyAliPayConfig;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -26,9 +27,7 @@ public class AliPayController {
private static final String FORMAT_JSON = "JSON"; private static final String FORMAT_JSON = "JSON";
private static final String CHARSET_UTF8 = "UTF-8"; private static final String CHARSET_UTF8 = "UTF-8";
private static final String SIGN_TYPE_RSA2 = "RSA2"; private static final String SIGN_TYPE_RSA2 = "RSA2";
@Autowired
@Resource
private MyAliPayConfig myAliPayConfig; private MyAliPayConfig myAliPayConfig;
@GetMapping("/pay") @GetMapping("/pay")
@ -41,7 +40,7 @@ public class AliPayController {
aliPay.setTraceNo(UUID.randomUUID().toString().replaceAll("-","")); aliPay.setTraceNo(UUID.randomUUID().toString().replaceAll("-",""));
aliPay.setTotalAmount("100"); aliPay.setTotalAmount("100");
aliPay.setSubject("笔记本华硕"); aliPay.setSubject("笔记本华硕");
//=====
request.setBizContent("{\"out_trade_no\":\"" + aliPay.getTraceNo() + "\"," request.setBizContent("{\"out_trade_no\":\"" + aliPay.getTraceNo() + "\","
+ "\"total_amount\":\"" + aliPay.getTotalAmount() + "\"," + "\"total_amount\":\"" + aliPay.getTotalAmount() + "\","
+ "\"subject\":\"" + aliPay.getSubject() + "\"," + "\"subject\":\"" + aliPay.getSubject() + "\","
@ -59,6 +58,7 @@ public class AliPayController {
} }
@PostMapping("/notify") // 注意这里必须是POST接口 @PostMapping("/notify") // 注意这里必须是POST接口
public String payNotify(HttpServletRequest request) throws Exception { public String payNotify(HttpServletRequest request) throws Exception {
if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) { if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
@ -71,7 +71,6 @@ public class AliPayController {
// System.out.println(name + " = " + request.getParameter(name)); // System.out.println(name + " = " + request.getParameter(name));
} }
String tradeNo = params.get("out_trade_no"); String tradeNo = params.get("out_trade_no");
String gmtPayment = params.get("gmt_payment"); String gmtPayment = params.get("gmt_payment");
String alipayTradeNo = params.get("trade_no"); String alipayTradeNo = params.get("trade_no");