|
@@ -2,10 +2,10 @@ package org.springblade.pay.tonglianPayment.utils;
|
|
|
|
|
|
|
|
import org.springblade.pay.tonglianPayment.dto.PaymentDTO;
|
|
import org.springblade.pay.tonglianPayment.dto.PaymentDTO;
|
|
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
import java.util.TreeMap;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public class SybPayService {
|
|
public class SybPayService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -52,8 +52,9 @@ public class SybPayService {
|
|
|
/*}*/
|
|
/*}*/
|
|
|
HttpConnectionUtil http = new HttpConnectionUtil(url + "/pay");
|
|
HttpConnectionUtil http = new HttpConnectionUtil(url + "/pay");
|
|
|
http.init();
|
|
http.init();
|
|
|
- if (!SybUtil.isEmpty(orgid))
|
|
|
|
|
|
|
+ if (!SybUtil.isEmpty(orgid)) {
|
|
|
params.put("orgid", orgid);
|
|
params.put("orgid", orgid);
|
|
|
|
|
+ }
|
|
|
params.put("version", "11");
|
|
params.put("version", "11");
|
|
|
params.put("trxamt", String.valueOf(trxamt));
|
|
params.put("trxamt", String.valueOf(trxamt));
|
|
|
params.put("reqsn", reqsn);
|
|
params.put("reqsn", reqsn);
|
|
@@ -90,17 +91,19 @@ public class SybPayService {
|
|
|
} else {*/
|
|
} else {*/
|
|
|
params.put("signtype", transactionType);
|
|
params.put("signtype", transactionType);
|
|
|
String appkey = "";
|
|
String appkey = "";
|
|
|
- if (transactionType.equals("RSA"))
|
|
|
|
|
|
|
+ if (transactionType.equals("RSA")) {
|
|
|
//appkey = SybConstants.SYB_RSACUSPRIKEY;
|
|
//appkey = SybConstants.SYB_RSACUSPRIKEY;
|
|
|
appkey = sybRsacusprikey;
|
|
appkey = sybRsacusprikey;
|
|
|
- else if (transactionType.equals("SM2"))
|
|
|
|
|
|
|
+ } else if (transactionType.equals("SM2")) {
|
|
|
//appkey = SybConstants.SYB_SM2PPRIVATEKEY;
|
|
//appkey = SybConstants.SYB_SM2PPRIVATEKEY;
|
|
|
appkey = sybSmpprivatekey;
|
|
appkey = sybSmpprivatekey;
|
|
|
- else
|
|
|
|
|
|
|
+ } else {
|
|
|
//appkey = SybConstants.SYB_MD5_APPKEY;
|
|
//appkey = SybConstants.SYB_MD5_APPKEY;
|
|
|
appkey = sybMdAppkey;
|
|
appkey = sybMdAppkey;
|
|
|
|
|
+ }
|
|
|
params.put("sign", SybUtil.unionSign(params, appkey, transactionType));
|
|
params.put("sign", SybUtil.unionSign(params, appkey, transactionType));
|
|
|
// }
|
|
// }
|
|
|
|
|
+
|
|
|
System.out.println("请求数据===" + params);
|
|
System.out.println("请求数据===" + params);
|
|
|
byte[] bys = http.postParams(params, true);
|
|
byte[] bys = http.postParams(params, true);
|
|
|
System.out.println("第二步===" + bys);
|
|
System.out.println("第二步===" + bys);
|
|
@@ -109,23 +112,17 @@ public class SybPayService {
|
|
|
Map<String, String> map = handleResult(result, transactionType, sybRsacusprikey, sybSmpprivatekey, sybMdAppkey);
|
|
Map<String, String> map = handleResult(result, transactionType, sybRsacusprikey, sybSmpprivatekey, sybMdAppkey);
|
|
|
System.out.println("第四步===" + map);
|
|
System.out.println("第四步===" + map);
|
|
|
return map;
|
|
return map;
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Map<String, String> cancel(long trxamt, String reqsn, String oldtrxid, String oldreqsn) throws Exception {
|
|
public Map<String, String> cancel(long trxamt, String reqsn, String oldtrxid, String oldreqsn) throws Exception {
|
|
|
TreeMap<String, String> params = new TreeMap<String, String>();
|
|
TreeMap<String, String> params = new TreeMap<String, String>();
|
|
|
- if (!SybUtil.isEmpty(SybConstants.SYB_ORGID))
|
|
|
|
|
|
|
+ if (!SybUtil.isEmpty(SybConstants.SYB_ORGID)) {
|
|
|
params.put("orgid", SybConstants.SYB_ORGID);
|
|
params.put("orgid", SybConstants.SYB_ORGID);
|
|
|
|
|
+ }
|
|
|
String url = "";
|
|
String url = "";
|
|
|
- /*if (ParamCache.getValue(PAYMENT_PARAMETER).equals("0")) {
|
|
|
|
|
- params.put("cusid", SybConstants.SYB_CUSID_TEST);
|
|
|
|
|
- params.put("appid", SybConstants.SYB_APPID_TEST);
|
|
|
|
|
- url = SybConstants.SYB_APIURL_TEST;
|
|
|
|
|
- } else {*/
|
|
|
|
|
params.put("cusid", SybConstants.SYB_CUSID);
|
|
params.put("cusid", SybConstants.SYB_CUSID);
|
|
|
params.put("appid", SybConstants.SYB_APPID);
|
|
params.put("appid", SybConstants.SYB_APPID);
|
|
|
url = SybConstants.SYB_APIURL;
|
|
url = SybConstants.SYB_APIURL;
|
|
|
-// }
|
|
|
|
|
HttpConnectionUtil http = new HttpConnectionUtil(url + "/cancel");
|
|
HttpConnectionUtil http = new HttpConnectionUtil(url + "/cancel");
|
|
|
http.init();
|
|
http.init();
|
|
|
params.put("version", "11");
|
|
params.put("version", "11");
|
|
@@ -134,25 +131,15 @@ public class SybPayService {
|
|
|
params.put("oldtrxid", oldtrxid);
|
|
params.put("oldtrxid", oldtrxid);
|
|
|
params.put("oldreqsn", oldreqsn);
|
|
params.put("oldreqsn", oldreqsn);
|
|
|
params.put("randomstr", SybUtil.getValidatecode(8));
|
|
params.put("randomstr", SybUtil.getValidatecode(8));
|
|
|
- /*if (ParamCache.getValue(PAYMENT_PARAMETER).equals("0")) {
|
|
|
|
|
- params.put("signtype", SybConstants.SIGN_TYPE_TEST);
|
|
|
|
|
- String appkey = "";
|
|
|
|
|
- if (SybConstants.SIGN_TYPE_TEST.equals("RSA"))
|
|
|
|
|
- appkey = SybConstants.SYB_RSACUSPRIKEY_TEST;
|
|
|
|
|
- else if (SybConstants.SIGN_TYPE_TEST.equals("SM2"))
|
|
|
|
|
- appkey = SybConstants.SYB_SM2PPRIVATEKEY_TEST;
|
|
|
|
|
- else
|
|
|
|
|
- appkey = SybConstants.SYB_MD5_APPKEY_TEST;
|
|
|
|
|
- params.put("sign", SybUtil.unionSign(params, appkey, SybConstants.SIGN_TYPE_TEST));
|
|
|
|
|
- } else {*/
|
|
|
|
|
params.put("signtype", SybConstants.SIGN_TYPE);
|
|
params.put("signtype", SybConstants.SIGN_TYPE);
|
|
|
String appkey = "";
|
|
String appkey = "";
|
|
|
- if (SybConstants.SIGN_TYPE.equals("RSA"))
|
|
|
|
|
|
|
+ if (SybConstants.SIGN_TYPE.equals("RSA")) {
|
|
|
appkey = SybConstants.SYB_RSACUSPRIKEY;
|
|
appkey = SybConstants.SYB_RSACUSPRIKEY;
|
|
|
- else if (SybConstants.SIGN_TYPE.equals("SM2"))
|
|
|
|
|
|
|
+ }else if (SybConstants.SIGN_TYPE.equals("SM2")) {
|
|
|
appkey = SybConstants.SYB_SM2PPRIVATEKEY;
|
|
appkey = SybConstants.SYB_SM2PPRIVATEKEY;
|
|
|
- else
|
|
|
|
|
|
|
+ }else {
|
|
|
appkey = SybConstants.SYB_MD5_APPKEY;
|
|
appkey = SybConstants.SYB_MD5_APPKEY;
|
|
|
|
|
+ }
|
|
|
params.put("sign", SybUtil.unionSign(params, appkey, SybConstants.SIGN_TYPE));
|
|
params.put("sign", SybUtil.unionSign(params, appkey, SybConstants.SIGN_TYPE));
|
|
|
// }
|
|
// }
|
|
|
byte[] bys = http.postParams(params, true);
|
|
byte[] bys = http.postParams(params, true);
|
|
@@ -164,8 +151,9 @@ public class SybPayService {
|
|
|
public Map<String, String> refund(long trxamt, String reqsn, String oldtrxid, String oldreqsn, String cusId, String appId, String orgid, String transactionType, String sybMdAppkey,
|
|
public Map<String, String> refund(long trxamt, String reqsn, String oldtrxid, String oldreqsn, String cusId, String appId, String orgid, String transactionType, String sybMdAppkey,
|
|
|
String sybRsacusprikey, String sybRsatlpubkey, String sybSmpprivatekey, String sybSmtlpubkey) throws Exception {
|
|
String sybRsacusprikey, String sybRsatlpubkey, String sybSmpprivatekey, String sybSmtlpubkey) throws Exception {
|
|
|
TreeMap<String, String> params = new TreeMap<String, String>();
|
|
TreeMap<String, String> params = new TreeMap<String, String>();
|
|
|
- if (!SybUtil.isEmpty(orgid))
|
|
|
|
|
|
|
+ if (!SybUtil.isEmpty(orgid)) {
|
|
|
params.put("orgid", orgid);
|
|
params.put("orgid", orgid);
|
|
|
|
|
+ }
|
|
|
String url = "";
|
|
String url = "";
|
|
|
params.put("cusid", cusId);
|
|
params.put("cusid", cusId);
|
|
|
params.put("appid", appId);
|
|
params.put("appid", appId);
|
|
@@ -188,45 +176,29 @@ public class SybPayService {
|
|
|
|
|
|
|
|
public Map<String, String> query(String reqsn, String trxid) throws Exception {
|
|
public Map<String, String> query(String reqsn, String trxid) throws Exception {
|
|
|
TreeMap<String, String> params = new TreeMap<String, String>();
|
|
TreeMap<String, String> params = new TreeMap<String, String>();
|
|
|
- if (!SybUtil.isEmpty(SybConstants.SYB_ORGID))
|
|
|
|
|
|
|
+ if (!SybUtil.isEmpty(SybConstants.SYB_ORGID)) {
|
|
|
params.put("orgid", SybConstants.SYB_ORGID);
|
|
params.put("orgid", SybConstants.SYB_ORGID);
|
|
|
|
|
+ }
|
|
|
String url = "";
|
|
String url = "";
|
|
|
- /*if (ParamCache.getValue(PAYMENT_PARAMETER).equals("0")) {
|
|
|
|
|
- params.put("cusid", SybConstants.SYB_CUSID_TEST);
|
|
|
|
|
- params.put("appid", SybConstants.SYB_APPID_TEST);
|
|
|
|
|
- url = SybConstants.SYB_APIURL_TEST;
|
|
|
|
|
- } else {*/
|
|
|
|
|
params.put("cusid", SybConstants.SYB_CUSID);
|
|
params.put("cusid", SybConstants.SYB_CUSID);
|
|
|
params.put("appid", SybConstants.SYB_APPID);
|
|
params.put("appid", SybConstants.SYB_APPID);
|
|
|
url = SybConstants.SYB_APIURL;
|
|
url = SybConstants.SYB_APIURL;
|
|
|
-// }
|
|
|
|
|
HttpConnectionUtil http = new HttpConnectionUtil(url + "/query");
|
|
HttpConnectionUtil http = new HttpConnectionUtil(url + "/query");
|
|
|
http.init();
|
|
http.init();
|
|
|
params.put("version", "11");
|
|
params.put("version", "11");
|
|
|
params.put("reqsn", reqsn);
|
|
params.put("reqsn", reqsn);
|
|
|
params.put("trxid", trxid);
|
|
params.put("trxid", trxid);
|
|
|
params.put("randomstr", SybUtil.getValidatecode(8));
|
|
params.put("randomstr", SybUtil.getValidatecode(8));
|
|
|
- /*if (ParamCache.getValue(PAYMENT_PARAMETER).equals("0")) {
|
|
|
|
|
- params.put("signtype", SybConstants.SIGN_TYPE_TEST);
|
|
|
|
|
- String appkey = "";
|
|
|
|
|
- if (SybConstants.SIGN_TYPE_TEST.equals("RSA"))
|
|
|
|
|
- appkey = SybConstants.SYB_RSACUSPRIKEY_TEST;
|
|
|
|
|
- else if (SybConstants.SIGN_TYPE_TEST.equals("SM2"))
|
|
|
|
|
- appkey = SybConstants.SYB_SM2PPRIVATEKEY_TEST;
|
|
|
|
|
- else
|
|
|
|
|
- appkey = SybConstants.SYB_MD5_APPKEY_TEST;
|
|
|
|
|
- params.put("sign", SybUtil.unionSign(params, appkey, SybConstants.SIGN_TYPE_TEST));
|
|
|
|
|
- } else {*/
|
|
|
|
|
params.put("signtype", SybConstants.SIGN_TYPE);
|
|
params.put("signtype", SybConstants.SIGN_TYPE);
|
|
|
String appkey = "";
|
|
String appkey = "";
|
|
|
- if (SybConstants.SIGN_TYPE.equals("RSA"))
|
|
|
|
|
|
|
+ if (SybConstants.SIGN_TYPE.equals("RSA")) {
|
|
|
appkey = SybConstants.SYB_RSACUSPRIKEY;
|
|
appkey = SybConstants.SYB_RSACUSPRIKEY;
|
|
|
- else if (SybConstants.SIGN_TYPE.equals("SM2"))
|
|
|
|
|
|
|
+ }else if (SybConstants.SIGN_TYPE.equals("SM2")) {
|
|
|
appkey = SybConstants.SYB_SM2PPRIVATEKEY;
|
|
appkey = SybConstants.SYB_SM2PPRIVATEKEY;
|
|
|
- else
|
|
|
|
|
|
|
+ }else {
|
|
|
appkey = SybConstants.SYB_MD5_APPKEY;
|
|
appkey = SybConstants.SYB_MD5_APPKEY;
|
|
|
|
|
+ }
|
|
|
params.put("sign", SybUtil.unionSign(params, appkey, SybConstants.SIGN_TYPE));
|
|
params.put("sign", SybUtil.unionSign(params, appkey, SybConstants.SIGN_TYPE));
|
|
|
-// }
|
|
|
|
|
byte[] bys = http.postParams(params, true);
|
|
byte[] bys = http.postParams(params, true);
|
|
|
String result = new String(bys, "UTF-8");
|
|
String result = new String(bys, "UTF-8");
|
|
|
Map<String, String> map = handleResult(result, SybConstants.SIGN_TYPE, SybConstants.SYB_RSACUSPRIKEY, SybConstants.SYB_SM2PPRIVATEKEY, SybConstants.SYB_MD5_APPKEY);
|
|
Map<String, String> map = handleResult(result, SybConstants.SIGN_TYPE, SybConstants.SYB_RSACUSPRIKEY, SybConstants.SYB_SM2PPRIVATEKEY, SybConstants.SYB_MD5_APPKEY);
|
|
@@ -245,12 +217,13 @@ public class SybPayService {
|
|
|
TreeMap tmap = new TreeMap();
|
|
TreeMap tmap = new TreeMap();
|
|
|
tmap.putAll(map);
|
|
tmap.putAll(map);
|
|
|
String appkey = "";
|
|
String appkey = "";
|
|
|
- if (transactionType.equals("RSA"))
|
|
|
|
|
|
|
+ if (transactionType.equals("RSA")) {
|
|
|
appkey = sybRsacusprikey;
|
|
appkey = sybRsacusprikey;
|
|
|
- else if (transactionType.equals("SM2"))
|
|
|
|
|
|
|
+ }else if (transactionType.equals("SM2")) {
|
|
|
appkey = sybSmpprivatekey;
|
|
appkey = sybSmpprivatekey;
|
|
|
- else
|
|
|
|
|
|
|
+ }else {
|
|
|
appkey = sybMdAppkey;
|
|
appkey = sybMdAppkey;
|
|
|
|
|
+ }
|
|
|
if (SybUtil.validSign(tmap, appkey, transactionType)) {
|
|
if (SybUtil.validSign(tmap, appkey, transactionType)) {
|
|
|
System.out.println("签名成功");
|
|
System.out.println("签名成功");
|
|
|
return map;
|
|
return map;
|
|
@@ -303,7 +276,7 @@ public class SybPayService {
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Map<String, String> scanNew (PaymentDTO paymentDTO) throws Exception {
|
|
|
|
|
|
|
+ public Map<String, String> scanNew(PaymentDTO paymentDTO) throws Exception {
|
|
|
|
|
|
|
|
TreeMap<String, String> params = new TreeMap<String, String>();
|
|
TreeMap<String, String> params = new TreeMap<String, String>();
|
|
|
if (!SybUtil.isEmpty(paymentDTO.getOrgid())) {
|
|
if (!SybUtil.isEmpty(paymentDTO.getOrgid())) {
|