mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-06-03 23:23:13 +08:00
2.13.2-SNAPSHOT开始
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
@@ -22,3 +23,7 @@
|
||||
.idea
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
target/
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
|
||||
28
pay-java-baidu/pom.xml
Normal file
28
pay-java-baidu/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-baidu</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- pay-java -->
|
||||
<dependency>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<artifactId>pay-java-common</artifactId>
|
||||
</dependency>
|
||||
<!-- /pay-java -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.egzosn.pay.baidu.api;
|
||||
|
||||
import com.egzosn.pay.common.api.BasePayConfigStorage;
|
||||
|
||||
public class BaiduPayConfigStorage extends BasePayConfigStorage {
|
||||
private String appid;
|
||||
private String dealId;
|
||||
|
||||
@Override
|
||||
public String getAppid() {
|
||||
return this.appid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPid() {
|
||||
return getDealId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSeller() {
|
||||
throw new UnsupportedOperationException("不支持");
|
||||
}
|
||||
|
||||
public String getDealId() {
|
||||
return dealId;
|
||||
}
|
||||
|
||||
public void setDealId(String dealId) {
|
||||
this.dealId = dealId;
|
||||
}
|
||||
|
||||
public String getAppKey() {
|
||||
return this.getKeyPrivate();
|
||||
}
|
||||
|
||||
public void setAppKey(String appKey) {
|
||||
setKeyPrivate(appKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyPublic() {
|
||||
return super.getKeyPrivate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKeyPublic(String keyPublic) {
|
||||
super.setKeyPublic(keyPublic);
|
||||
}
|
||||
|
||||
public void setAppid(String appid) {
|
||||
this.appid = appid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,491 @@
|
||||
package com.egzosn.pay.baidu.api;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.egzosn.pay.baidu.bean.BaiduPayOrder;
|
||||
import com.egzosn.pay.baidu.bean.BaiduRefundOrder;
|
||||
import com.egzosn.pay.baidu.bean.BaiduTransactionType;
|
||||
import com.egzosn.pay.baidu.bean.type.AuditStatus;
|
||||
import com.egzosn.pay.baidu.util.Asserts;
|
||||
import com.egzosn.pay.common.api.BasePayService;
|
||||
import com.egzosn.pay.common.bean.*;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.http.UriVariables;
|
||||
import com.egzosn.pay.common.util.DateUtils;
|
||||
import com.egzosn.pay.common.util.sign.SignUtils;
|
||||
import com.egzosn.pay.common.util.str.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class BaiduPayService extends BasePayService<BaiduPayConfigStorage, BaiduPayOrder> {
|
||||
public static final String APP_KEY = "appKey";
|
||||
public static final String APP_ID = "appId";
|
||||
public static final String DEAL_ID = "dealId";
|
||||
public static final String TP_ORDER_ID = "tpOrderId";
|
||||
public static final String DEAL_TITLE = "dealTitle";
|
||||
public static final String TOTAL_AMOUNT = "totalAmount";
|
||||
public static final String SIGN_FIELDS_RANGE = "signFieldsRange";
|
||||
public static final String BIZ_INFO = "bizInfo";
|
||||
public static final String RSA_SIGN = "rsaSign";
|
||||
public static final String ORDER_ID = "orderId";
|
||||
public static final String USER_ID = "userId";
|
||||
public static final String SITE_ID = "siteId";
|
||||
public static final String SIGN = "sign";
|
||||
public static final String METHOD = "method";
|
||||
public static final String TYPE = "type";
|
||||
|
||||
public static final Integer RESPONSE_SUCCESS = 2;
|
||||
public static final String RESPONSE_STATUS = "status";
|
||||
|
||||
|
||||
public BaiduPayService(BaiduPayConfigStorage payConfigStorage) {
|
||||
super(payConfigStorage);
|
||||
}
|
||||
|
||||
public BaiduPayService(BaiduPayConfigStorage payConfigStorage,
|
||||
HttpConfigStorage configStorage) {
|
||||
super(payConfigStorage, configStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证响应
|
||||
*
|
||||
* @param params 回调回来的参数集
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean verify(Map<String, Object> params) {
|
||||
if (!RESPONSE_SUCCESS.equals(params.get(RESPONSE_STATUS))) {
|
||||
return false;
|
||||
}
|
||||
return signVerify(params, String.valueOf(params.get(RSA_SIGN))) && verifySource(String.valueOf(params.get(TP_ORDER_ID)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证签名
|
||||
*
|
||||
* @param params 参数集
|
||||
* @param sign 签名原文
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean signVerify(Map<String, Object> params, String sign) {
|
||||
String rsaSign = String.valueOf(params.get(RSA_SIGN));
|
||||
String targetRsaSign = getRsaSign(params, RSA_SIGN);
|
||||
LOG.debug("百度返回的签名: " + rsaSign + " 本地产生的签名: " + targetRsaSign);
|
||||
return StringUtils.equals(rsaSign, targetRsaSign);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifySource(String id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回创建的订单信息
|
||||
*
|
||||
* @param order 支付订单
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> orderInfo(BaiduPayOrder order) {
|
||||
Map<String, Object> params = getUseOrderInfoParams(order);
|
||||
String rsaSign = getRsaSign(params, RSA_SIGN);
|
||||
params.put(RSA_SIGN, rsaSign);
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取"查询支付状态"所需参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getUseQueryPay() {
|
||||
String appKey = payConfigStorage.getAppKey();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(APP_KEY, appKey);
|
||||
result.put(APP_ID, payConfigStorage.getAppid());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取"创建订单"所需参数
|
||||
*
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> getUseOrderInfoParams(PayOrder order) {
|
||||
BaiduPayOrder payOrder = (BaiduPayOrder) order;
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
String appKey = payConfigStorage.getAppKey();
|
||||
String dealId = payConfigStorage.getDealId();
|
||||
result.put(APP_KEY, appKey);
|
||||
result.put(TP_ORDER_ID, payOrder.getTradeNo());
|
||||
result.put(DEAL_ID, dealId);
|
||||
result.put(DEAL_TITLE, payOrder.getSubject());
|
||||
result.put(SIGN_FIELDS_RANGE, payOrder.getSignFieldsRange());
|
||||
result.put(BIZ_INFO, JSON.toJSONString(payOrder.getBizInfo()));
|
||||
result.put(TOTAL_AMOUNT, String.valueOf(order.getPrice()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取输出消息,用户返回给支付端
|
||||
*
|
||||
* @param code 状态
|
||||
* @param message 消息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public PayOutMessage getPayOutMessage(String code, String message) {
|
||||
throw new UnsupportedOperationException("请使用 " + getClass().getName() + "#getPayOutMessageUseBaidu");
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求业务方退款审核/响应处理
|
||||
* http://smartprogram.baidu.com/docs/develop/function/tune_up_examine/
|
||||
*
|
||||
* @param errno
|
||||
* @param message
|
||||
* @param auditStatus
|
||||
* @param refundPayMoney
|
||||
* @return
|
||||
*/
|
||||
public PayOutMessage getApplyRefundOutMessageUseBaidu(Integer errno,
|
||||
String message,
|
||||
AuditStatus auditStatus,
|
||||
BigDecimal refundPayMoney) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("auditStatus", auditStatus.getCode());
|
||||
JSONObject calculateRes = new JSONObject();
|
||||
calculateRes.put("refundPayMoney", refundPayMoney);
|
||||
data.put("calculateRes", calculateRes);
|
||||
return PayOutMessage.JSON()
|
||||
.content("errno", errno)
|
||||
.content("message", message)
|
||||
.content("data", data)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知退款状态/响应处理
|
||||
* http://smartprogram.baidu.com/docs/develop/function/tune_up_drawback/
|
||||
*
|
||||
* @param errno
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public PayOutMessage getRefundOutMessageUseBaidu(Integer errno,
|
||||
String message) {
|
||||
return PayOutMessage.JSON()
|
||||
.content("errno", errno)
|
||||
.content("message", message)
|
||||
.content("data", "{}")
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付通知/响应处理
|
||||
*
|
||||
* @param errno
|
||||
* @param message
|
||||
* @param isConsumed
|
||||
* @param isErrorOrder
|
||||
* @return
|
||||
*/
|
||||
public PayOutMessage getPayOutMessageUseBaidu(Integer errno,
|
||||
String message,
|
||||
Integer isConsumed,
|
||||
Integer isErrorOrder) {
|
||||
Asserts.isNoNull(errno, "errno 是必填的");
|
||||
Asserts.isNoNull(message, "message 是必填的");
|
||||
Asserts.isNoNull(isConsumed, "isConsumed 是必填的");
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("isConsumed", isConsumed);
|
||||
if (isErrorOrder != null) {
|
||||
data.put("isErrorOrder", isErrorOrder);
|
||||
}
|
||||
return PayOutMessage.JSON()
|
||||
.content("errno", errno)
|
||||
.content("message", message)
|
||||
.content("data", data)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付通知/响应处理
|
||||
* http://smartprogram.baidu.com/docs/develop/function/tune_up_notice/
|
||||
*
|
||||
* @param code
|
||||
* @param message
|
||||
* @param isConsumed
|
||||
* @return
|
||||
*/
|
||||
public PayOutMessage getPayOutMessageUseBaidu(Integer code,
|
||||
String message,
|
||||
Integer isConsumed) {
|
||||
return getPayOutMessageUseBaidu(code, message, isConsumed, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付通知/响应处理
|
||||
* http://smartprogram.baidu.com/docs/develop/function/tune_up_notice/
|
||||
*
|
||||
* @param payMessage 支付回调消息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PayOutMessage successPayOutMessage(PayMessage payMessage) {
|
||||
return getPayOutMessageUseBaidu(0, "success", 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取输出消息,用户返回给支付端, 针对于web端
|
||||
*
|
||||
* @param orderInfo 发起支付的订单信息
|
||||
* @param method 请求方式 "post" "get",
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public String buildRequest(Map<String, Object> orderInfo,
|
||||
MethodType method) {
|
||||
throw new UnsupportedOperationException("百度不支持PC支付");
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度不支持扫码付
|
||||
*
|
||||
* @param order 发起支付的订单信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public String getQrPay(BaiduPayOrder order) {
|
||||
throw new UnsupportedOperationException("百度不支持扫码付");
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度不支持刷卡付
|
||||
*
|
||||
* @param order 发起支付的订单信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<String, Object> microPay(BaiduPayOrder order) {
|
||||
throw new UnsupportedOperationException("百度不支持刷卡付");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
*
|
||||
* @param tradeNo 支付平台订单号
|
||||
* @param outTradeNo 商户单号
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> query(String tradeNo, String outTradeNo) {
|
||||
return secondaryInterface(tradeNo, outTradeNo, BaiduTransactionType.PAY_QUERY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度不支持该操作
|
||||
*
|
||||
* @param tradeNo 支付平台订单号
|
||||
* @param outTradeNo 商户单号
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<String, Object> close(String tradeNo, String outTradeNo) {
|
||||
throw new UnsupportedOperationException("不支持该操作");
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款, 请使用 {@link com.egzosn.pay.baidu.api.BaiduPayService#refundUseBaidu}
|
||||
*
|
||||
* @param orderId
|
||||
* @param userId
|
||||
* @param refundAmount 退款金额
|
||||
* @param totalAmount 总金额
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<String, Object> refund(String orderId,
|
||||
String userId,
|
||||
BigDecimal refundAmount,
|
||||
BigDecimal totalAmount) {
|
||||
throw new UnsupportedOperationException("请使用 " + getClass().getName() + "#refundUseBaidu");
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款
|
||||
*
|
||||
* @param orderId
|
||||
* @param userId
|
||||
* @param refundType
|
||||
* @param tpOrderId
|
||||
* @param refundReason
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> refundUseBaidu(Long orderId,
|
||||
Long userId,
|
||||
Integer refundType,
|
||||
String tpOrderId,
|
||||
String refundReason) {
|
||||
return refundUseBaidu(new BaiduRefundOrder(orderId, userId, refundType, refundReason, tpOrderId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款, 请使用 {@link com.egzosn.pay.baidu.api.BaiduPayService#refundUseBaidu}
|
||||
*
|
||||
* @param refundOrder 退款订单信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<String, Object> refund(RefundOrder refundOrder) {
|
||||
throw new UnsupportedOperationException("请使用 " + getClass().getName() + "#refundUseBaidu");
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款, 请使用 {@link com.egzosn.pay.baidu.api.BaiduPayService#refundUseBaidu}
|
||||
*
|
||||
* @param refundOrder
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> refundUseBaidu(BaiduRefundOrder refundOrder) {
|
||||
Map<String, Object> parameters = getUseQueryPay();
|
||||
BaiduTransactionType transactionType = BaiduTransactionType.APPLY_REFUND;
|
||||
parameters.put(METHOD, transactionType.getMethod());
|
||||
parameters.put(ORDER_ID, refundOrder.getTradeNo());
|
||||
parameters.put(USER_ID, refundOrder.getUserId());
|
||||
parameters.put("refundType", refundOrder.getRefundType());
|
||||
parameters.put("refundReason", String.valueOf(refundOrder.getRefundReason()));
|
||||
parameters.put(TP_ORDER_ID, refundOrder.getTpOrderId());
|
||||
parameters.put("applyRefundMoney", refundOrder.getApplyRefundMoney());
|
||||
parameters.put("bizRefundBatchId", refundOrder.getBizRefundBatchId());
|
||||
parameters.put(APP_KEY, payConfigStorage.getAppKey());
|
||||
parameters.put(RSA_SIGN, getRsaSign(parameters, RSA_SIGN));
|
||||
return requestTemplate.getForObject(String.format("%s?%s", getReqUrl(transactionType), UriVariables.getMapToParameters(parameters)), JSONObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退费查询
|
||||
*
|
||||
* @param orderId 百度平台订单ID
|
||||
* @param userId 百度用户ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> refundquery(String orderId,
|
||||
String userId) {
|
||||
Map<String, Object> parameters = getUseQueryPay();
|
||||
BaiduTransactionType transactionType = BaiduTransactionType.REFUND_QUERY;
|
||||
parameters.put(METHOD, transactionType.getMethod());
|
||||
parameters.put(TYPE, 3);
|
||||
parameters.put(ORDER_ID, orderId);
|
||||
parameters.put(USER_ID, userId);
|
||||
parameters.put(APP_KEY, payConfigStorage.getAppKey());
|
||||
parameters.put(RSA_SIGN, getRsaSign(parameters, RSA_SIGN));
|
||||
return requestTemplate.getForObject(String.format("%s?%s", getReqUrl(transactionType), UriVariables.getMapToParameters(parameters)), JSONObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退费查询
|
||||
*
|
||||
* @param refundOrder 退款订单单号信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> refundquery(RefundOrder refundOrder) {
|
||||
return refundquery(refundOrder.getTradeNo(), refundOrder.getOutTradeNo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载资金账单
|
||||
*
|
||||
* @param billDate 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
|
||||
* @param access_token
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadbill(Date billDate, String access_token) {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("access_token", access_token);
|
||||
parameters.put("billTime", DateUtils.formatDay(billDate));
|
||||
return requestTemplate.getForObject(String.format("%s?%s", getReqUrl(BaiduTransactionType.DOWNLOAD_BILL),
|
||||
UriVariables.getMapToParameters(parameters)), JSONObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载订单对账单
|
||||
*
|
||||
* @param billDate
|
||||
* @param access_token
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> downloadOrderBill(Date billDate, String access_token) {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("access_token", access_token);
|
||||
parameters.put("billTime", DateUtils.formatDay(billDate));
|
||||
return requestTemplate.getForObject(String.format("%s?%s", getReqUrl(BaiduTransactionType.DOWNLOAD_ORDER_BILL),
|
||||
UriVariables.getMapToParameters(parameters)), JSONObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用查询接口
|
||||
*
|
||||
* @param orderId
|
||||
* @param siteId
|
||||
* @param transactionType 交易类型
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> secondaryInterface(Object orderId,
|
||||
String siteId,
|
||||
TransactionType transactionType) {
|
||||
if (!BaiduTransactionType.PAY_QUERY.equals(transactionType)) {
|
||||
throw new UnsupportedOperationException("不支持该操作");
|
||||
}
|
||||
|
||||
Map<String, Object> parameters = getUseQueryPay();
|
||||
parameters.put(ORDER_ID, orderId);
|
||||
parameters.put(SITE_ID, siteId);
|
||||
parameters.put(SIGN, getRsaSign(parameters, SIGN));
|
||||
return requestTemplate.getForObject(String.format("%s?%s", getReqUrl(transactionType), UriVariables.getMapToParameters(parameters)), JSONObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付请求地址
|
||||
*
|
||||
* @param transactionType 交易类型
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getReqUrl(TransactionType transactionType) {
|
||||
return ((BaiduTransactionType) transactionType).getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*
|
||||
* @param params
|
||||
* @param ignoreKeys
|
||||
* @return
|
||||
*/
|
||||
private String getRsaSign(Map<String, Object> params, String... ignoreKeys) {
|
||||
String waitSignVal = SignUtils.parameterText(params, "&", false, ignoreKeys);
|
||||
return SignUtils.RSA.createSign(waitSignVal, payConfigStorage.getKeyPrivate(), "UTF-8");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.egzosn.pay.baidu.bean;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.common.bean.TransactionType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BaiduPayOrder extends PayOrder {
|
||||
|
||||
/**
|
||||
* 需要隐藏的支付方式
|
||||
*/
|
||||
private List<TransactionType> bannedChannels = Collections.emptyList();
|
||||
|
||||
/**
|
||||
* 固定值
|
||||
*/
|
||||
private String signFieldsRange;
|
||||
|
||||
/**
|
||||
* 附加信息
|
||||
*/
|
||||
private JSONObject bizInfo = new JSONObject();
|
||||
|
||||
public BaiduPayOrder(String dealTitle,
|
||||
BigDecimal totalAmount,
|
||||
String tpOrderId,
|
||||
String signFieldsRange) {
|
||||
this(dealTitle, totalAmount, tpOrderId, signFieldsRange, Collections.<TransactionType>emptyList());
|
||||
}
|
||||
|
||||
public BaiduPayOrder(String dealTitle,
|
||||
BigDecimal totalAmount,
|
||||
String tpOrderId,
|
||||
String signFieldsRange,
|
||||
List<TransactionType> bannedChannels) {
|
||||
setPrice(totalAmount);
|
||||
setOutTradeNo(tpOrderId);
|
||||
setSubject(dealTitle);
|
||||
setSignFieldsRange(signFieldsRange);
|
||||
setBannedChannels(bannedChannels);
|
||||
}
|
||||
|
||||
public JSONObject getBizInfo() {
|
||||
return bizInfo;
|
||||
}
|
||||
|
||||
public void setBizInfo(JSONObject bizInfo) {
|
||||
this.bizInfo = bizInfo;
|
||||
}
|
||||
|
||||
public List<TransactionType> getBannedChannels() {
|
||||
return bannedChannels;
|
||||
}
|
||||
|
||||
public void setBannedChannels(List<TransactionType> bannedChannels) {
|
||||
this.bannedChannels = bannedChannels;
|
||||
}
|
||||
|
||||
public String getSignFieldsRange() {
|
||||
return signFieldsRange;
|
||||
}
|
||||
|
||||
public void setSignFieldsRange(String signFieldsRange) {
|
||||
this.signFieldsRange = signFieldsRange;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.egzosn.pay.baidu.bean;
|
||||
|
||||
import com.egzosn.pay.common.bean.RefundOrder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class BaiduRefundOrder extends RefundOrder {
|
||||
/**
|
||||
* 平台用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 退款类型
|
||||
*/
|
||||
private Integer refundType;
|
||||
/**
|
||||
* 退款原因
|
||||
*/
|
||||
private String refundReason;
|
||||
/**
|
||||
* 平台订单ID
|
||||
*/
|
||||
private String tpOrderId;
|
||||
/**
|
||||
* 退款金额,单位:分,发起部分退款时必传
|
||||
*/
|
||||
private BigDecimal applyRefundMoney;
|
||||
/**
|
||||
* 业务方退款批次id,退款业务流水唯一编号,发起部分退款时必传
|
||||
*/
|
||||
private String bizRefundBatchId;
|
||||
|
||||
public BaiduRefundOrder(Long orderId,
|
||||
Long userId,
|
||||
Integer refundType,
|
||||
String refundReason,
|
||||
String tpOrderId) {
|
||||
super();
|
||||
setTradeNo(String.valueOf(orderId));
|
||||
this.userId = userId;
|
||||
this.refundType = refundType;
|
||||
this.refundReason = refundReason;
|
||||
this.tpOrderId = tpOrderId;
|
||||
}
|
||||
|
||||
public BigDecimal getApplyRefundMoney() {
|
||||
return applyRefundMoney;
|
||||
}
|
||||
|
||||
public void setApplyRefundMoney(BigDecimal applyRefundMoney) {
|
||||
setRefundAmount(applyRefundMoney);
|
||||
}
|
||||
|
||||
public String getBizRefundBatchId() {
|
||||
return bizRefundBatchId;
|
||||
}
|
||||
|
||||
public void setBizRefundBatchId(String bizRefundBatchId) {
|
||||
this.bizRefundBatchId = bizRefundBatchId;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public Integer getRefundType() {
|
||||
return refundType;
|
||||
}
|
||||
|
||||
public String getRefundReason() {
|
||||
return refundReason;
|
||||
}
|
||||
|
||||
public String getTpOrderId() {
|
||||
return tpOrderId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.egzosn.pay.baidu.bean;
|
||||
|
||||
import com.egzosn.pay.common.bean.TransactionType;
|
||||
|
||||
public enum BaiduTransactionType implements TransactionType {
|
||||
/**
|
||||
* 查询支付状态
|
||||
*/
|
||||
PAY_QUERY("https://dianshang.baidu.com/platform/entity/openapi/queryorderdetail", null),
|
||||
/**
|
||||
* 取消核销
|
||||
*/
|
||||
REFUND_QUERY("https://nop.nuomi.com/nop/server/rest", "nuomi.cashier.syncorderstatus"),
|
||||
/**
|
||||
* 下载资金账单
|
||||
*/
|
||||
DOWNLOAD_BILL("https://openapi.baidu.com/rest/2.0/smartapp/pay/paymentservice/capitaBill", null),
|
||||
/**
|
||||
* 下载订单对账单
|
||||
*/
|
||||
DOWNLOAD_ORDER_BILL("https://openapi.baidu.com/rest/2.0/smartapp/pay/paymentservice/orderBill", null),
|
||||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
APPLY_REFUND("https://nop.nuomi.com/nop/server/rest", "nuomi.cashier.applyorderrefund");
|
||||
private final String method;
|
||||
private final String url;
|
||||
|
||||
BaiduTransactionType( String url, String method) {
|
||||
this.url = url;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.egzosn.pay.baidu.bean.type;
|
||||
|
||||
public enum AuditStatus {
|
||||
SUCCESS(1, "审核通过可退款"),
|
||||
FAIL(2, "审核不通过,不能退款"),
|
||||
UNKNOWN(3, "审核结果不确定,待重试");
|
||||
private final int code;
|
||||
private final String desc;
|
||||
|
||||
AuditStatus(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package com.egzosn.pay.baidu;
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.egzosn.pay.baidu.util;
|
||||
|
||||
public class Asserts {
|
||||
|
||||
public static void isNoNull(Object object, String message) {
|
||||
if (object == null) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isTrue(boolean bool, String message) {
|
||||
if (!bool) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.egzosn.pay.baidu.api;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Created by hocgin on 2019/11/24.
|
||||
* email: hocgin@gmail.com
|
||||
*
|
||||
* @author hocgin
|
||||
*/
|
||||
public class BaiduPayServiceTest {
|
||||
|
||||
@Test
|
||||
public void orderInfo() {
|
||||
BaiduPayConfigStorage configStorage = new BaiduPayConfigStorage();
|
||||
configStorage.setAppid("APP ID");
|
||||
configStorage.setAppKey("APP KEY");
|
||||
configStorage.setDealId("DEAL ID");
|
||||
configStorage.setKeyPublic("KEY PUBLIC");
|
||||
|
||||
BaiduPayService payService = new BaiduPayService(configStorage);
|
||||
// payService.refund()
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -193,7 +193,20 @@ public enum SignUtils implements SignType {
|
||||
* @param ignoreKey 需要忽略添加的key
|
||||
* @return 去掉空值与签名参数后的新签名,拼接后字符串
|
||||
*/
|
||||
public static String parameterText(Map parameters, String separator, String... ignoreKey ) {
|
||||
public static String parameterText(Map parameters, String separator, String... ignoreKey) {
|
||||
return parameterText(parameters, separator, true, ignoreKey);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 把数组所有元素排序,并按照“参数=参数值”的模式用“@param separator”字符拼接成字符串
|
||||
* @param parameters 参数
|
||||
* @param separator 分隔符
|
||||
* @param ignoreNullValue 需要忽略NULL值
|
||||
* @param ignoreKey 需要忽略添加的key
|
||||
* @return 去掉空值与签名参数后的新签名,拼接后字符串
|
||||
*/
|
||||
public static String parameterText(Map parameters, String separator, boolean ignoreNullValue, String... ignoreKey ) {
|
||||
if(parameters == null){
|
||||
return "";
|
||||
}
|
||||
@@ -225,7 +238,7 @@ public enum SignUtils implements SignType {
|
||||
for (String k : keys) {
|
||||
String valueStr = "";
|
||||
Object o = parameters.get(k);
|
||||
if (null == o) {
|
||||
if (ignoreNullValue && null == o) {
|
||||
continue;
|
||||
}
|
||||
if (o instanceof String[]) {
|
||||
|
||||
8
pom.xml
8
pom.xml
@@ -52,6 +52,7 @@
|
||||
<module>pay-java-payoneer</module>
|
||||
<module>pay-java-paypal</module>
|
||||
<module>pay-java-yiji</module>
|
||||
<module>pay-java-baidu</module>
|
||||
<module>pay-java-demo</module>
|
||||
|
||||
</modules>
|
||||
@@ -63,6 +64,7 @@
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<fastjson.version>1.2.58</fastjson.version>
|
||||
<zxing.version>3.3.1</zxing.version>
|
||||
<junit.version>5.5.1</junit.version>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -104,6 +106,12 @@
|
||||
<version>${zxing.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</dependencyManagement>
|
||||
|
||||
Reference in New Issue
Block a user