|
@@ -1,18 +1,17 @@
|
|
|
package com.ym.mec.thirdparty.adapay;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.huifu.adapay.AdaPay;
|
|
|
import com.huifu.adapay.demo.BaseDemo;
|
|
|
import com.huifu.adapay.demo.NotifyCallbackDemo;
|
|
|
import com.huifu.adapay.exception.BaseAdaPayException;
|
|
|
import com.huifu.adapay.model.DeviceInfo;
|
|
|
import com.huifu.adapay.model.payment.*;
|
|
|
+import com.huifu.adapay.util.AdaPaySign;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author jane.zhao
|
|
@@ -25,7 +24,7 @@ public class Pay {
|
|
|
* @return paymentId
|
|
|
* @throws Exception 异常
|
|
|
*/
|
|
|
- public static void init() throws Exception {
|
|
|
+ public Pay() throws Exception {
|
|
|
//apiKey,商户联调用
|
|
|
String apiKey = "api_test_e640fa26-bbe6-458f-ac44-a71723ee2176";
|
|
|
//apiKey,真实交易用(live)
|
|
@@ -55,7 +54,7 @@ public class Pay {
|
|
|
BigDecimal amount = new BigDecimal("0.01");
|
|
|
String orderSubject = "测试大雅订单";
|
|
|
String orderBody = "测试大雅订单";
|
|
|
- Payment payment = Pay.executePayment(amount,orderNo,payChannel,orderSubject,orderBody);
|
|
|
+ Payment payment = demo.executePayment(amount,orderNo,payChannel,orderSubject,orderBody);
|
|
|
//支付查询接口
|
|
|
//demo.queryPayment(payment.getId());
|
|
|
//关单接口
|
|
@@ -64,13 +63,42 @@ public class Pay {
|
|
|
return payment.getId();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String orderSubject, String orderBody) throws Exception {
|
|
|
+
|
|
|
+ Map<String, Object> paymentParams = new HashMap<>(10);
|
|
|
+ paymentParams.put("appId",appId);
|
|
|
+ paymentParams.put("amount", amount);
|
|
|
+ paymentParams.put("orderNo", orderNo);
|
|
|
+ paymentParams.put("notifyUrl", notifyUrl);
|
|
|
+ paymentParams.put("orderSubject", orderSubject);
|
|
|
+ paymentParams.put("orderBody", orderBody);
|
|
|
+ String originalStr = JSONObject.toJSONString(paymentParams);
|
|
|
+
|
|
|
+ String sign = AdaPaySign.sign(originalStr, AdaPay.privateKey);
|
|
|
+ paymentParams.put("sign",sign);
|
|
|
+ paymentParams.remove(appId);
|
|
|
+ return paymentParams;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean verifySign(BigDecimal amount, String orderNo, String notifyUrl, String orderSubject, String orderBody, String sign) throws Exception {
|
|
|
+ Map<String, Object> paymentParams = new HashMap<>(10);
|
|
|
+ paymentParams.put("appId",appId);
|
|
|
+ paymentParams.put("amount", amount);
|
|
|
+ paymentParams.put("orderNo", orderNo);
|
|
|
+ paymentParams.put("notifyUrl", notifyUrl);
|
|
|
+ paymentParams.put("orderSubject", orderSubject);
|
|
|
+ paymentParams.put("orderBody", orderBody);
|
|
|
+ String originalStr = JSONObject.toJSONString(paymentParams);
|
|
|
+ return AdaPaySign.verifySign(originalStr,sign, AdaPay.pubKey);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 执行一个支付交易
|
|
|
* @return 创建的支付对象
|
|
|
* @throws Exception 异常
|
|
|
*/
|
|
|
public static Payment executePayment(BigDecimal amount,String orderNo,String payChannel,String orderSubject,String orderBody) throws Exception {
|
|
|
- init();
|
|
|
System.out.println("=======execute payment begin=======");
|
|
|
//创建支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/04-trade.html#id3
|
|
|
Map<String, Object> paymentParams = new HashMap<>(10);
|