mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-08 12:06:07 +08:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -12,32 +12,18 @@ import com.egzosn.pay.common.api.BasePayConfigStorage;
|
||||
public class AliPayConfigStorage extends BasePayConfigStorage {
|
||||
|
||||
/**
|
||||
* 商户PID
|
||||
* 商户应用id
|
||||
*/
|
||||
public volatile String appId ;
|
||||
private volatile String appId ;
|
||||
/**
|
||||
* 商户签约拿到的pid,partner_id的简称,合作伙伴身份等同于 partner
|
||||
*/
|
||||
public volatile String pid ;
|
||||
private volatile String pid ;
|
||||
|
||||
/**
|
||||
* 商户收款账号
|
||||
*/
|
||||
public volatile String seller;
|
||||
/**
|
||||
* 公钥
|
||||
*/
|
||||
private volatile String aliPublicKey;
|
||||
|
||||
|
||||
public String getAliPublicKey() {
|
||||
return aliPublicKey;
|
||||
}
|
||||
|
||||
public void setAliPublicKey(String aliPublicKey) {
|
||||
setKeyPublic(aliPublicKey);
|
||||
this.aliPublicKey = aliPublicKey;
|
||||
}
|
||||
private volatile String seller;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -163,11 +163,6 @@ public class AliPayService extends BasePayService {
|
||||
*/
|
||||
private Map<String, Object> getOrder(PayOrder order) {
|
||||
|
||||
//兼容上一版本 即时收款
|
||||
/* if (AliTransactionType.DIRECT == order.getTransactionType() || AliTransactionType.MOBILE == order.getTransactionType() || AliTransactionType.WAPPAY == order.getTransactionType()){
|
||||
return getOrderBefore(order);
|
||||
}
|
||||
*/
|
||||
|
||||
Map<String, Object> orderInfo = getPublicParameters(order.getTransactionType());
|
||||
|
||||
@@ -185,7 +180,6 @@ public class AliPayService extends BasePayService {
|
||||
case DIRECT:
|
||||
bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
|
||||
orderInfo.put("return_url", payConfigStorage.getReturnUrl());
|
||||
// bizContent.remove("seller_id");
|
||||
break;
|
||||
case WAP:
|
||||
bizContent.put("product_code", "QUICK_WAP_PAY");
|
||||
@@ -245,7 +239,6 @@ public class AliPayService extends BasePayService {
|
||||
valueStr += (i == len - 1) ? values[i] : values[i] + ",";
|
||||
}
|
||||
//乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
|
||||
//valueStr = new String(valueStr.getBytes("ISO-8859-1"), "gbk");
|
||||
if (!valueStr.matches("\\w+")){
|
||||
try {
|
||||
if(valueStr.equals(new String(valueStr.getBytes("iso8859-1"), "iso8859-1"))){
|
||||
@@ -313,8 +306,7 @@ public class AliPayService extends BasePayService {
|
||||
|
||||
Map<String, Object> orderInfo = orderInfo(order);
|
||||
|
||||
// Map<String, Object> content = new HashMap<>(1);
|
||||
// content.put("biz_content", orderInfo.remove("biz_content"));
|
||||
|
||||
//预订单
|
||||
JSONObject result = getHttpRequestTemplate().postForObject(getReqUrl() + "?" + UriVariables.getMapToParameters(orderInfo), null, JSONObject.class);
|
||||
JSONObject response = result.getJSONObject("alipay_trade_precreate_response");
|
||||
|
||||
@@ -19,16 +19,54 @@ import com.egzosn.pay.common.bean.TransactionType;
|
||||
* date 2016/10/19 22:58
|
||||
*/
|
||||
public enum AliTransactionType implements TransactionType {
|
||||
//即时到帐 //手机网站支付
|
||||
DIRECT("alipay.trade.page.pay"),APP("alipay.trade.app.pay"),WAP("alipay.trade.wap.pay")
|
||||
// TODO 2017/2/23 20:26 author: egan 以下三个为主动交易类型 暂未测试,
|
||||
//扫码付 //条码付 // 声波付
|
||||
,SWEEPPAY("alipay.trade.precreate"),BAR_CODE("alipay.trade.pay"),WAVE_CODE("alipay.trade.pay")
|
||||
//交易辅助接口
|
||||
,QUERY("alipay.trade.query"),CLOSE("alipay.trade.close"),REFUND("alipay.trade.refund"),REFUNDQUERY("alipay.trade.fastpay.refund.query"),DOWNLOADBILL("alipay.data.dataservice.bill.downloadurl.query")
|
||||
/**
|
||||
* 即时到帐
|
||||
*/
|
||||
DIRECT("alipay.trade.page.pay"),
|
||||
/**
|
||||
* APP支付
|
||||
*/
|
||||
APP("alipay.trade.app.pay"),
|
||||
/**
|
||||
* 手机网站支付
|
||||
*/
|
||||
WAP("alipay.trade.wap.pay")
|
||||
|
||||
/**
|
||||
* 扫码付
|
||||
*/
|
||||
,SWEEPPAY("alipay.trade.precreate"),
|
||||
/**
|
||||
* 条码付
|
||||
*/
|
||||
BAR_CODE("alipay.trade.pay"),
|
||||
/**
|
||||
* 声波付
|
||||
*/
|
||||
WAVE_CODE("alipay.trade.pay")
|
||||
//交易辅助接口
|
||||
|
||||
/**
|
||||
* 交易订单查询
|
||||
*/
|
||||
,QUERY("alipay.trade.query"),
|
||||
/**
|
||||
* 交易订单关闭
|
||||
*/
|
||||
CLOSE("alipay.trade.close"),
|
||||
/**
|
||||
* 退款
|
||||
*/
|
||||
REFUND("alipay.trade.refund"),
|
||||
/**
|
||||
* 退款查询
|
||||
*/
|
||||
REFUNDQUERY("alipay.trade.fastpay.refund.query"),
|
||||
/**
|
||||
* 下载对账单
|
||||
*/
|
||||
DOWNLOADBILL("alipay.data.dataservice.bill.downloadurl.query")
|
||||
|
||||
//回调通知,回调后不清楚交易类型,以此定义
|
||||
,UNAWARE("UNAWARE")
|
||||
;
|
||||
|
||||
|
||||
@@ -44,7 +82,7 @@ public enum AliTransactionType implements TransactionType {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
/**
|
||||
/* *
|
||||
* 获取接口名称
|
||||
* @return 接口名称
|
||||
*/
|
||||
|
||||
@@ -36,8 +36,8 @@ public class AliPayService extends BasePayService {
|
||||
protected final Log LOG = LogFactory.getLog(AliPayService.class);
|
||||
|
||||
|
||||
private String HTTPS_REQ_URL = "https://mapi.alipay.com/gateway.do";
|
||||
private String QUERY_REQ_URL = "https://openapi.alipay.com/gateway.do";
|
||||
private static final String HTTPS_REQ_URL = "https://mapi.alipay.com/gateway.do";
|
||||
private static final String QUERY_REQ_URL = "https://openapi.alipay.com/gateway.do";
|
||||
|
||||
public AliPayService(PayConfigStorage payConfigStorage) {
|
||||
super(payConfigStorage);
|
||||
@@ -164,7 +164,7 @@ public class AliPayService extends BasePayService {
|
||||
}
|
||||
|
||||
private String getOrderInfo(PayOrder order) {
|
||||
String orderInfo = "partner=\"" + this.payConfigStorage.getPartner() + "\"";
|
||||
String orderInfo = "partner=\"" + this.payConfigStorage.getPid() + "\"";
|
||||
orderInfo = orderInfo + "&seller_id=\"" + this.payConfigStorage.getSeller() + "\"";
|
||||
orderInfo = orderInfo + "&out_trade_no=\"" + order.getOutTradeNo() + "\"";
|
||||
orderInfo = orderInfo + "&subject=\"" + order.getSubject() + "\"";
|
||||
@@ -190,7 +190,7 @@ public class AliPayService extends BasePayService {
|
||||
private Map<String, Object> getOrder(PayOrder order) {
|
||||
Map<String, Object> orderInfo = new TreeMap<>();
|
||||
// 签约合作者身份ID
|
||||
orderInfo.put("partner", payConfigStorage.getPartner());
|
||||
orderInfo.put("partner", payConfigStorage.getPid());
|
||||
// 签约卖家支付宝账号
|
||||
orderInfo.put("seller_id", payConfigStorage.getSeller());
|
||||
// 商户网站唯一订单号
|
||||
|
||||
@@ -22,13 +22,41 @@ import com.egzosn.pay.common.bean.TransactionType;
|
||||
*/
|
||||
@Deprecated
|
||||
public enum AliTransactionType implements TransactionType {
|
||||
//即时到帐 //移动支付 //手机网站支付
|
||||
DIRECT("create_direct_pay_by_user"),APP("mobile.securitypay.pay"),WAP("alipay.wap.create.direct.pay.by.user"),
|
||||
//交易辅助接口
|
||||
QUERY("alipay.trade.query"),CLOSE("alipay.trade.close"),REFUND("alipay.trade.refund"),REFUNDQUERY("alipay.trade.fastpay.refund.query"),DOWNLOADBILL("alipay.data.dataservice.bill.downloadurl.query")
|
||||
/**
|
||||
* 即时到帐
|
||||
*/
|
||||
DIRECT("create_direct_pay_by_user"),
|
||||
/**
|
||||
* 移动支付
|
||||
*/
|
||||
APP("mobile.securitypay.pay"),
|
||||
/**
|
||||
* 手机网站支付
|
||||
*/
|
||||
WAP("alipay.wap.create.direct.pay.by.user"),
|
||||
|
||||
//不知道交易类型,主要用于回调通知,回调后不清楚交易类型,以此定义
|
||||
,UNAWARE("UNAWARE")
|
||||
//交易辅助接口
|
||||
|
||||
/**
|
||||
* 交易订单查询
|
||||
*/
|
||||
QUERY("alipay.trade.query"),
|
||||
/**
|
||||
* 交易订单关闭
|
||||
*/
|
||||
CLOSE("alipay.trade.close"),
|
||||
/**
|
||||
* 退款
|
||||
*/
|
||||
REFUND("alipay.trade.refund"),
|
||||
/**
|
||||
* 退款查询
|
||||
*/
|
||||
REFUNDQUERY("alipay.trade.fastpay.refund.query"),
|
||||
/**
|
||||
* 下载对账单
|
||||
*/
|
||||
DOWNLOADBILL("alipay.data.dataservice.bill.downloadurl.query")
|
||||
;
|
||||
|
||||
private String method;
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class BasePayConfigStorage implements PayConfigStorage{
|
||||
/**
|
||||
* 同步回调地址,支付完成后展示的页面
|
||||
*/
|
||||
private volatile String returnUrl;;
|
||||
private volatile String returnUrl;
|
||||
/**
|
||||
* 签名加密类型
|
||||
*/
|
||||
|
||||
@@ -27,25 +27,39 @@ public class PayMessageRouterRule {
|
||||
|
||||
|
||||
private final PayMessageRouter routerBuilder;
|
||||
/**
|
||||
* 默认同步
|
||||
*/
|
||||
private boolean async = false;
|
||||
|
||||
private boolean async = true;
|
||||
|
||||
private String fromPay;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
private String msgType;
|
||||
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
private String payType;
|
||||
|
||||
/**
|
||||
* 交易类型
|
||||
*/
|
||||
private String[] transactionType;
|
||||
|
||||
private String discount;
|
||||
|
||||
private String rDiscount;
|
||||
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* 正则匹配
|
||||
*/
|
||||
private String rSubject;
|
||||
|
||||
/**
|
||||
* 匹配的键名称
|
||||
*/
|
||||
private String key;
|
||||
/**
|
||||
* 匹配的键名称对应的值 正则
|
||||
*/
|
||||
private String rValue;
|
||||
|
||||
private boolean reEnter = false;
|
||||
|
||||
@@ -101,27 +115,7 @@ public class PayMessageRouterRule {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果discount等于某值
|
||||
*
|
||||
* @param discount discount等于某值
|
||||
* @return Route规则
|
||||
*/
|
||||
public PayMessageRouterRule discount(String discount) {
|
||||
this.discount = discount;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果discount匹配该正则表达式
|
||||
*
|
||||
* @param regex discount匹配该正则表达式
|
||||
* @return Route规则
|
||||
*/
|
||||
public PayMessageRouterRule rDiscount(String regex) {
|
||||
this.rDiscount = regex;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果subject等于某值
|
||||
@@ -144,6 +138,18 @@ public class PayMessageRouterRule {
|
||||
this.rSubject = regex;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* 如果subject匹配该正则表达式
|
||||
*
|
||||
* @param key 需要匹配支付消息内键的名字
|
||||
* @param regex key值对应的正则
|
||||
* @return Route规则
|
||||
*/
|
||||
public PayMessageRouterRule key2RValue(String key, String regex) {
|
||||
this.key = key;
|
||||
this.rValue = regex;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -228,19 +234,14 @@ public class PayMessageRouterRule {
|
||||
*/
|
||||
protected boolean test(PayMessage payMessage) {
|
||||
return (
|
||||
(this.fromPay == null || this.fromPay.toLowerCase().equals((payMessage.getFromPay() ==null?null:payMessage.getFromPay().toLowerCase())))
|
||||
&&
|
||||
(this.msgType == null || this.msgType.toLowerCase().equals((payMessage.getMsgType() ==null?null:payMessage.getMsgType().toLowerCase())))
|
||||
(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.transactionType == null || equalsTransactionType(payMessage.getTransactionType()))
|
||||
&&
|
||||
(this.discount == null || this.discount
|
||||
.equals(payMessage.getDiscount() == null ? null : payMessage.getDiscount().trim()))
|
||||
&&
|
||||
(this.rDiscount == null || Pattern
|
||||
.matches(this.rDiscount, payMessage.getDiscount() == null ? "" : payMessage.getDiscount().trim()))
|
||||
(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()))
|
||||
@@ -319,13 +320,6 @@ public class PayMessageRouterRule {
|
||||
this.async = async;
|
||||
}
|
||||
|
||||
public String getFromPay() {
|
||||
return fromPay;
|
||||
}
|
||||
|
||||
public void setFromPay(String fromPay) {
|
||||
this.fromPay = fromPay;
|
||||
}
|
||||
|
||||
public String getMsgType() {
|
||||
return msgType;
|
||||
@@ -351,20 +345,20 @@ public class PayMessageRouterRule {
|
||||
this.transactionType = transactionType;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
return discount;
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setDiscount(String discount) {
|
||||
this.discount = discount;
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getrDiscount() {
|
||||
return rDiscount;
|
||||
public String getrValue() {
|
||||
return rValue;
|
||||
}
|
||||
|
||||
public void setrDiscount(String rDiscount) {
|
||||
this.rDiscount = rDiscount;
|
||||
public void setrValue(String rValue) {
|
||||
this.rValue = rValue;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -95,7 +95,7 @@ public class PayController {
|
||||
* @param payId 账户id
|
||||
* @param openid openid
|
||||
* @param price 金额
|
||||
* @return 跳到支付页面
|
||||
* @return 返回jsapi所需参数
|
||||
*/
|
||||
@RequestMapping(value = "jsapi" )
|
||||
public Map toPay(Integer payId, String openid, BigDecimal price) {
|
||||
@@ -130,7 +130,7 @@ public class PayController {
|
||||
order.setAuthCode(authCode);
|
||||
//支付结果
|
||||
Map<String, Object> params = payResponse.getService().microPay(order);
|
||||
PayConfigStorage storage = payResponse.getStorage();
|
||||
PayConfigStorage storage = payResponse.getService().getPayConfigStorage();
|
||||
//校验
|
||||
if (payResponse.getService().verify(params)) {
|
||||
PayMessage message = new PayMessage(params, storage.getPayType(), storage.getMsgType().name());
|
||||
|
||||
@@ -91,7 +91,6 @@ public class PayResponse {
|
||||
router = new PayMessageRouter(this.service);
|
||||
router
|
||||
.rule()
|
||||
.async(false)
|
||||
//消息类型
|
||||
.msgType(MsgType.text.name())
|
||||
//支付账户事件类型
|
||||
@@ -102,20 +101,17 @@ public class PayResponse {
|
||||
.handler(autowire(new AliPayMessageHandler(payId)))
|
||||
.end()
|
||||
.rule()
|
||||
.async(false)
|
||||
.msgType(MsgType.xml.name())
|
||||
.payType(PayType.wxPay.name())
|
||||
.handler(autowire(new WxPayMessageHandler(payId)))
|
||||
.end()
|
||||
.rule()
|
||||
.async(false)
|
||||
.msgType(MsgType.json.name())
|
||||
.payType(PayType.youdianPay.name())
|
||||
.interceptor(new YoudianPayMessageInterceptor()) //拦截器
|
||||
.handler(autowire(new YouDianPayMessageHandler(payId)))
|
||||
.end()
|
||||
.rule()
|
||||
.async(false)
|
||||
.msgType(MsgType.xml.name())
|
||||
.payType(PayType.fuiou.name())
|
||||
.handler(autowire(new FuiouPayMessageHandler(payId)))
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.egzosn.pay.demo.service.handler;
|
||||
import com.egzosn.pay.common.api.PayService;
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
import com.egzosn.pay.common.bean.outbuilder.TextBuilder;
|
||||
import com.egzosn.pay.common.exception.PayErrorException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -42,6 +43,7 @@ public class AliPayMessageHandler extends BasePayMessageHandler {
|
||||
}/* else if ("WAIT_BUYER_PAY".equals(trade_status) || "TRADE_CLOSED".equals(trade_status)) {
|
||||
|
||||
}*/
|
||||
|
||||
return payService.getPayOutMessage("fail", "失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,19 +20,10 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
|
||||
// 商户收款账号
|
||||
public volatile String seller;
|
||||
//公钥
|
||||
private volatile String aliPublicKey;
|
||||
|
||||
//全渠道固定值
|
||||
public static String version = "5.0.0";
|
||||
|
||||
public String getAliPublicKey() {
|
||||
return aliPublicKey;
|
||||
}
|
||||
|
||||
public void setAliPublicKey(String aliPublicKey) {
|
||||
setKeyPublic(aliPublicKey);
|
||||
this.aliPublicKey = aliPublicKey;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,27 +32,8 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getPid()
|
||||
* @return 合作者id
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public String getPartner() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置合作者id
|
||||
* @see #setPid(String)
|
||||
* @param partner 合作者id
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPartner(String partner) {
|
||||
this.pid = partner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPid() {
|
||||
return pid;
|
||||
|
||||
@@ -14,22 +14,18 @@ import com.egzosn.pay.common.api.BasePayConfigStorage;
|
||||
public class WxPayConfigStorage extends BasePayConfigStorage {
|
||||
|
||||
|
||||
public String appSecret;
|
||||
/**
|
||||
* 应用id
|
||||
*/
|
||||
public String appid ;
|
||||
private String appid ;
|
||||
/**
|
||||
* 商户号 合作者id
|
||||
*/
|
||||
public String mchId;
|
||||
private String mchId;
|
||||
|
||||
|
||||
|
||||
|
||||
public void setAppSecret(String appSecret) {
|
||||
this.appSecret = appSecret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppid() {
|
||||
|
||||
@@ -10,28 +10,47 @@ import com.egzosn.pay.common.bean.TransactionType;
|
||||
* date 2016/10/19 22:58
|
||||
*/
|
||||
public enum WxTransactionType implements TransactionType {
|
||||
//公众号支付
|
||||
/**
|
||||
* 公众号支付
|
||||
*/
|
||||
JSAPI("pay/unifiedorder"),
|
||||
//扫码付
|
||||
/**
|
||||
* 扫码付
|
||||
*/
|
||||
NATIVE("pay/unifiedorder"),
|
||||
//移动支付
|
||||
/**
|
||||
* 移动支付
|
||||
*/
|
||||
APP("pay/unifiedorder"),
|
||||
/**
|
||||
* H5支付
|
||||
*/
|
||||
MWEB("pay/unifiedorder"),
|
||||
//刷卡付,暂未接触
|
||||
/**
|
||||
* 刷卡付
|
||||
*/
|
||||
MICROPAY("pay/micropay"),
|
||||
// TODO 2017/3/8 19:14 author: egan 交易辅助接口
|
||||
//查询订单
|
||||
/**
|
||||
* 查询订单
|
||||
*/
|
||||
QUERY("pay/orderquery"),
|
||||
//关闭订单
|
||||
/**
|
||||
* 关闭订单
|
||||
*/
|
||||
CLOSE("pay/closeorder"),
|
||||
//申请退款
|
||||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
REFUND("secapi/pay/refund"),
|
||||
//查询退款
|
||||
/**
|
||||
* 查询退款
|
||||
*/
|
||||
REFUNDQUERY("pay/refundquery"),
|
||||
//下载对账单
|
||||
DOWNLOADBILL("pay/downloadbill"),
|
||||
//不知道交易类型,主要用于回调通知,回调后不清楚交易类型,以此定义
|
||||
UNAWARE("UNAWARE")
|
||||
/**
|
||||
* 下载对账单
|
||||
*/
|
||||
DOWNLOADBILL("pay/downloadbill")
|
||||
;
|
||||
|
||||
WxTransactionType(String method) {
|
||||
|
||||
Reference in New Issue
Block a user