@@ -1,181 +1,95 @@ | |||||
package com.github.binarywang.wxpay.config; | package com.github.binarywang.wxpay.config; | ||||
import com.github.binarywang.wxpay.exception.WxPayException; | |||||
import org.apache.commons.io.IOUtils; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.apache.http.ssl.SSLContexts; | |||||
import javax.net.ssl.SSLContext; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.security.KeyStore; | import java.security.KeyStore; | ||||
import javax.net.ssl.SSLContext; | |||||
import org.apache.commons.io.IOUtils; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.apache.http.ssl.SSLContexts; | |||||
import com.github.binarywang.wxpay.exception.WxPayException; | |||||
import lombok.Data; | |||||
/** | /** | ||||
* 微信支付配置 | * 微信支付配置 | ||||
* | * | ||||
* @author Binary Wang (https://github.com/binarywang) | * @author Binary Wang (https://github.com/binarywang) | ||||
*/ | */ | ||||
@Data | |||||
public class WxPayConfig { | public class WxPayConfig { | ||||
/** | /** | ||||
* http请求连接超时时间 | |||||
* http请求连接超时时间. | |||||
*/ | */ | ||||
private int httpConnectionTimeout = 5000; | private int httpConnectionTimeout = 5000; | ||||
/** | /** | ||||
* http请求数据读取等待时间 | |||||
* http请求数据读取等待时间. | |||||
*/ | */ | ||||
private int httpTimeout = 10000; | private int httpTimeout = 10000; | ||||
private String appId; | |||||
private String subAppId; | |||||
private String mchId; | |||||
private String mchKey; | |||||
private String subMchId; | |||||
private String notifyUrl; | |||||
private String tradeType; | |||||
private String signType; | |||||
private SSLContext sslContext; | |||||
private String keyPath; | |||||
private boolean useSandboxEnv = false; | |||||
private String httpProxyHost; | |||||
private Integer httpProxyPort; | |||||
private String httpProxyUsername; | |||||
private String httpProxyPassword; | |||||
public String getKeyPath() { | |||||
return keyPath; | |||||
} | |||||
/** | |||||
* 设置证书 | |||||
* | |||||
* @param keyPath apiclient_cert.p12的文件的绝对路径 | |||||
*/ | |||||
public void setKeyPath(String keyPath) { | |||||
this.keyPath = keyPath; | |||||
} | |||||
/** | /** | ||||
* 商户号 | |||||
* 公众号appid. | |||||
*/ | */ | ||||
public String getMchId() { | |||||
return this.mchId; | |||||
} | |||||
public void setMchId(String mchId) { | |||||
this.mchId = mchId; | |||||
} | |||||
private String appId; | |||||
/** | /** | ||||
* 商户密钥 | |||||
* 服务商模式下的子商户公众账号ID. | |||||
*/ | */ | ||||
public String getMchKey() { | |||||
return this.mchKey; | |||||
} | |||||
public void setMchKey(String mchKey) { | |||||
this.mchKey = mchKey; | |||||
} | |||||
private String subAppId; | |||||
/** | /** | ||||
* 公众号appid | |||||
* 商户号. | |||||
*/ | */ | ||||
public String getAppId() { | |||||
return this.appId; | |||||
} | |||||
public void setAppId(String appId) { | |||||
this.appId = appId; | |||||
} | |||||
private String mchId; | |||||
/** | /** | ||||
* 服务商模式下的子商户公众账号ID | |||||
* 商户密钥. | |||||
*/ | */ | ||||
public String getSubAppId() { | |||||
return this.subAppId; | |||||
} | |||||
public void setSubAppId(String subAppId) { | |||||
this.subAppId = subAppId; | |||||
} | |||||
private String mchKey; | |||||
/** | /** | ||||
* 服务商模式下的子商户号 | |||||
* 服务商模式下的子商户号. | |||||
*/ | */ | ||||
public String getSubMchId() { | |||||
return this.subMchId; | |||||
} | |||||
public void setSubMchId(String subMchId) { | |||||
this.subMchId = subMchId; | |||||
} | |||||
private String subMchId; | |||||
/** | /** | ||||
* 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。 | |||||
* 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数. | |||||
*/ | */ | ||||
public String getNotifyUrl() { | |||||
return this.notifyUrl; | |||||
} | |||||
public void setNotifyUrl(String notifyUrl) { | |||||
this.notifyUrl = notifyUrl; | |||||
} | |||||
private String notifyUrl; | |||||
/** | /** | ||||
* 交易类型 | |||||
* 交易类型. | |||||
* <pre> | * <pre> | ||||
* JSAPI--公众号支付 | * JSAPI--公众号支付 | ||||
* NATIVE--原生扫码支付 | * NATIVE--原生扫码支付 | ||||
* APP--app支付 | * APP--app支付 | ||||
* </pre> | * </pre> | ||||
*/ | */ | ||||
public String getTradeType() { | |||||
return this.tradeType; | |||||
} | |||||
public void setTradeType(String tradeType) { | |||||
this.tradeType = tradeType; | |||||
} | |||||
private String tradeType; | |||||
/** | /** | ||||
* 签名方式 | |||||
* 签名方式. | |||||
* 有两种HMAC_SHA256 和MD5 | * 有两种HMAC_SHA256 和MD5 | ||||
* | |||||
* @see com.github.binarywang.wxpay.constant.WxPayConstants.SignType | * @see com.github.binarywang.wxpay.constant.WxPayConstants.SignType | ||||
*/ | */ | ||||
public String getSignType() { | |||||
return this.signType; | |||||
} | |||||
public void setSignType(String signType) { | |||||
this.signType = signType; | |||||
} | |||||
public SSLContext getSslContext() { | |||||
return this.sslContext; | |||||
} | |||||
public void setSslContext(SSLContext sslContext) { | |||||
this.sslContext = sslContext; | |||||
} | |||||
private String signType; | |||||
private SSLContext sslContext; | |||||
/** | /** | ||||
* 微信支付是否使用仿真测试环境 | |||||
* 证书apiclient_cert.p12的文件的绝对路径. | |||||
*/ | |||||
private String keyPath; | |||||
/** | |||||
* 微信支付是否使用仿真测试环境. | |||||
* 默认不使用 | * 默认不使用 | ||||
*/ | */ | ||||
public boolean useSandbox() { | |||||
return this.useSandboxEnv; | |||||
} | |||||
private boolean useSandboxEnv = false; | |||||
private String httpProxyHost; | |||||
private Integer httpProxyPort; | |||||
private String httpProxyUsername; | |||||
private String httpProxyPassword; | |||||
/** | /** | ||||
* 设置是否使用沙箱仿真测试环境 | |||||
* 初始化ssl. | |||||
*/ | */ | ||||
public void setUseSandboxEnv(boolean useSandboxEnv) { | |||||
this.useSandboxEnv = useSandboxEnv; | |||||
} | |||||
public SSLContext initSSLContext() throws WxPayException { | public SSLContext initSSLContext() throws WxPayException { | ||||
if (StringUtils.isBlank(this.getMchId())) { | if (StringUtils.isBlank(this.getMchId())) { | ||||
throw new WxPayException("请确保商户号mchId已设置"); | throw new WxPayException("请确保商户号mchId已设置"); | ||||
@@ -224,57 +138,4 @@ public class WxPayConfig { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* http请求连接超时时间 | |||||
*/ | |||||
public int getHttpConnectionTimeout() { | |||||
return this.httpConnectionTimeout; | |||||
} | |||||
public void setHttpConnectionTimeout(int httpConnectionTimeout) { | |||||
this.httpConnectionTimeout = httpConnectionTimeout; | |||||
} | |||||
/** | |||||
* http请求数据读取等待时间 | |||||
*/ | |||||
public int getHttpTimeout() { | |||||
return this.httpTimeout; | |||||
} | |||||
public void setHttpTimeout(int httpTimeout) { | |||||
this.httpTimeout = httpTimeout; | |||||
} | |||||
public String getHttpProxyHost() { | |||||
return httpProxyHost; | |||||
} | |||||
public void setHttpProxyHost(String httpProxyHost) { | |||||
this.httpProxyHost = httpProxyHost; | |||||
} | |||||
public Integer getHttpProxyPort() { | |||||
return httpProxyPort; | |||||
} | |||||
public void setHttpProxyPort(Integer httpProxyPort) { | |||||
this.httpProxyPort = httpProxyPort; | |||||
} | |||||
public String getHttpProxyUsername() { | |||||
return httpProxyUsername; | |||||
} | |||||
public void setHttpProxyUsername(String httpProxyUsername) { | |||||
this.httpProxyUsername = httpProxyUsername; | |||||
} | |||||
public String getHttpProxyPassword() { | |||||
return httpProxyPassword; | |||||
} | |||||
public void setHttpProxyPassword(String httpProxyPassword) { | |||||
this.httpProxyPassword = httpProxyPassword; | |||||
} | |||||
} | } |
@@ -1,8 +1,29 @@ | |||||
package com.github.binarywang.wxpay.service.impl; | package com.github.binarywang.wxpay.service.impl; | ||||
import java.io.File; | |||||
import java.nio.charset.StandardCharsets; | |||||
import java.nio.file.Files; | |||||
import java.nio.file.Path; | |||||
import java.nio.file.Paths; | |||||
import java.util.Date; | |||||
import java.util.HashMap; | |||||
import java.util.LinkedList; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import java.util.zip.ZipException; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import com.github.binarywang.utils.qrcode.QrcodeUtils; | import com.github.binarywang.utils.qrcode.QrcodeUtils; | ||||
import com.github.binarywang.wxpay.bean.WxPayApiData; | import com.github.binarywang.wxpay.bean.WxPayApiData; | ||||
import com.github.binarywang.wxpay.bean.coupon.*; | |||||
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryRequest; | |||||
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryResult; | |||||
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendRequest; | |||||
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendResult; | |||||
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryRequest; | |||||
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryResult; | |||||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; | import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; | ||||
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; | import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; | ||||
import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult; | import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult; | ||||
@@ -10,10 +31,38 @@ import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult; | |||||
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; | import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; | ||||
import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult; | import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult; | ||||
import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; | import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; | ||||
import com.github.binarywang.wxpay.bean.request.*; | |||||
import com.github.binarywang.wxpay.bean.result.*; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayAuthcode2OpenidRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayDefaultRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayDownloadBillRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayOrderCloseRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayQueryCommentRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayRefundQueryRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayReportRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayShorturlRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; | |||||
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayAuthcode2OpenidResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayBillBaseResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayBillResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayCommonResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayOrderCloseResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayOrderReverseResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPaySandboxSignKeyResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayShorturlResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult; | |||||
import com.github.binarywang.wxpay.config.WxPayConfig; | import com.github.binarywang.wxpay.config.WxPayConfig; | ||||
import com.github.binarywang.wxpay.constant.WxPayConstants; | |||||
import com.github.binarywang.wxpay.constant.WxPayConstants.BillType; | import com.github.binarywang.wxpay.constant.WxPayConstants.BillType; | ||||
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; | import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; | ||||
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType; | import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType; | ||||
@@ -24,18 +73,6 @@ import com.github.binarywang.wxpay.util.SignUtils; | |||||
import com.google.common.base.Joiner; | import com.google.common.base.Joiner; | ||||
import com.google.common.collect.Maps; | import com.google.common.collect.Maps; | ||||
import jodd.io.ZipUtil; | import jodd.io.ZipUtil; | ||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import java.io.File; | |||||
import java.io.IOException; | |||||
import java.nio.charset.StandardCharsets; | |||||
import java.nio.file.Files; | |||||
import java.nio.file.Path; | |||||
import java.nio.file.Paths; | |||||
import java.util.*; | |||||
import java.util.zip.ZipException; | |||||
import static com.github.binarywang.wxpay.constant.WxPayConstants.QUERY_COMMENT_DATE_FORMAT; | import static com.github.binarywang.wxpay.constant.WxPayConstants.QUERY_COMMENT_DATE_FORMAT; | ||||
import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; | import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; | ||||
@@ -79,7 +116,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { | |||||
@Override | @Override | ||||
public String getPayBaseUrl() { | public String getPayBaseUrl() { | ||||
if (this.getConfig().useSandbox()) { | |||||
if (this.getConfig().isUseSandboxEnv()) { | |||||
return PAY_BASE_URL + "/sandboxnew"; | return PAY_BASE_URL + "/sandboxnew"; | ||||
} | } | ||||
@@ -16,9 +16,9 @@ public class XmlWxPayConfig extends WxPayConfig { | |||||
} | } | ||||
@Override | @Override | ||||
public boolean useSandbox() { | |||||
public boolean isUseSandboxEnv() { | |||||
//沙箱环境不成熟,有问题无法使用,暂时屏蔽掉 | //沙箱环境不成熟,有问题无法使用,暂时屏蔽掉 | ||||
// return true; | |||||
//return true; | |||||
return false; | return false; | ||||
} | } | ||||
} | } |