|
|
@@ -48,28 +48,41 @@ public class AlipayController {
|
|
|
this.tradeService = tradeService;
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/testPay")
|
|
|
- public Response testPay(@RequestBody PayModelDTO payModelDTO){
|
|
|
- System.out.println("testPay开始");
|
|
|
- return new SuccessResponse();
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 支付
|
|
|
+ * @param payModelDTO 支付参数模型DTO
|
|
|
+ * @return 支付界面
|
|
|
+ * @throws AlipayApiException 支付宝异常
|
|
|
+ * @throws IOException IO异常
|
|
|
+ */
|
|
|
@PostMapping("/pay")
|
|
|
public Response pay(@RequestBody PayModelDTO payModelDTO) throws AlipayApiException, IOException {
|
|
|
- Order order=orderService.createOrder(payModelDTO.getUserId(),payModelDTO.getProductId(),payModelDTO.getPlatformType(),payModelDTO.getPrice());
|
|
|
+ Order order=orderService.createOrder(
|
|
|
+ payModelDTO.getUserId(),
|
|
|
+ payModelDTO.getProductId(),
|
|
|
+ payModelDTO.getPlatformType(),
|
|
|
+ payModelDTO.getPrice());
|
|
|
if (order==null)
|
|
|
return new ErrorResponse(500,"存在重复订单,订单创建失败");
|
|
|
- // 订单模型
|
|
|
+ // 销售产品码,电脑支付场景仅支持这个
|
|
|
String productCode = "FAST_INSTANT_TRADE_PAY";
|
|
|
+ // 必传参数
|
|
|
AlipayTradePagePayModel model = new AlipayTradePagePayModel();
|
|
|
+ // 商户订单号,商家自定义,保持唯一性
|
|
|
model.setOutTradeNo(order.getOutTradeNo().toString());
|
|
|
+ // 订单标题,不可以使用特殊符号
|
|
|
model.setSubject(payModelDTO.getSubject());
|
|
|
+ // 支付金额,最小值0.01元
|
|
|
model.setTotalAmount(String.valueOf(order.getPrice()));
|
|
|
+ // 商品描述
|
|
|
model.setBody(payModelDTO.getSubject()+", 共"+payModelDTO.getPrice()+"元");
|
|
|
+ // 销售产品码
|
|
|
model.setProductCode(productCode);
|
|
|
|
|
|
AlipayTradePagePayRequest pagePayRequest =new AlipayTradePagePayRequest();
|
|
|
+ // 交易成功后,返回的页面
|
|
|
pagePayRequest.setReturnUrl(payModelDTO.getReturnUrl());
|
|
|
+ // 交易成功后,异步调用的URL
|
|
|
pagePayRequest.setNotifyUrl(alipayProperties.getNotifyUrl());
|
|
|
pagePayRequest.setBizModel(model);
|
|
|
|
|
|
@@ -86,6 +99,13 @@ public class AlipayController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 支付成功后异步回调
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ * @throws AlipayApiException
|
|
|
+ * @throws UnsupportedEncodingException
|
|
|
+ */
|
|
|
@RequestMapping("/notify")
|
|
|
public String notify(HttpServletRequest request) throws AlipayApiException, UnsupportedEncodingException {
|
|
|
System.out.println("notify开始");
|
|
|
@@ -94,8 +114,9 @@ public class AlipayController {
|
|
|
StringBuilder notifyBuild = new StringBuilder("/****************************** alipay notify ******************************/\n");
|
|
|
parameterMap.forEach((key, value) -> notifyBuild.append(key + "=" + value[0] + "\n") );
|
|
|
log.info(notifyBuild.toString());
|
|
|
-
|
|
|
+ // 1. 校验签名,确保当前支付通知是由支付宝发送的
|
|
|
boolean flag = alipayService.verifySign(request);
|
|
|
+ // 2. 二次校验,校验支付结果中的业务内容是否与对应订单相同
|
|
|
if (flag) {
|
|
|
/**
|
|
|
* 需要严格按照如下描述校验通知数据的正确性
|