9.3 李雨欣测试购买记录接口 12:03
parent
0830a4cfc2
commit
47219ffd0b
|
@ -16,6 +16,8 @@ public class MyAliPayConfig {
|
||||||
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() {
|
||||||
|
|
|
@ -5,15 +5,18 @@ 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.alipay.easysdk.factory.Factory;
|
||||||
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,21 +29,27 @@ 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")
|
||||||
public void pay(AliPay aliPay, HttpServletResponse httpResponse) throws Exception{
|
public void pay(AliPay aliPay, HttpServletResponse httpResponse) throws Exception{
|
||||||
|
|
||||||
|
|
||||||
AlipayClient alipayClient = new DefaultAlipayClient(GATEWAY_URL, myAliPayConfig.getAppId(),
|
AlipayClient alipayClient = new DefaultAlipayClient(GATEWAY_URL, myAliPayConfig.getAppId(),
|
||||||
myAliPayConfig.getAppPrivateKey(), FORMAT_JSON, CHARSET_UTF8, myAliPayConfig.getAlipayPublicKey(), SIGN_TYPE_RSA2);
|
myAliPayConfig.getAppPrivateKey(), FORMAT_JSON,
|
||||||
|
CHARSET_UTF8, myAliPayConfig.getAlipayPublicKey(),
|
||||||
|
SIGN_TYPE_RSA2);
|
||||||
|
|
||||||
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
|
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
|
||||||
request.setNotifyUrl(myAliPayConfig.getNotifyUrl());
|
request.setNotifyUrl(myAliPayConfig.getNotifyUrl());
|
||||||
//-商品的内容可以从系统中传递过来,目前这里是手写的
|
request.setReturnUrl(myAliPayConfig.getReturnUrl());
|
||||||
aliPay.setTraceNo(UUID.randomUUID().toString().replaceAll("-",""));
|
|
||||||
aliPay.setTotalAmount("100");
|
// //-商品的内容可以从系统中传递过来
|
||||||
aliPay.setSubject("笔记本华硕");
|
// aliPay.setTraceNo(UUID.randomUUID().toString().replaceAll("-",""));
|
||||||
|
// aliPay.setTotalAmount("100");
|
||||||
|
// aliPay.setSubject("笔记本华硕");
|
||||||
|
|
||||||
|
|
||||||
request.setBizContent("{\"out_trade_no\":\"" + aliPay.getTraceNo() + "\","
|
request.setBizContent("{\"out_trade_no\":\"" + aliPay.getTraceNo() + "\","
|
||||||
+ "\"total_amount\":\"" + aliPay.getTotalAmount() + "\","
|
+ "\"total_amount\":\"" + aliPay.getTotalAmount() + "\","
|
||||||
|
@ -59,6 +68,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,12 +81,13 @@ 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");
|
||||||
// (不需要)支付宝验签
|
|
||||||
//if (Factory.Payment.Common().verifyNotify(params)) {
|
|
||||||
|
// 支付宝验签
|
||||||
|
if (Factory.Payment.Common().verifyNotify(params)) {
|
||||||
// 验签通过
|
// 验签通过
|
||||||
System.out.println("交易名称: " + params.get("subject"));
|
System.out.println("交易名称: " + params.get("subject"));
|
||||||
System.out.println("交易状态: " + params.get("trade_status"));
|
System.out.println("交易状态: " + params.get("trade_status"));
|
||||||
|
@ -87,10 +98,9 @@ public class AliPayController {
|
||||||
System.out.println("买家付款时间: " + params.get("gmt_payment"));
|
System.out.println("买家付款时间: " + params.get("gmt_payment"));
|
||||||
System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
|
System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
|
||||||
|
|
||||||
// 更新订单未已支付
|
// 更新订单已支付的逻辑代码
|
||||||
// ordersMapper.updateState(tradeNo, "已支付", gmtPayment, alipayTradeNo);
|
}
|
||||||
//}
|
}
|
||||||
|
return "success";
|
||||||
}
|
}
|
||||||
return "success";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class MyapiController {
|
||||||
return Result.success(null,"操作成功");
|
return Result.success(null,"操作成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
* @param myapiId
|
* @param myapiId
|
||||||
|
@ -86,6 +87,9 @@ public class MyapiController {
|
||||||
myapiService.removeById(myapiId);
|
myapiService.removeById(myapiId);
|
||||||
return Result.success(null,"操作成功");
|
return Result.success(null,"操作成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回显接口
|
* 回显接口
|
||||||
* @param myapiId
|
* @param myapiId
|
||||||
|
|
|
@ -25,6 +25,6 @@ public class PartyController {
|
||||||
|
|
||||||
//测试
|
//测试
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SelectPhoneUtil.queryMobileLocation("18790307917");
|
SelectPhoneUtil.queryMobileLocation("15066755856");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue