mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-08 03:56:48 +08:00
代码整理
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-ali</artifactId>
|
||||
|
||||
@@ -628,6 +628,7 @@ public class AliPayService extends BasePayService<AliPayConfigStorage> implement
|
||||
* @param billType 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单;
|
||||
* @return 返回支付方下载对账单的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, String billType) {
|
||||
|
||||
return this.downloadBill(billDate, "trade".equals(billType) ? AliPayBillType.TRADE_DAY : AliPayBillType.SIGNCUSTOMER_DAY);
|
||||
@@ -640,6 +641,7 @@ public class AliPayService extends BasePayService<AliPayConfigStorage> implement
|
||||
* @param billType 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单;
|
||||
* @return 返回支付方下载对账单的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, BillType billType) {
|
||||
//获取公共参数
|
||||
Map<String, Object> parameters = getPublicParameters(AliTransactionType.DOWNLOADBILL);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-baidu</artifactId>
|
||||
|
||||
@@ -542,6 +542,7 @@ public class BaiduPayService extends BasePayService<BaiduPayConfigStorage> {
|
||||
* @param accessToken 用户token
|
||||
* @return 对账单
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, String accessToken) {
|
||||
return downloadBill(billDate, new BaiduBillType(accessToken, BaiduTransactionType.DOWNLOAD_ORDER_BILL.name()));
|
||||
}
|
||||
@@ -553,6 +554,7 @@ public class BaiduPayService extends BasePayService<BaiduPayConfigStorage> {
|
||||
* @param billType 账单类型 {@link BaiduBillType}
|
||||
* @return 返回支付方下载对账单的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, BillType billType) {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("access_token", billType.getCustom());
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.egzosn.pay.common.api;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@@ -11,6 +12,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -59,6 +61,7 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
*/
|
||||
protected List<PayMessageInterceptor<PayMessage, PayService>> interceptors = new ArrayList<PayMessageInterceptor<PayMessage, PayService>>();
|
||||
|
||||
private Charset inputCharset = Consts.UTF_8;
|
||||
|
||||
/**
|
||||
* 设置支付配置
|
||||
@@ -68,6 +71,10 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
@Override
|
||||
public BasePayService setPayConfigStorage(PC payConfigStorage) {
|
||||
this.payConfigStorage = payConfigStorage;
|
||||
|
||||
if (StringUtils.isNotEmpty(payConfigStorage.getInputCharset())) {
|
||||
this.inputCharset = Charset.forName(payConfigStorage.getInputCharset());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -94,7 +101,6 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
}
|
||||
|
||||
|
||||
|
||||
public BasePayService(PC payConfigStorage) {
|
||||
this(payConfigStorage, null);
|
||||
}
|
||||
@@ -106,7 +112,6 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate a Base64 encoded String from user , password
|
||||
*
|
||||
@@ -159,11 +164,11 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
*/
|
||||
@Override
|
||||
public <O extends PayOrder> String toPay(O order) {
|
||||
if (StringUtils.isNotEmpty(order.getSubject()) && order.getSubject().contains("'")){
|
||||
order.setSubject(order.getSubject().replace("'",""));
|
||||
if (StringUtils.isNotEmpty(order.getSubject()) && order.getSubject().contains("'")) {
|
||||
order.setSubject(order.getSubject().replace("'", ""));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(order.getBody()) && order.getBody().contains("'")){
|
||||
order.setBody(order.getBody().replace("'",""));
|
||||
if (StringUtils.isNotEmpty(order.getBody()) && order.getBody().contains("'")) {
|
||||
order.setBody(order.getBody().replace("'", ""));
|
||||
}
|
||||
Map<String, Object> orderInfo = orderInfo(order);
|
||||
return buildRequest(orderInfo, MethodType.POST);
|
||||
@@ -203,6 +208,7 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
public Map<String, Object> getParameter2Map(Map<String, String[]> parameterMap, InputStream is) {
|
||||
return getNoticeParams(new DefaultNoticeRequest(parameterMap, is)).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
*
|
||||
@@ -213,22 +219,18 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
public NoticeParams getNoticeParams(NoticeRequest request) {
|
||||
final Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
|
||||
Map<String, Object> params = new TreeMap<String, Object>();
|
||||
Map<String, Object> params = new TreeMap<>();
|
||||
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
String[] values = entry.getValue();
|
||||
String valueStr = "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0, len = values.length; i < len; i++) {
|
||||
valueStr += (i == len - 1) ? values[i] : values[i] + ",";
|
||||
sb.append(values[i]).append((i == len - 1) ? "" : ',');
|
||||
}
|
||||
String valueStr = sb.toString();
|
||||
if (StringUtils.isNotEmpty(payConfigStorage.getInputCharset()) && !valueStr.matches("\\w+")) {
|
||||
try {
|
||||
if (valueStr.equals(new String(valueStr.getBytes("iso8859-1"), "iso8859-1"))) {
|
||||
valueStr = new String(valueStr.getBytes("iso8859-1"), payConfigStorage.getInputCharset());
|
||||
}
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
LOG.error("", e);
|
||||
if (valueStr.equals(new String(valueStr.getBytes(Consts.ISO_8859_1), Consts.ISO_8859_1))) {
|
||||
valueStr = new String(valueStr.getBytes(Consts.ISO_8859_1), inputCharset);
|
||||
}
|
||||
}
|
||||
params.put(name, valueStr);
|
||||
@@ -329,9 +331,10 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
* @return 返回支付方下载对账单的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, String billType){
|
||||
public Map<String, Object> downloadBill(Date billDate, String billType) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
@@ -421,7 +424,6 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
*
|
||||
@@ -432,7 +434,7 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
@Deprecated
|
||||
@Override
|
||||
public PayOutMessage payBack(Map<String, String[]> parameterMap, InputStream is) {
|
||||
return payBack(new DefaultNoticeRequest(parameterMap, is));
|
||||
return payBack(new DefaultNoticeRequest(parameterMap, is));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,7 +447,7 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
public PayOutMessage payBack(NoticeRequest request) {
|
||||
final NoticeParams noticeParams = getNoticeParams(request);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("回调响应:{}" , JSON.toJSONString(noticeParams));
|
||||
LOG.debug("回调响应:{}", JSON.toJSONString(noticeParams));
|
||||
}
|
||||
if (!verify(noticeParams)) {
|
||||
return getPayOutMessage("fail", "失败");
|
||||
@@ -480,26 +482,30 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
* @param orderInfo 订单信息
|
||||
* @return 处理后订单信息
|
||||
*/
|
||||
@Override
|
||||
public <O extends PayOrder> Map<String, Object> preOrderHandler(Map<String, Object> orderInfo, O payOrder) {
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过时
|
||||
*
|
||||
* @param parameters 参数map
|
||||
* @param key key
|
||||
* @param value 值
|
||||
* @param key key
|
||||
* @param value 值
|
||||
* @return 返回订单参数
|
||||
*/
|
||||
@Deprecated
|
||||
protected Map<String, Object> setParameters(Map<String, Object> parameters, String key, String value) {
|
||||
return OrderParaStructure.loadParameters(parameters, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 过时
|
||||
*
|
||||
* @param parameters 参数map
|
||||
* @param key key
|
||||
* @param order 订单对象
|
||||
* @param key key
|
||||
* @param order 订单对象
|
||||
* @return 返回订单参数
|
||||
*/
|
||||
@Deprecated
|
||||
|
||||
@@ -146,7 +146,8 @@ public final class UriVariables {
|
||||
boolean isOpen = false;//值里有嵌套
|
||||
char openName = 0;
|
||||
if (len > 0) {
|
||||
for (int i = 0; i < len; i++) {// 遍历整个带解析的字符串
|
||||
// 遍历整个带解析的字符串
|
||||
for (int i = 0; i < len; i++) {
|
||||
curChar = str.charAt(i);// 取当前字符
|
||||
if (isKey) {// 如果当前生成的是key
|
||||
|
||||
@@ -177,7 +178,7 @@ public final class UriVariables {
|
||||
}
|
||||
}
|
||||
if (curChar == '&' && !isOpen) {// 如果读取到&分割符,同时这个分割符不是值域,这时将map里添加
|
||||
putKeyValueToMap(temp, isKey, key, map);
|
||||
putKeyValueToMap(temp, false, key, map);
|
||||
temp.setLength(0);
|
||||
isKey = true;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>war</packaging>
|
||||
@@ -84,7 +84,11 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.10.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.30</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -45,7 +45,7 @@ public class WxV3PayController {
|
||||
private WxPayService service = null;
|
||||
|
||||
|
||||
@PostConstruct //没有证书的情况下注释掉,避免启动报错
|
||||
// @PostConstruct //没有证书的情况下注释掉,避免启动报错
|
||||
public void init() {
|
||||
WxPayConfigStorage wxPayConfigStorage = new WxPayConfigStorage();
|
||||
wxPayConfigStorage.setAppId("wxc7b993ff15a9f26c");
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-fuiou</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-payoneer</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -518,7 +518,7 @@ public class PayPalPayService extends BasePayService<PayPalConfigStorage> implem
|
||||
JSONObject resp = getHttpRequestTemplate().getForObject(getReqUrl(PayPalTransactionType.REFUND_GET), authHeader(), JSONObject.class, refundOrder.getRefundNo());
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, BillType billType) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -231,6 +231,7 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
* @param noticeParams 回调回来的参数集
|
||||
* @return 签名校验 true通过
|
||||
*/
|
||||
@Override
|
||||
public boolean verify(NoticeParams noticeParams) {
|
||||
final Map<String, Object> result = noticeParams.getBody();
|
||||
if (null == result || result.get(SDKConstants.param_signature) == null) {
|
||||
@@ -719,6 +720,7 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
* @param fileType 文件类型 文件类型,一般商户填写00即可
|
||||
* @return 返回fileContent 请自行将数据落地
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, String fileType) {
|
||||
return downloadBill(billDate, new UnionPayBillType(fileType));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-wx-youdian</artifactId>
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.egzosn.pay.wx.youdian.api;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@@ -15,11 +13,9 @@ import com.egzosn.pay.common.api.BasePayService;
|
||||
import com.egzosn.pay.common.bean.AssistOrder;
|
||||
import com.egzosn.pay.common.bean.BaseRefundResult;
|
||||
import com.egzosn.pay.common.bean.BillType;
|
||||
|
||||
import com.egzosn.pay.common.bean.CurType;
|
||||
import com.egzosn.pay.common.bean.MethodType;
|
||||
import com.egzosn.pay.common.bean.NoticeParams;
|
||||
import com.egzosn.pay.common.bean.NoticeRequest;
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
@@ -47,21 +43,19 @@ import com.egzosn.pay.wx.youdian.bean.YoudianTransactionType;
|
||||
*/
|
||||
public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorage> {
|
||||
|
||||
private final static String URL = "http://life.51youdian.com/Api/CheckoutCounter/";
|
||||
|
||||
private static final String URL = "http://life.51youdian.com/Api/CheckoutCounter/";
|
||||
private static final String ACCESS_TOKEN = "access_token";
|
||||
private static final String RETURN_CODE = "return_code";
|
||||
private static final String ERROR_CODE = "errorcode";
|
||||
private static final String ORDER_SN = "order_sn";
|
||||
|
||||
/**
|
||||
* 获取请求token
|
||||
*
|
||||
* @return 授权令牌
|
||||
*/
|
||||
public String getAccessToken() {
|
||||
try {
|
||||
return getAccessToken(false);
|
||||
}
|
||||
catch (PayErrorException e) {
|
||||
throw e;
|
||||
}
|
||||
private String getAccessToken() {
|
||||
return getAccessToken(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +65,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
* @return 新的授权令牌
|
||||
* @throws PayErrorException 支付异常
|
||||
*/
|
||||
public String getAccessToken(boolean forceRefresh) throws PayErrorException {
|
||||
private String getAccessToken(boolean forceRefresh) throws PayErrorException {
|
||||
Lock lock = payConfigStorage.getAccessTokenLock();
|
||||
try {
|
||||
lock.lock();
|
||||
@@ -90,7 +84,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
String sign = createSign(param.toString() + apbNonce, payConfigStorage.getInputCharset());
|
||||
param.append("&apb_nonce=").append(apbNonce).append("&sign=").append(sign);
|
||||
JSONObject json = execute(getReqUrl(YoudianTransactionType.RESET_LOGIN) + "?" + param.toString(), MethodType.GET, null);
|
||||
int errorcode = json.getIntValue("errorcode");
|
||||
int errorcode = json.getIntValue(ERROR_CODE);
|
||||
if (0 == errorcode) {
|
||||
payConfigStorage.updateAccessToken(payConfigStorage.getAccessToken(), 7200);
|
||||
}
|
||||
@@ -112,7 +106,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
* @return 登陆信息
|
||||
* @throws PayErrorException 支付异常
|
||||
*/
|
||||
public JSONObject login() throws PayErrorException {
|
||||
private JSONObject login() throws PayErrorException {
|
||||
TreeMap<String, String> data = new TreeMap<>();
|
||||
data.put("username", payConfigStorage.getSeller());
|
||||
data.put("password", payConfigStorage.getKeyPrivate());
|
||||
@@ -125,7 +119,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
String queryParam = SignTextUtils.parameterText(data) + "&apb_nonce=" + apbNonce + "&sign=" + sign;
|
||||
|
||||
JSONObject json = execute(getReqUrl(YoudianTransactionType.LOGIN) + "?" + queryParam, MethodType.GET, null);
|
||||
payConfigStorage.updateAccessToken(json.getString("access_token"), json.getLongValue("viptime"));
|
||||
payConfigStorage.updateAccessToken(json.getString(ACCESS_TOKEN), json.getLongValue("viptime"));
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -149,24 +143,19 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
* @param noticeParams 回调回来的参数集
|
||||
* @return 签名校验 true通过
|
||||
*/
|
||||
@Override
|
||||
public boolean verify(NoticeParams noticeParams) {
|
||||
final Map<String, Object> params = noticeParams.getBody();
|
||||
|
||||
if (!"SUCCESS".equals(params.get("return_code"))) {
|
||||
LOG.debug(String.format("友店微信支付异常:return_code=%s,参数集=%s", params.get("return_code"), params));
|
||||
if (!"SUCCESS".equals(params.get(RETURN_CODE))) {
|
||||
LOG.debug("友店微信支付异常:return_code={},参数集={}", params.get(RETURN_CODE), params);
|
||||
return false;
|
||||
}
|
||||
if (params.get("sign") == null) {
|
||||
LOG.debug("友店微信支付异常:签名为空!out_trade_no=" + params.get("out_trade_no"));
|
||||
LOG.debug("友店微信支付异常:签名为空!out_trade_no={}", params.get("out_trade_no"));
|
||||
}
|
||||
|
||||
try {
|
||||
return signVerify(params, (String) params.get("sign")) && verifySource((String) params.get("out_trade_no"));
|
||||
}
|
||||
catch (PayErrorException e) {
|
||||
LOG.error(e.getMessage());
|
||||
}
|
||||
return false;
|
||||
return signVerify(params, (String) params.get("sign")) && verifySource((String) params.get("out_trade_no"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +165,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
* @param sign 比对的签名结果
|
||||
* @return 生成的签名结果
|
||||
*/
|
||||
public boolean signVerify(Map<String, Object> params, String sign) {
|
||||
private boolean signVerify(Map<String, Object> params, String sign) {
|
||||
return SignUtils.valueOf(payConfigStorage.getSignType()).verify(params, sign, "&key=" + payConfigStorage.getKeyPublic(), payConfigStorage.getInputCharset());
|
||||
}
|
||||
|
||||
@@ -188,12 +177,12 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
* @param id id 商户订单号(扫码收款返回的order_sn)
|
||||
* @return true通过
|
||||
*/
|
||||
public boolean verifySource(String id) {
|
||||
private boolean verifySource(String id) {
|
||||
|
||||
try {
|
||||
JSONObject jsonObject = (JSONObject) query(id, null);
|
||||
|
||||
return 0 == jsonObject.getIntValue("errorcode");
|
||||
return 0 == jsonObject.getIntValue(ERROR_CODE);
|
||||
}
|
||||
catch (PayErrorException e) {
|
||||
if (Integer.parseInt(e.getPayError().getErrorCode()) >= 400) {
|
||||
@@ -216,13 +205,13 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
* @see MethodType#GET
|
||||
* @see MethodType#POST
|
||||
*/
|
||||
public JSONObject execute(String uri, MethodType method, Object request) throws PayErrorException {
|
||||
private JSONObject execute(String uri, MethodType method, Object request) throws PayErrorException {
|
||||
int retryTimes = 0;
|
||||
do {
|
||||
try {
|
||||
JSONObject result = requestTemplate.doExecute(uri, request, JSONObject.class, method);
|
||||
if (0 != result.getIntValue("errorcode")) {
|
||||
throw new PayErrorException(new YdPayError(result.getIntValue("errorcode"), result.getString("msg"), result.toJSONString()));
|
||||
if (0 != result.getIntValue(ERROR_CODE)) {
|
||||
throw new PayErrorException(new YdPayError(result.getIntValue(ERROR_CODE), result.getString("msg"), result.toJSONString()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -263,7 +252,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
@Override
|
||||
public JSONObject orderInfo(PayOrder order) {
|
||||
Map<String, Object> data = new TreeMap<>();
|
||||
data.put("access_token", getAccessToken());
|
||||
data.put(ACCESS_TOKEN, getAccessToken());
|
||||
data.put("paymoney", Util.conversionAmount(order.getPrice()).toString());
|
||||
data.putAll(order.getAttrs());
|
||||
data = preOrderHandler(data, order);
|
||||
@@ -271,15 +260,10 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
String sign = createSign(SignTextUtils.parameterText(data, "") + apbNonce, payConfigStorage.getInputCharset());
|
||||
data.put("PayMoney", data.remove("paymoney"));
|
||||
String params = SignTextUtils.parameterText(data) + "&apb_nonce=" + apbNonce + "&sign=" + sign;
|
||||
try {
|
||||
JSONObject json = execute(getReqUrl(order.getTransactionType()) + "?" + params, MethodType.GET, null);
|
||||
//友店比较特殊,需要在下完预订单后,自己存储 order_sn 对应 微信官方文档 out_trade_no
|
||||
order.setTradeNo(json.getString("order_sn"));
|
||||
return json;
|
||||
}
|
||||
catch (PayErrorException e) {
|
||||
throw e;
|
||||
}
|
||||
JSONObject json = execute(getReqUrl(order.getTransactionType()) + "?" + params, MethodType.GET, null);
|
||||
//友店比较特殊,需要在下完预订单后,自己存储 order_sn 对应 微信官方文档 out_trade_no
|
||||
order.setTradeNo(json.getString(ORDER_SN));
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
@@ -301,31 +285,6 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
*
|
||||
* @param request 通知请求
|
||||
* @return 获得回调的请求参数
|
||||
*/
|
||||
@Override
|
||||
public NoticeParams getNoticeParams(NoticeRequest request) {
|
||||
final Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
Map<String, Object> params = new TreeMap<String, Object>();
|
||||
for (Iterator iter = parameterMap.keySet().iterator(); iter.hasNext(); ) {
|
||||
String name = (String) iter.next();
|
||||
String[] values = parameterMap.get(name);
|
||||
String valueStr = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
|
||||
}
|
||||
params.put(name, valueStr.trim());
|
||||
}
|
||||
|
||||
return new NoticeParams(params);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 具体需要返回的数据为
|
||||
* return_code 返回码只有SUCCESS和FAIL
|
||||
@@ -342,11 +301,11 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
@Override
|
||||
public PayOutMessage getPayOutMessage(String code, String message) {
|
||||
Map<String, Object> builder = new TreeMap<>();
|
||||
builder.put("return_code", code.toUpperCase());
|
||||
builder.put(RETURN_CODE, code.toUpperCase());
|
||||
builder.put("return_msg", message);
|
||||
builder.put("nonce_str", SignTextUtils.randomStr());
|
||||
String sgin = SignUtils.valueOf(payConfigStorage.getSignType()).sign(builder, "&key=" + payConfigStorage.getKeyPrivate(), payConfigStorage.getInputCharset());
|
||||
return PayOutMessage.TEXT().content("{\"return_code\":\"" + builder.get("return_code") + "\",\"return_msg\":\"" + builder.get("return_msg") + "\",\"nonce_str\":\"" + builder.get("nonce_str") + "\",\"sign\":\"" + sgin + "\"}").build();
|
||||
return PayOutMessage.TEXT().content("{\"return_code\":\"" + builder.get(RETURN_CODE) + "\",\"return_msg\":\"" + builder.get("return_msg") + "\",\"nonce_str\":\"" + builder.get("nonce_str") + "\",\"sign\":\"" + sgin + "\"}").build();
|
||||
}
|
||||
|
||||
|
||||
@@ -393,8 +352,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
@Override
|
||||
public Map<String, Object> microPay(PayOrder order) {
|
||||
order.setTransactionType(YoudianTransactionType.MICROPAY);
|
||||
JSONObject orderInfo = orderInfo(order);
|
||||
return orderInfo;
|
||||
return orderInfo(order);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,7 +364,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> query(String tradeNo, String outTradeNo) {
|
||||
return query(new AssistOrder(tradeNo, outTradeNo));
|
||||
return query(new AssistOrder(tradeNo, outTradeNo));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,18 +377,17 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
public Map<String, Object> query(AssistOrder assistOrder) {
|
||||
String apbNonce = SignTextUtils.randomStr();
|
||||
TreeMap<String, String> data = new TreeMap<>();
|
||||
data.put("access_token", payConfigStorage.getAccessToken());
|
||||
data.put(ACCESS_TOKEN, payConfigStorage.getAccessToken());
|
||||
|
||||
if (StringUtils.isEmpty(assistOrder.getTradeNo())) {
|
||||
data.put("order_sn", assistOrder.getOutTradeNo());
|
||||
data.put(ORDER_SN, assistOrder.getOutTradeNo());
|
||||
}
|
||||
else {
|
||||
data.put("order_sn", assistOrder.getTradeNo());
|
||||
data.put(ORDER_SN, assistOrder.getTradeNo());
|
||||
}
|
||||
String sign = createSign(SignTextUtils.parameterText(data, "") + apbNonce, payConfigStorage.getInputCharset());
|
||||
String queryParam = SignTextUtils.parameterText(data) + "&apb_nonce=" + apbNonce + "&sign=" + sign;
|
||||
JSONObject jsonObject = execute(getReqUrl(YoudianTransactionType.NATIVE_STATUS) + "?" + queryParam, MethodType.GET, null);
|
||||
return jsonObject;
|
||||
return execute(getReqUrl(YoudianTransactionType.NATIVE_STATUS) + "?" + queryParam, MethodType.GET, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -438,14 +395,15 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
public Map<String, Object> close(String tradeNo, String outTradeNo) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易关闭接口
|
||||
*
|
||||
* @param assistOrder 关闭订单
|
||||
* @param assistOrder 关闭订单
|
||||
* @return 返回支付方交易关闭后的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> close(AssistOrder assistOrder){
|
||||
public Map<String, Object> close(AssistOrder assistOrder) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@@ -459,13 +417,13 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
public RefundResult refund(RefundOrder refundOrder) {
|
||||
String apbNonce = SignTextUtils.randomStr();
|
||||
TreeMap<String, String> data = new TreeMap<>();
|
||||
data.put("access_token", payConfigStorage.getAccessToken());
|
||||
data.put(ACCESS_TOKEN, payConfigStorage.getAccessToken());
|
||||
|
||||
if (StringUtils.isEmpty(refundOrder.getOutTradeNo())) {
|
||||
data.put("order_sn", refundOrder.getOutTradeNo());
|
||||
data.put(ORDER_SN, refundOrder.getOutTradeNo());
|
||||
}
|
||||
else {
|
||||
data.put("order_sn", refundOrder.getTradeNo());
|
||||
data.put(ORDER_SN, refundOrder.getTradeNo());
|
||||
}
|
||||
//支付类型刷卡为3扫码为4
|
||||
data.put("type", "4");
|
||||
@@ -476,7 +434,7 @@ public class WxYouDianPayService extends BasePayService<WxYouDianPayConfigStorag
|
||||
return new BaseRefundResult(jsonObject) {
|
||||
@Override
|
||||
public String getCode() {
|
||||
return getAttrString("errorcode");
|
||||
return getAttrString(ERROR_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-wx</artifactId>
|
||||
|
||||
@@ -81,6 +81,7 @@ public class WxCombinePayService extends WxPayService {
|
||||
* @param order 支付订单集
|
||||
* @return 下单结果
|
||||
*/
|
||||
@Override
|
||||
public JSONObject unifiedOrder(PayOrder order) {
|
||||
|
||||
//统一下单
|
||||
|
||||
@@ -200,6 +200,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
|
||||
* @param noticeParams 通知参数
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean verify(NoticeParams noticeParams) {
|
||||
|
||||
//当前使用的微信平台证书序列号
|
||||
@@ -238,7 +239,6 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
|
||||
|
||||
//统一下单
|
||||
Map<String, Object> parameters = wxParameterStructure.initPartner(null);
|
||||
;
|
||||
// wxParameterStructure.getPublicParameters(parameters);
|
||||
// 商品描述
|
||||
OrderParaStructure.loadParameters(parameters, WxConst.DESCRIPTION, order.getSubject());
|
||||
@@ -573,6 +573,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
|
||||
* @param billType 账单类型 {@link WxBillType} 与 {@link WxAccountType}
|
||||
* @return 返回支付方下载对账单的结果, 如果【账单类型】为gzip的话则返回值中key为data值为gzip的输入流
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, BillType billType) {
|
||||
//获取公共参数
|
||||
Map<String, Object> parameters = new HashMap<>(5);
|
||||
|
||||
@@ -94,6 +94,7 @@ public class WxProfitSharingService extends WxPayService implements ProfitSharin
|
||||
* @param noticeParams 通知参数
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean verify(NoticeParams noticeParams) {
|
||||
throw new PayErrorException(new WxPayError("", "分账不支持方式"));
|
||||
}
|
||||
@@ -105,6 +106,7 @@ public class WxProfitSharingService extends WxPayService implements ProfitSharin
|
||||
* @param order 支付订单集
|
||||
* @return 下单结果
|
||||
*/
|
||||
@Override
|
||||
public JSONObject unifiedOrder(PayOrder order) {
|
||||
|
||||
Map<String, Object> parameters = new MapGen<String, Object>(WxConst.APPID, payConfigStorage.getAppId())
|
||||
@@ -336,6 +338,7 @@ public class WxProfitSharingService extends WxPayService implements ProfitSharin
|
||||
* @param billType 账单类型 {@link ProfitSharingBillType}
|
||||
* @return 返回支付方下载对账单的结果, 如果【账单类型】为gzip的话则返回值中key为data值为gzip的输入流
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadBill(Date billDate, BillType billType) {
|
||||
|
||||
Map<String, Object> parameters = new MapGen<String, Object>(WxConst.BILL_DATE, DateUtils.formatDate(billDate, DateUtils.YYYY_MM_DD))
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.egzosn.pay.common.api.BasePayService;
|
||||
import com.egzosn.pay.common.bean.AssistOrder;
|
||||
import com.egzosn.pay.common.bean.BaseRefundResult;
|
||||
import com.egzosn.pay.common.bean.BillType;
|
||||
|
||||
import com.egzosn.pay.common.bean.CurType;
|
||||
import com.egzosn.pay.common.bean.DefaultCurType;
|
||||
import com.egzosn.pay.common.bean.MethodType;
|
||||
@@ -94,7 +93,7 @@ public class YiJiPayService extends BasePayService<YiJiPayConfigStorage> {
|
||||
@Override
|
||||
public boolean verify(Map<String, Object> params) {
|
||||
|
||||
return verify(new NoticeParams(params));
|
||||
return verify(new NoticeParams(params));
|
||||
|
||||
}
|
||||
|
||||
@@ -104,10 +103,11 @@ public class YiJiPayService extends BasePayService<YiJiPayConfigStorage> {
|
||||
* @param noticeParams 回调回来的参数集
|
||||
* @return 签名校验 true通过
|
||||
*/
|
||||
public boolean verify(NoticeParams noticeParams){
|
||||
@Override
|
||||
public boolean verify(NoticeParams noticeParams) {
|
||||
final Map<String, Object> params = noticeParams.getBody();
|
||||
if (params.get(SIGN) == null) {
|
||||
LOG.debug("易极付支付异常:params:" + params);
|
||||
LOG.debug("易极付支付异常:params:{}", params);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -311,14 +311,15 @@ public class YiJiPayService extends BasePayService<YiJiPayConfigStorage> {
|
||||
public Map<String, Object> close(String tradeNo, String outTradeNo) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易关闭接口
|
||||
*
|
||||
* @param assistOrder 关闭订单
|
||||
* @param assistOrder 关闭订单
|
||||
* @return 返回支付方交易关闭后的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> close(AssistOrder assistOrder){
|
||||
public Map<String, Object> close(AssistOrder assistOrder) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@@ -400,7 +401,6 @@ public class YiJiPayService extends BasePayService<YiJiPayConfigStorage> {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param billDate 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于易极付交易收单的业务账单;signcustomer是指基于商户易极付余额收入及支出等资金变动的帐务账单;
|
||||
* @param billType 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
|
||||
* @return 返回支付方下载对账单的结果
|
||||
|
||||
4
pom.xml
4
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>com.egzosn</groupId>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>2.14.4-fix</version>
|
||||
<version>2.14.5</version>
|
||||
|
||||
<name>Pay Java - Parent</name>
|
||||
<description>Pay Java Parent</description>
|
||||
@@ -65,7 +65,7 @@
|
||||
|
||||
|
||||
<properties>
|
||||
<pay.version>2.14.4-fix</pay.version>
|
||||
<pay.version>2.14.5</pay.version>
|
||||
<httpmime.version>4.5.4</httpmime.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<fastjson.version>1.2.73</fastjson.version>
|
||||
|
||||
Reference in New Issue
Block a user