mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-07 19:46:15 +08:00
移除已废弃的字段与方法
This commit is contained in:
@@ -4,8 +4,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import com.egzosn.pay.common.bean.MsgType;
|
||||
|
||||
/**
|
||||
* 支付基础配置存储
|
||||
*
|
||||
@@ -51,12 +49,6 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
|
||||
*/
|
||||
private String payType;
|
||||
|
||||
/**
|
||||
* 消息来源类型
|
||||
*/
|
||||
@Deprecated
|
||||
private MsgType msgType;
|
||||
|
||||
|
||||
/**
|
||||
* 访问令牌 每次请求其他方法都要传入的值
|
||||
@@ -158,37 +150,36 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
|
||||
this.payType = payType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MsgType getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(MsgType msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
/**
|
||||
* 获取访问令牌
|
||||
* @return 访问令牌
|
||||
*
|
||||
* @return 访问令牌
|
||||
*/
|
||||
public String getAccessToken() {
|
||||
return this.accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取access token锁
|
||||
*
|
||||
* @return access token锁
|
||||
*/
|
||||
public Lock getAccessTokenLock() {
|
||||
return this.accessTokenLock;
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制将access token过期掉
|
||||
* @return 过期时间
|
||||
*
|
||||
* @return 过期时间
|
||||
*/
|
||||
public long getExpiresTime() {
|
||||
return expiresTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问令牌是否过期
|
||||
*
|
||||
* @return true过期
|
||||
*/
|
||||
public boolean isAccessTokenExpired() {
|
||||
@@ -251,7 +242,7 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAttrs() {
|
||||
if (null == attr){
|
||||
if (null == attr) {
|
||||
attr = new HashMap<>();
|
||||
}
|
||||
return attr;
|
||||
@@ -265,7 +256,8 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
|
||||
|
||||
/**
|
||||
* 添加配置信息
|
||||
* @param key key
|
||||
*
|
||||
* @param key key
|
||||
* @param value 值
|
||||
*/
|
||||
public void addAttr(String key, Object value) {
|
||||
|
||||
@@ -21,9 +21,7 @@ import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
import com.egzosn.pay.common.bean.RefundOrder;
|
||||
import com.egzosn.pay.common.bean.TransactionType;
|
||||
import com.egzosn.pay.common.bean.TransferOrder;
|
||||
import com.egzosn.pay.common.exception.PayErrorException;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.http.HttpRequestTemplate;
|
||||
import com.egzosn.pay.common.util.MatrixToImageWriter;
|
||||
@@ -112,7 +110,8 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
String base64ClientID = null;
|
||||
try {
|
||||
base64ClientID = com.egzosn.pay.common.util.sign.encrypt.Base64.encode(String.format("%s:%s", user, password).getBytes("UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
@@ -154,10 +153,12 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
Map orderInfo = orderInfo(order);
|
||||
return buildRequest(orderInfo, MethodType.POST);
|
||||
}
|
||||
|
||||
/**
|
||||
* app支付
|
||||
*
|
||||
* @param order 订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @param <O> 预订单类型
|
||||
* @return 对应app所需参数信息
|
||||
*/
|
||||
@Override
|
||||
@@ -173,7 +174,7 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
*/
|
||||
@Override
|
||||
public <O extends PayOrder> BufferedImage genQrPay(O order) {
|
||||
return MatrixToImageWriter.writeInfoToJpgBuff(getQrPay(order));
|
||||
return MatrixToImageWriter.writeInfoToJpgBuff(getQrPay(order));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +200,8 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
if (valueStr.equals(new String(valueStr.getBytes("iso8859-1"), "iso8859-1"))) {
|
||||
valueStr = new String(valueStr.getBytes("iso8859-1"), payConfigStorage.getInputCharset());
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
@@ -265,7 +267,6 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 申请退款接口
|
||||
*
|
||||
@@ -281,7 +282,6 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
*
|
||||
@@ -309,19 +309,6 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
return callback.perform(downloadbill(billDate, billType));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tradeNoOrBillDate 支付平台订单号或者账单类型, 具体请 类型为{@link String }或者 {@link Date },类型须强制限制,类型不对应则抛出异常{@link PayErrorException}
|
||||
* @param outTradeNoBillType 商户单号或者 账单类型
|
||||
* @param transactionType 交易类型
|
||||
* @param callback 处理器
|
||||
* @param <T> 返回类型
|
||||
* @return 返回支付方对应接口的结果
|
||||
*/
|
||||
@Override
|
||||
public <T> T secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType, Callback<T> callback) {
|
||||
return callback.perform(secondaryInterface(tradeNoOrBillDate, outTradeNoBillType, transactionType));
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
@@ -450,12 +437,13 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
/**
|
||||
* 预订单回调处理器,用于订单信息的扩展
|
||||
* 签名之前使用
|
||||
* 如果需要进行扩展请重写该方法即可
|
||||
* 如果需要进行扩展请重写该方法即可
|
||||
*
|
||||
* @param orderInfo 预订单信息
|
||||
* @param orderInfo 订单信息
|
||||
* @return 处理后订单信息
|
||||
*/
|
||||
public <O extends PayOrder> Map<String, Object> preOrderHandler(Map<String, Object> orderInfo, O payOrder){
|
||||
public <O extends PayOrder> Map<String, Object> preOrderHandler(Map<String, Object> orderInfo, O payOrder) {
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.egzosn.pay.common.api;
|
||||
|
||||
import com.egzosn.pay.common.bean.Attrs;
|
||||
import com.egzosn.pay.common.bean.MsgType;
|
||||
|
||||
/**
|
||||
* 支付客户端配置存储
|
||||
@@ -23,10 +22,21 @@ public interface PayConfigStorage extends Attrs {
|
||||
|
||||
/**
|
||||
* 应用id
|
||||
* 纠正名称
|
||||
*
|
||||
* @return 应用id
|
||||
* @see #getAppId()
|
||||
*/
|
||||
@Deprecated
|
||||
String getAppid();
|
||||
|
||||
/**
|
||||
* 应用id
|
||||
* 纠正名称
|
||||
*
|
||||
* @return 应用id
|
||||
*/
|
||||
String getAppid();
|
||||
String getAppId();
|
||||
|
||||
/**
|
||||
* 合作商唯一标识
|
||||
@@ -100,17 +110,6 @@ public interface PayConfigStorage extends Attrs {
|
||||
*/
|
||||
String getPayType();
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*
|
||||
* @return "text" 或者 "xml",json
|
||||
* @see #getMsgType
|
||||
* @see MsgType
|
||||
*/
|
||||
@Deprecated
|
||||
MsgType getMsgType();
|
||||
|
||||
|
||||
/**
|
||||
* 应该是线程安全的
|
||||
*
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
package com.egzosn.pay.common.api;
|
||||
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
import com.egzosn.pay.common.util.LogExceptionHandler;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -14,6 +8,13 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
import com.egzosn.pay.common.util.LogExceptionHandler;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 支付消息路由器,通过代码化的配置,把来自支付的消息交给handler处理
|
||||
@@ -124,15 +125,13 @@ public class PayMessageRouter {
|
||||
* 处理支付消息
|
||||
*
|
||||
* @param payMessage 支付消息
|
||||
* @param storage 支付配置
|
||||
* @param storage 支付配置
|
||||
* @return 支付输出结果
|
||||
*/
|
||||
public PayOutMessage route(Map<String, Object> payMessage, PayConfigStorage storage) {
|
||||
PayMessage message = payService.createMessage(payMessage);
|
||||
message.setPayType(storage.getPayType());
|
||||
if (null != storage.getMsgType()){
|
||||
message.setMsgType(storage.getMsgType().name());
|
||||
}
|
||||
|
||||
return route(message);
|
||||
}
|
||||
|
||||
@@ -172,7 +171,8 @@ public class PayMessageRouter {
|
||||
}
|
||||
})
|
||||
);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
res = rule.service(payMessage, payService, exceptionHandler);
|
||||
// 在同步操作结束,session访问结束
|
||||
if (LOG.isDebugEnabled()) {
|
||||
@@ -190,9 +190,11 @@ public class PayMessageRouter {
|
||||
future.get();
|
||||
LOG.debug("End session access: async=true, fromPay=" + payMessage.getFromPay());
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOG.error("Error happened when wait task finish", e);
|
||||
} catch (ExecutionException e) {
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
LOG.error("Error happened when wait task finish", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.egzosn.pay.common.api;
|
||||
|
||||
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
import com.egzosn.pay.common.exception.PayErrorException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
import com.egzosn.pay.common.exception.PayErrorException;
|
||||
|
||||
|
||||
/**
|
||||
* Route规则 路由
|
||||
* @author egan
|
||||
*
|
||||
* @author egan
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2016-6-1 11:28:01
|
||||
@@ -32,10 +33,6 @@ public class PayMessageRouterRule {
|
||||
*/
|
||||
private boolean async = false;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
private String msgType;
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
@@ -74,7 +71,7 @@ public class PayMessageRouterRule {
|
||||
/**
|
||||
* 设置是否异步执行,默认是true
|
||||
*
|
||||
* @param async 是否异步执行,默认是true
|
||||
* @param async 是否异步执行,默认是true
|
||||
* @return Route规则
|
||||
*/
|
||||
public PayMessageRouterRule async(boolean async) {
|
||||
@@ -82,21 +79,11 @@ public class PayMessageRouterRule {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果msgType等于某值
|
||||
*
|
||||
* @param msgType 消息类型
|
||||
* @return Route规则
|
||||
*/
|
||||
public PayMessageRouterRule msgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果payType等于某值
|
||||
*
|
||||
* @param payType 支付类型
|
||||
* @param payType 支付类型
|
||||
* @return Route规则
|
||||
*/
|
||||
public PayMessageRouterRule payType(String payType) {
|
||||
@@ -110,13 +97,12 @@ public class PayMessageRouterRule {
|
||||
* @param transactionType 交易类型
|
||||
* @return Route规则
|
||||
*/
|
||||
public PayMessageRouterRule transactionType(String ... transactionType) {
|
||||
public PayMessageRouterRule transactionType(String... transactionType) {
|
||||
this.transactionType = transactionType;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 如果subject等于某值
|
||||
*
|
||||
@@ -138,10 +124,11 @@ public class PayMessageRouterRule {
|
||||
this.rSubject = regex;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果subject匹配该正则表达式
|
||||
*
|
||||
* @param key 需要匹配支付消息内键的名字
|
||||
* @param key 需要匹配支付消息内键的名字
|
||||
* @param regex key值对应的正则
|
||||
* @return Route规则
|
||||
*/
|
||||
@@ -165,7 +152,7 @@ public class PayMessageRouterRule {
|
||||
/**
|
||||
* 设置消息拦截器
|
||||
*
|
||||
* @param interceptor 消息拦截器
|
||||
* @param interceptor 消息拦截器
|
||||
* @param otherInterceptors 其他消息拦截器
|
||||
* @return Route规则
|
||||
*/
|
||||
@@ -192,7 +179,7 @@ public class PayMessageRouterRule {
|
||||
/**
|
||||
* 设置消息处理器
|
||||
*
|
||||
* @param handler 消息处理器
|
||||
* @param handler 消息处理器
|
||||
* @param otherHandlers 其他消息处理器
|
||||
* @return Route规则
|
||||
*/
|
||||
@@ -229,41 +216,41 @@ public class PayMessageRouterRule {
|
||||
/**
|
||||
* 将支付事件修正为不区分大小写,
|
||||
* 比如框架定义的事件常量为
|
||||
*
|
||||
* @param payMessage 支付消息
|
||||
* @return 是否匹配通过
|
||||
*/
|
||||
protected boolean test(PayMessage payMessage) {
|
||||
return (
|
||||
(this.msgType == null || this.msgType.toLowerCase().equals((payMessage.getMsgType() ==null?null:payMessage.getMsgType().toLowerCase())))
|
||||
&&
|
||||
(this.payType == null || this.payType.equals((payMessage.getPayType() == null ? null : payMessage.getPayType())))
|
||||
(this.payType == null || this.payType.equals((payMessage.getPayType() == null ? null : payMessage.getPayType())))
|
||||
&&
|
||||
(this.transactionType == null || equalsTransactionType(payMessage.getTransactionType()))
|
||||
&&
|
||||
(this.key == null ||this.rValue == null || Pattern
|
||||
(this.key == null || this.rValue == null || Pattern
|
||||
.matches(this.rValue, payMessage.getPayMessage().get(key) == null ? "" : payMessage.getPayMessage().get(key).toString().trim()))
|
||||
&&
|
||||
&&
|
||||
(this.subject == null || this.subject
|
||||
.equals(payMessage.getSubject() == null ? null : payMessage.getSubject().trim()))
|
||||
&&
|
||||
(this.rSubject == null || Pattern
|
||||
.matches(this.rSubject, payMessage.getSubject() == null ? "" : payMessage.getSubject().trim()))
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配交易类型
|
||||
*
|
||||
* @param transactionType 交易类型
|
||||
* @return 匹配交易类型
|
||||
*/
|
||||
public boolean equalsTransactionType(String transactionType) {
|
||||
if (null == transactionType){
|
||||
if (null == transactionType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String type :this.getTransactionType()){
|
||||
if (type.toLowerCase().equals((transactionType.toLowerCase()))){
|
||||
for (String type : this.getTransactionType()) {
|
||||
if (type.toLowerCase().equals((transactionType.toLowerCase()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -273,15 +260,16 @@ public class PayMessageRouterRule {
|
||||
|
||||
|
||||
/**
|
||||
* 返回支付响应消息
|
||||
* @param payMessage 支付消息
|
||||
* @param payService 支付服务
|
||||
* 返回支付响应消息
|
||||
*
|
||||
* @param payMessage 支付消息
|
||||
* @param payService 支付服务
|
||||
* @param exceptionHandler 异常处理器
|
||||
* @return 支付响应消息
|
||||
*/
|
||||
protected PayOutMessage service(PayMessage payMessage,
|
||||
PayService payService,
|
||||
PayErrorExceptionHandler exceptionHandler) {
|
||||
PayService payService,
|
||||
PayErrorExceptionHandler exceptionHandler) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -301,7 +289,8 @@ public class PayMessageRouterRule {
|
||||
res = handler.handle(payMessage, context, payService);
|
||||
}
|
||||
return res;
|
||||
} catch (PayErrorException e) {
|
||||
}
|
||||
catch (PayErrorException e) {
|
||||
exceptionHandler.handle(e);
|
||||
}
|
||||
return null;
|
||||
@@ -320,15 +309,6 @@ public class PayMessageRouterRule {
|
||||
this.async = async;
|
||||
}
|
||||
|
||||
|
||||
public String getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public String getPayType() {
|
||||
return payType;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
package com.egzosn.pay.common.api;
|
||||
|
||||
import com.egzosn.pay.common.bean.*;
|
||||
import com.egzosn.pay.common.exception.PayErrorException;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.http.HttpRequestTemplate;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import com.egzosn.pay.common.bean.MethodType;
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
import com.egzosn.pay.common.bean.RefundOrder;
|
||||
import com.egzosn.pay.common.bean.RefundResult;
|
||||
import com.egzosn.pay.common.bean.TransactionType;
|
||||
import com.egzosn.pay.common.bean.TransferOrder;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.http.HttpRequestTemplate;
|
||||
|
||||
/**
|
||||
* 支付服务
|
||||
*
|
||||
* @author egan
|
||||
* <pre>
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2016-5-18 14:09:01
|
||||
* </pre>
|
||||
@@ -60,53 +66,35 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
*/
|
||||
|
||||
boolean verify(Map<String, Object> params);
|
||||
/**
|
||||
* 签名校验
|
||||
* 后面版本废弃
|
||||
* @param params 参数集
|
||||
* @param sign 签名原文
|
||||
* @return 签名校验 true通过
|
||||
*/
|
||||
@Deprecated
|
||||
boolean signVerify(Map<String, Object> params, String sign);
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝需要,微信是否也需要再次校验来源,进行订单查询
|
||||
* 校验数据来源
|
||||
* 后面版本废弃
|
||||
* @param id 业务id, 数据的真实性.
|
||||
* @return true通过
|
||||
*/
|
||||
@Deprecated
|
||||
boolean verifySource(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 返回创建的订单信息
|
||||
*
|
||||
* @param order 支付订单
|
||||
* @param <O> 预订单类型
|
||||
* @return 订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @see PayOrder 支付订单信息
|
||||
*/
|
||||
<O extends PayOrder>Map<String, Object> orderInfo(O order);
|
||||
<O extends PayOrder> Map<String, Object> orderInfo(O order);
|
||||
|
||||
/**
|
||||
* 页面转跳支付, 返回对应页面重定向信息
|
||||
*
|
||||
* @param order 订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @param <O> 预订单类型
|
||||
* @return 对应页面重定向信息
|
||||
*/
|
||||
<O extends PayOrder>String toPay(O order);
|
||||
<O extends PayOrder> String toPay(O order);
|
||||
|
||||
/**
|
||||
* app支付
|
||||
*
|
||||
* @param order 订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @param <O> 预订单类型
|
||||
* @return 对应app所需参数信息
|
||||
*/
|
||||
<O extends PayOrder>Map<String, Object> app(O order);
|
||||
<O extends PayOrder> Map<String, Object> app(O order);
|
||||
|
||||
/**
|
||||
* 创建签名
|
||||
@@ -118,7 +106,6 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
String createSign(String content, String characterEncoding);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
*
|
||||
@@ -161,27 +148,29 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
* 获取输出二维码,用户返回给支付端,
|
||||
*
|
||||
* @param order 发起支付的订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @param <O> 预订单类型
|
||||
* @return 返回图片信息,支付时需要的
|
||||
*/
|
||||
<O extends PayOrder>BufferedImage genQrPay(O order);
|
||||
<O extends PayOrder> BufferedImage genQrPay(O order);
|
||||
|
||||
/**
|
||||
* 获取输出二维码信息,
|
||||
*
|
||||
* @param order 发起支付的订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @param <O> 预订单类型
|
||||
* @return 返回二维码信息,,支付时需要的
|
||||
*/
|
||||
<O extends PayOrder>String getQrPay(O order);
|
||||
<O extends PayOrder> String getQrPay(O order);
|
||||
|
||||
/**
|
||||
* 刷卡付,pos主动扫码付款(条码付)
|
||||
* 刷脸付
|
||||
*
|
||||
* @param order 发起支付的订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @param <O> 预订单类型
|
||||
* @return 返回支付结果
|
||||
*/
|
||||
<O extends PayOrder>Map<String, Object> microPay(O order);
|
||||
<O extends PayOrder> Map<String, Object> microPay(O order);
|
||||
|
||||
/**
|
||||
* 交易查询接口
|
||||
@@ -245,7 +234,6 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
<T> T cancel(String tradeNo, String outTradeNo, Callback<T> callback);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 申请退款接口
|
||||
*
|
||||
@@ -265,7 +253,6 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
<T> T refund(RefundOrder refundOrder, Callback<T> callback);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
*
|
||||
@@ -305,32 +292,6 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
<T> T downloadbill(Date billDate, String billType, Callback<T> callback);
|
||||
|
||||
|
||||
/**
|
||||
* 通用查询接口
|
||||
* 接下来移除此方法
|
||||
* @param tradeNoOrBillDate 支付平台订单号或者账单类型, 具体请
|
||||
* 类型为{@link String }或者 {@link Date },类型须强制限制,类型不对应则抛出异常{@link PayErrorException}
|
||||
* @param outTradeNoBillType 商户单号或者 账单类型
|
||||
* @param transactionType 交易类型
|
||||
* @return 返回支付方对应接口的结果
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, Object> secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType);
|
||||
|
||||
/**
|
||||
* 通用查询接口
|
||||
* 接下来移除此方法
|
||||
* @param tradeNoOrBillDate 支付平台订单号或者账单日期, 具体请 类型为{@link String }或者 {@link Date },类型须强制限制,类型不对应则抛出异常{@link PayErrorException}
|
||||
* @param outTradeNoBillType 商户单号或者 账单类型
|
||||
* @param transactionType 交易类型
|
||||
* @param callback 处理器
|
||||
* @param <T> 返回类型
|
||||
* @return 返回支付方对应接口的结果
|
||||
*/
|
||||
@Deprecated
|
||||
<T> T secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType, Callback<T> callback);
|
||||
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
@@ -409,6 +370,7 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
|
||||
/**
|
||||
* 创建消息
|
||||
*
|
||||
* @param message 支付平台返回的消息
|
||||
* @return 支付消息对象
|
||||
*/
|
||||
@@ -417,12 +379,13 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
/**
|
||||
* 预订单回调处理器,用于订单信息的扩展
|
||||
* 签名之前使用
|
||||
* 如果需要进行扩展请重写该方法即可
|
||||
* 如果需要进行扩展请重写该方法即可
|
||||
*
|
||||
* @param orderInfo 商户平台预订单信息
|
||||
* @param payOrder 订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @param payOrder 订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @return 处理后订单信息
|
||||
*/
|
||||
<O extends PayOrder>Map<String, Object> preOrderHandler(Map<String, Object> orderInfo, O payOrder);
|
||||
<O extends PayOrder> Map<String, Object> preOrderHandler(Map<String, Object> orderInfo, O payOrder);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original egan or egan.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.egzosn.pay.common.bean;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
* @author: egan
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2016/11/18 0:59
|
||||
* </pre>
|
||||
*/
|
||||
public enum MsgType {
|
||||
text, xml,json
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.util.Map;
|
||||
/**
|
||||
* 支付回调消息
|
||||
* 基础实现,具体可根据具体支付回调的消息去实现
|
||||
*
|
||||
* @author egan
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
@@ -15,8 +16,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class PayMessage implements Serializable {
|
||||
private Map<String, Object> payMessage = null;
|
||||
@Deprecated
|
||||
private String msgType;
|
||||
private String payType;
|
||||
private String transactionType;
|
||||
private String fromPay;
|
||||
@@ -30,16 +29,14 @@ public class PayMessage implements Serializable {
|
||||
this.payMessage = payMessage;
|
||||
}
|
||||
|
||||
public PayMessage(Map<String, Object> payMessage, String payType, String msgType) {
|
||||
public PayMessage(Map<String, Object> payMessage, String payType) {
|
||||
this.payMessage = payMessage;
|
||||
this.payType = payType;
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
|
||||
public PayMessage(Map<String, Object> payMessage, String msgType, String payType, String transactionType) {
|
||||
public PayMessage(Map<String, Object> payMessage, String payType, String transactionType) {
|
||||
this.payMessage = payMessage;
|
||||
this.msgType = msgType;
|
||||
this.payType = payType;
|
||||
this.transactionType = transactionType;
|
||||
}
|
||||
@@ -48,16 +45,6 @@ public class PayMessage implements Serializable {
|
||||
this.payMessage = payMessage;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
|
||||
public String getPayType() {
|
||||
return payType;
|
||||
@@ -72,7 +59,7 @@ public class PayMessage implements Serializable {
|
||||
}
|
||||
|
||||
public void setTransactionType(String transactionType) {
|
||||
this.transactionType = transactionType;
|
||||
this.transactionType = transactionType;
|
||||
}
|
||||
|
||||
public String getFromPay() {
|
||||
@@ -90,28 +77,31 @@ public class PayMessage implements Serializable {
|
||||
public void setDescribe(String describe) {
|
||||
this.describe = describe;
|
||||
}
|
||||
public String getDiscount(){
|
||||
|
||||
public String getDiscount() {
|
||||
return (String) payMessage.get("discount");
|
||||
}
|
||||
public String getSubject(){
|
||||
|
||||
public String getSubject() {
|
||||
return (String) payMessage.get("subject");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////微信与支付宝共用
|
||||
public String getOutTradeNo(){
|
||||
public String getOutTradeNo() {
|
||||
return (String) payMessage.get("out_trade_no");
|
||||
}
|
||||
|
||||
public String getSign(){
|
||||
public String getSign() {
|
||||
return (String) payMessage.get("sign");
|
||||
}
|
||||
|
||||
public Number getTotalFee(){
|
||||
public Number getTotalFee() {
|
||||
String totalFee = (String) payMessage.get("total_fee");
|
||||
if (null == totalFee || "".equals(totalFee)){ return 0; }
|
||||
if (isNumber(totalFee)){
|
||||
if (null == totalFee || "".equals(totalFee)) {
|
||||
return 0;
|
||||
}
|
||||
if (isNumber(totalFee)) {
|
||||
return new BigDecimal(totalFee);
|
||||
}
|
||||
return 0;
|
||||
@@ -120,13 +110,11 @@ public class PayMessage implements Serializable {
|
||||
/////////微信与支付宝共用
|
||||
|
||||
|
||||
|
||||
public boolean isNumber(String str){
|
||||
public boolean isNumber(String str) {
|
||||
return str.matches("^(-?[1-9]\\d*\\.?\\d*)|(-?0\\.\\d*[1-9])|(-?[0])|(-?[0]\\.\\d*)$");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return payMessage.toString();
|
||||
@@ -137,5 +125,4 @@ public class PayMessage implements Serializable {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.egzosn.pay.common.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.egzosn.pay.common.bean.outbuilder.JsonBuilder;
|
||||
import com.egzosn.pay.common.bean.outbuilder.TextBuilder;
|
||||
import com.egzosn.pay.common.bean.outbuilder.XmlBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 支付回调通知返回消息
|
||||
* @author egan
|
||||
* 支付回调通知返回消息
|
||||
*
|
||||
* @author egan
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2016-6-1 11:40:30
|
||||
@@ -17,7 +18,6 @@ import java.io.Serializable;
|
||||
*/
|
||||
public abstract class PayOutMessage implements Serializable {
|
||||
protected String content;
|
||||
protected String msgType;
|
||||
|
||||
|
||||
public String getContent() {
|
||||
@@ -28,34 +28,32 @@ public abstract class PayOutMessage implements Serializable {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得文本消息builder
|
||||
*
|
||||
* @return 文本消息builder
|
||||
*/
|
||||
public static TextBuilder TEXT() {
|
||||
return new TextBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得XML消息builder
|
||||
*
|
||||
* @return XML消息builder
|
||||
*/
|
||||
public static XmlBuilder XML() {
|
||||
return new XmlBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得Json消息builder
|
||||
*
|
||||
* @return Json消息builder
|
||||
*/
|
||||
public static JsonBuilder JSON() {
|
||||
return new JsonBuilder(new JSONObject());
|
||||
}
|
||||
|
||||
public abstract String toMessage();
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package com.egzosn.pay.common.bean.outbuilder;
|
||||
|
||||
import com.egzosn.pay.common.bean.MsgType;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
|
||||
/**
|
||||
* @author egan
|
||||
* <pre>
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2016-6-1 11:40:30
|
||||
* </pre>
|
||||
*/
|
||||
public class PayJsonOutMessage extends PayOutMessage{
|
||||
public class PayJsonOutMessage extends PayOutMessage {
|
||||
|
||||
public PayJsonOutMessage() {
|
||||
this.msgType = MsgType.json.name();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.egzosn.pay.common.bean.outbuilder;
|
||||
|
||||
import com.egzosn.pay.common.bean.MsgType;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
|
||||
/**
|
||||
@@ -13,7 +12,6 @@ import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
public class PayTextOutMessage extends PayOutMessage{
|
||||
|
||||
public PayTextOutMessage() {
|
||||
this.msgType = MsgType.text.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.egzosn.pay.common.bean.outbuilder;
|
||||
|
||||
import com.egzosn.pay.common.bean.MsgType;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
|
||||
/**
|
||||
@@ -15,7 +14,6 @@ public class PayXmlOutMessage extends PayOutMessage{
|
||||
private String code;
|
||||
|
||||
public PayXmlOutMessage() {
|
||||
this.msgType = MsgType.xml.name();
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.egzosn.pay.common.http;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.egzosn.pay.common.bean.result.PayException;
|
||||
import com.egzosn.pay.common.exception.PayErrorException;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.egzosn.pay.common.bean.result.PayException;
|
||||
import com.egzosn.pay.common.exception.PayErrorException;
|
||||
|
||||
/**
|
||||
* URL表达式处理器
|
||||
@@ -23,22 +22,22 @@ public class UriVariables {
|
||||
|
||||
/**
|
||||
* 依次匹配
|
||||
* @param uri 匹配的uri,带代表式
|
||||
*
|
||||
* @param uri 匹配的uri,带代表式
|
||||
* @param uriVariables 匹配表达式的值
|
||||
* @return 匹配完的url
|
||||
* <code>
|
||||
* System.out.println(getUri("http://egan.in/{a}/ba/{a1}?{bb}={a1}", "no1", "no2", "no3", "no4"));
|
||||
* 结果 http://egan.in/no1/ba/no2?no3=no4
|
||||
* System.out.println(getUri("http://egan.in/{a}/ba/{a1}?{bb}={a1}", "no1", "no2", "no3", "no4"));
|
||||
* 结果 http://egan.in/no1/ba/no2?no3=no4
|
||||
* </code>
|
||||
*
|
||||
*/
|
||||
public static String getUri(String uri, Object... uriVariables) {
|
||||
|
||||
if (null == uriVariables){
|
||||
if (null == uriVariables) {
|
||||
return uri;
|
||||
}
|
||||
for (Object variable : uriVariables){
|
||||
if (null == variable){
|
||||
for (Object variable : uriVariables) {
|
||||
if (null == variable) {
|
||||
continue;
|
||||
}
|
||||
uri = uri.replaceFirst("\\{\\w+\\}", variable.toString());
|
||||
@@ -47,29 +46,29 @@ public class UriVariables {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 匹配Map.key
|
||||
* @param uri 匹配的uri,带代表式
|
||||
*
|
||||
* @param uri 匹配的uri,带代表式
|
||||
* @param uriVariables 匹配表达式的值
|
||||
* @return 匹配完的url
|
||||
* <code>
|
||||
* Map<String, Object> uriVariable = new HashMap<String, Object>();
|
||||
* uriVariable.put("a", "no1");
|
||||
* uriVariable.put("a1", "no2");
|
||||
* uriVariable.put("bb", "no3");
|
||||
* System.out.println(getUri("http://egan.in/{a}/ba/{a1}?{bb}={a1}", uriVariable));
|
||||
* 结果 http://egan.in/no1/ba/no2?no3=no2
|
||||
* Map<String, Object> uriVariable = new HashMap<String, Object>();
|
||||
* uriVariable.put("a", "no1");
|
||||
* uriVariable.put("a1", "no2");
|
||||
* uriVariable.put("bb", "no3");
|
||||
* System.out.println(getUri("http://egan.in/{a}/ba/{a1}?{bb}={a1}", uriVariable));
|
||||
* 结果 http://egan.in/no1/ba/no2?no3=no2
|
||||
* </code>
|
||||
*/
|
||||
public static String getUri(String uri, Map<String, Object> uriVariables) {
|
||||
|
||||
if (null == uriVariables){
|
||||
if (null == uriVariables) {
|
||||
return uri;
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : uriVariables.entrySet()) {
|
||||
Object uriVariable = entry.getValue();
|
||||
if (null == uriVariable){
|
||||
if (null == uriVariable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -79,15 +78,15 @@ public class UriVariables {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Map转化为对应得参数字符串
|
||||
*
|
||||
* @param pe 参数
|
||||
* @return 参数字符串
|
||||
*/
|
||||
public static String getMapToParameters(Map pe){
|
||||
public static String getMapToParameters(Map<String, ?> pe) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry entry : (Set<Map.Entry>)pe.entrySet()) {
|
||||
for (Map.Entry<String, ?> entry : pe.entrySet()) {
|
||||
Object o = entry.getValue();
|
||||
|
||||
if (null == o) {
|
||||
@@ -106,14 +105,15 @@ public class UriVariables {
|
||||
continue;
|
||||
}
|
||||
String value = os[i].toString().trim();
|
||||
valueStr += (i == len - 1) ? value : value + ",";
|
||||
valueStr += (i == len - 1) ? value : value + ",";
|
||||
}
|
||||
builder.append(entry.getKey()).append("=").append(URLEncoder.encode(valueStr, "utf-8")).append("&");
|
||||
|
||||
continue;
|
||||
}
|
||||
builder.append(entry.getKey()).append("=").append(URLEncoder.encode( entry.getValue().toString(), "utf-8")).append("&");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
builder.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(), "utf-8")).append("&");
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public class UriVariables {
|
||||
* @param str 需要解析的字符串
|
||||
* @return 解析的结果map
|
||||
*/
|
||||
public static JSONObject getParametersToMap (String str) {
|
||||
public static JSONObject getParametersToMap(String str) {
|
||||
|
||||
JSONObject map = new JSONObject();
|
||||
int len = str.length();
|
||||
@@ -148,16 +148,19 @@ public class UriVariables {
|
||||
key = temp.toString();
|
||||
temp.setLength(0);
|
||||
isKey = false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
temp.append(curChar);
|
||||
}
|
||||
} else {// 如果当前生成的是value
|
||||
}
|
||||
else {// 如果当前生成的是value
|
||||
if (isOpen) {
|
||||
if (curChar == openName) {
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
} else {//如果没开启嵌套
|
||||
}
|
||||
else {//如果没开启嵌套
|
||||
if (curChar == '{') {//如果碰到,就开启嵌套
|
||||
isOpen = true;
|
||||
openName = '}';
|
||||
@@ -171,7 +174,8 @@ public class UriVariables {
|
||||
putKeyValueToMap(temp, isKey, key, map);
|
||||
temp.setLength(0);
|
||||
isKey = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
temp.append(curChar);
|
||||
}
|
||||
}
|
||||
@@ -182,14 +186,15 @@ public class UriVariables {
|
||||
return map;
|
||||
}
|
||||
|
||||
private static void putKeyValueToMap (StringBuilder temp, boolean isKey, String key, Map<String, Object> map) {
|
||||
private static void putKeyValueToMap(StringBuilder temp, boolean isKey, String key, Map<String, Object> map) {
|
||||
if (isKey) {
|
||||
key = temp.toString();
|
||||
if (key.length() == 0) {
|
||||
throw new PayErrorException(new PayException("QString format illegal", "内容格式有误"));
|
||||
}
|
||||
map.put(key, "");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (key.length() == 0) {
|
||||
throw new PayErrorException(new PayException("QString format illegal", "内容格式有误"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user