|
|
@@ -1,9 +1,10 @@
|
|
|
package com.seecoder.BlueWhale.configure;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alipay.api.*;
|
|
|
+import com.alipay.api.AlipayClient;
|
|
|
+import com.alipay.api.DefaultAlipayClient;
|
|
|
import com.alipay.api.request.AlipayTradePagePayRequest;
|
|
|
-
|
|
|
+import com.seecoder.BlueWhale.exception.BlueWhaleException;
|
|
|
import lombok.Getter;
|
|
|
import lombok.Setter;
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
@@ -34,24 +35,26 @@ public class AlipayTools {
|
|
|
|
|
|
private static String signType="RSA2";
|
|
|
|
|
|
- public void pay(String name , Double price, HttpServletResponse httpResponse){
|
|
|
+ /**
|
|
|
+ * @Author: DingXiaoyu
|
|
|
+ * @Date: 16:02 2024/1/27
|
|
|
+ * 用来测试支付宝沙箱
|
|
|
+ */
|
|
|
+ public void testPay(String name , Double price, HttpServletResponse httpResponse){
|
|
|
AlipayClient alipayClient = new DefaultAlipayClient(serverUrl,appId,appPrivateKey,format,charset,alipayPublicKey,signType);
|
|
|
-
|
|
|
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
|
|
|
-
|
|
|
request.setNotifyUrl(notifyUrl);
|
|
|
-
|
|
|
String replace = UUID.randomUUID().toString().replace("-", "");
|
|
|
JSONObject bizContent = new JSONObject();
|
|
|
- bizContent.put("out_trade_no", replace); //订单编号
|
|
|
+ bizContent.put("out_trade_no", replace);
|
|
|
bizContent.put("total_amount", price);
|
|
|
bizContent.put("subject", name);
|
|
|
bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
|
|
|
request.setBizContent(bizContent.toString());
|
|
|
-
|
|
|
- String form= "" ;
|
|
|
+ String form;
|
|
|
try {
|
|
|
form = alipayClient.pageExecute(request).getBody();
|
|
|
+ System.out.println(form);
|
|
|
httpResponse.setContentType("text/html;charset=" + charset);
|
|
|
httpResponse.getWriter().write(form);
|
|
|
httpResponse.getWriter().flush();
|
|
|
@@ -60,4 +63,46 @@ public class AlipayTools {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// public String pay(String tradeName, String name , Double price){
|
|
|
+// AlipayClient alipayClient = new DefaultAlipayClient(serverUrl,appId,appPrivateKey,format,charset,alipayPublicKey,signType);
|
|
|
+// AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
|
|
|
+// request.setNotifyUrl(notifyUrl);
|
|
|
+// JSONObject bizContent = new JSONObject();
|
|
|
+// bizContent.put("out_trade_no", tradeName); //订单id-优惠券id
|
|
|
+// bizContent.put("total_amount", price);
|
|
|
+// bizContent.put("subject", name);
|
|
|
+// bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
|
|
|
+// request.setBizContent(bizContent.toString());
|
|
|
+// String form;
|
|
|
+// try {
|
|
|
+// form = alipayClient.pageExecute(request).getBody();
|
|
|
+// System.out.println(form);
|
|
|
+// } catch (Exception e) {
|
|
|
+// throw BlueWhaleException.payError();
|
|
|
+// }
|
|
|
+// return form;
|
|
|
+// }
|
|
|
+
|
|
|
+ public void pay(String tradeName, String name , Double price, HttpServletResponse httpResponse){
|
|
|
+ AlipayClient alipayClient = new DefaultAlipayClient(serverUrl,appId,appPrivateKey,format,charset,alipayPublicKey,signType);
|
|
|
+ AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
|
|
|
+ request.setNotifyUrl(notifyUrl);
|
|
|
+ JSONObject bizContent = new JSONObject();
|
|
|
+ bizContent.put("out_trade_no", tradeName); //订单id-优惠券id
|
|
|
+ bizContent.put("total_amount", price);
|
|
|
+ bizContent.put("subject", name);
|
|
|
+ bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
|
|
|
+ request.setBizContent(bizContent.toString());
|
|
|
+ String form;
|
|
|
+ try {
|
|
|
+ form = alipayClient.pageExecute(request).getBody();
|
|
|
+ httpResponse.setContentType("text/html;charset=" + charset);
|
|
|
+ httpResponse.getWriter().write(form);
|
|
|
+ httpResponse.getWriter().flush();
|
|
|
+ httpResponse.getWriter().close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw BlueWhaleException.payError();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|