增加预订单回调处理,用于扩展信息

This commit is contained in:
egzosn
2019-10-08 22:05:53 +08:00
parent fdf5df5d5f
commit ad7efdce9d
9 changed files with 34 additions and 14 deletions

View File

@@ -153,7 +153,7 @@ public class AliPayService extends BasePayService<AliPayConfigStorage> {
@Override
public Map<String, Object> orderInfo(PayOrder order) {
Map<String, Object> orderInfo = getOrder(order);
Map<String, Object> orderInfo = getOrder(order);
String sign = null;
if (AliTransactionType.APP == order.getTransactionType() ){
@@ -233,7 +233,7 @@ public class AliPayService extends BasePayService<AliPayConfigStorage> {
// 支付宝处理完请求后,当前页面跳转到商户指定页面的路径,可空
orderInfo.put("return_url", payConfigStorage.getReturnUrl());
return orderInfo;
return preOrderHandler(orderInfo, order);
}

View File

@@ -454,4 +454,17 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
public PayMessage createMessage(Map<String, Object> message) {
return new PayMessage(message);
}
/**
* 预订单回调处理器,用于订单信息的扩展
* 签名之前使用
* 如果需要进行扩展请重写该方法即可
* @param orderInfo 预订单信息
* @param orderInfo 订单信息
* @return 处理后订单信息
*/
public Map<String, Object> preOrderHandler(Map<String, Object> orderInfo, PayOrder payOrder){
return orderInfo;
}
}

View File

@@ -62,6 +62,7 @@ public class FuiouPayService extends BasePayService<FuiouPayConfigStorage> {
* 获取对应的请求地址
* @return 请求地址
*/
@Override
public String getReqUrl(TransactionType transactionType){
return payConfigStorage.isTest() ? DEV_URL_FUIOU_BASE_DOMAIN : URL_FUIOU_BASE_DOMAIN;
}
@@ -152,7 +153,7 @@ public class FuiouPayService extends BasePayService<FuiouPayConfigStorage> {
*/
@Override
public Map<String, Object> orderInfo(PayOrder order) {
LinkedHashMap<String, Object> parameters = getOrderInfo(order);
Map<String, Object> parameters = getOrderInfo(order);
String sign = createSign(SignUtils.parameters2MD5Str(parameters, "|"), payConfigStorage.getInputCharset());
parameters.put("md5", sign);
return parameters;
@@ -163,7 +164,7 @@ public class FuiouPayService extends BasePayService<FuiouPayConfigStorage> {
* @param order 支付订单
* @return 返回支付请求参数集合
*/
private LinkedHashMap<String, Object> getOrderInfo(PayOrder order) {
private Map<String, Object> getOrderInfo(PayOrder order) {
LinkedHashMap<String, Object> parameters = new LinkedHashMap<String, Object>();
//商户代码
parameters.put("mchnt_cd", payConfigStorage.getPid());
@@ -195,7 +196,7 @@ public class FuiouPayService extends BasePayService<FuiouPayConfigStorage> {
parameters.put("rem", "");
//版本号
parameters.put("ver", "1.0.1");
return parameters;
return preOrderHandler(parameters, order);
}
/**

View File

@@ -185,7 +185,7 @@ public class PayoneerPayService extends BasePayService<PayoneerConfigStorage> im
params.put("currency", order.getCurType());
params.put("description", order.getSubject());
return params;
return preOrderHandler(params, order);
}
/**

View File

@@ -44,6 +44,7 @@ public class PayPalPayService extends BasePayService<PayPalConfigStorage>{
* 获取对应的请求地址
* @return 请求地址
*/
@Override
public String getReqUrl(TransactionType transactionType){
return (payConfigStorage.isTest() ? SANDBOX_REQ_URL : REQ_URL) + transactionType.getMethod();
}
@@ -182,7 +183,7 @@ public class PayPalPayService extends BasePayService<PayPalConfigStorage>{
if ("created".equals(resp.getString("state")) && StringUtils.isNotEmpty(resp.getString("id"))){
order.setOutTradeNo(resp.getString("id"));
}
return resp;
return preOrderHandler(resp, order);
}
@Override

View File

@@ -288,7 +288,7 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
params.put(SDKConstants.param_payTimeout, getPayTimeout(order.getExpirationTime()));
params.put("orderDesc", order.getSubject());
}
params = preOrderHandler(params, order);
return setSign(params);
}

View File

@@ -224,9 +224,10 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
*/
@Override
public JSONObject orderInfo(PayOrder order) {
TreeMap<String, String> data = new TreeMap<>();
Map<String, Object> data = new TreeMap<>();
data.put("access_token", getAccessToken());
data.put("paymoney", Util.conversionAmount(order.getPrice()).toString());
data = preOrderHandler(data, order);
String apbNonce = SignUtils.randomStr();
String sign = createSign(SignUtils.parameterText(data, "") + apbNonce, payConfigStorage.getInputCharset());
data.put("PayMoney", data.remove("paymoney"));
@@ -460,6 +461,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
* @param type 交易类型
* @return 请求地址
*/
@Override
public String getReqUrl(TransactionType type){
return URL + type.getMethod();

View File

@@ -101,6 +101,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
* @param transactionType 交易类型
* @return 请求url
*/
@Override
public String getReqUrl(TransactionType transactionType) {
return URI + (payConfigStorage.isTest() ? SANDBOXNEW : "") + transactionType.getMethod();
@@ -221,13 +222,14 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
parameters.put("time_expire", DateUtils.formatDate(order.getExpirationTime(), DateUtils.YYYYMMDDHHMMSS));
}
((WxTransactionType) order.getTransactionType()).setAttribute(parameters, order);
parameters = preOrderHandler(parameters, order);
setSign(parameters);
String requestXML = XML.getMap2Xml(parameters);
if (LOG.isDebugEnabled()) {
LOG.debug("requestXML:" + requestXML);
}
//调起支付的参数列表
JSONObject result = requestTemplate.postForObject(getReqUrl(order.getTransactionType()), requestXML, JSONObject.class);
@@ -250,15 +252,14 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
////统一下单
JSONObject result = unifiedOrder(order);
// 对微信返回的数据进行校验
if (verify(result)) {
if (verify(preOrderHandler(result, order))) {
//如果是扫码支付或者刷卡付无需处理,直接返回
if (((WxTransactionType) order.getTransactionType()).isReturn()) {
return result;
}
SortedMap<String, Object> params = new TreeMap<String, Object>();
Map<String, Object> params = new TreeMap<String, Object>();
if (WxTransactionType.JSAPI == order.getTransactionType()) {
params.put("signType", payConfigStorage.getSignType());
@@ -274,6 +275,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
params.put("noncestr", result.get(NONCE_STR));
params.put("package", "Sign=WXPay");
}
params = preOrderHandler(params, order);
String paySign = createSign(SignUtils.parameterText(params), payConfigStorage.getInputCharset());
params.put(SIGN, paySign);
return params;

View File

@@ -53,6 +53,7 @@ public class YiJiPayService extends BasePayService<YiJiPayConfigStorage> {
*
* @return 请求地址
*/
@Override
public String getReqUrl(TransactionType transactionType) {
if (payConfigStorage.isTest()){
return DEV_REQ_URL;
@@ -175,7 +176,7 @@ public class YiJiPayService extends BasePayService<YiJiPayConfigStorage> {
orderInfo.put("currency", order.getCurType());
}
return orderInfo;
return preOrderHandler(orderInfo, order);
}
/**