mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-07-15 23:13:31 +08:00
简化代码
This commit is contained in:
parent
adf3685e88
commit
71f97c063f
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公众号appid.
|
||||||
|
*/
|
||||||
private String appId;
|
private String appId;
|
||||||
|
/**
|
||||||
|
* 服务商模式下的子商户公众账号ID.
|
||||||
|
*/
|
||||||
private String subAppId;
|
private String subAppId;
|
||||||
|
/**
|
||||||
|
* 商户号.
|
||||||
|
*/
|
||||||
private String mchId;
|
private String mchId;
|
||||||
|
/**
|
||||||
|
* 商户密钥.
|
||||||
|
*/
|
||||||
private String mchKey;
|
private String mchKey;
|
||||||
|
/**
|
||||||
|
* 服务商模式下的子商户号.
|
||||||
|
*/
|
||||||
private String subMchId;
|
private String subMchId;
|
||||||
|
/**
|
||||||
|
* 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数.
|
||||||
|
*/
|
||||||
private String notifyUrl;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 商户号
|
|
||||||
*/
|
|
||||||
public String getMchId() {
|
|
||||||
return this.mchId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMchId(String mchId) {
|
|
||||||
this.mchId = mchId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 商户密钥
|
|
||||||
*/
|
|
||||||
public String getMchKey() {
|
|
||||||
return this.mchKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMchKey(String mchKey) {
|
|
||||||
this.mchKey = mchKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 公众号appid
|
|
||||||
*/
|
|
||||||
public String getAppId() {
|
|
||||||
return this.appId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppId(String appId) {
|
|
||||||
this.appId = appId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 服务商模式下的子商户公众账号ID
|
|
||||||
*/
|
|
||||||
public String getSubAppId() {
|
|
||||||
return this.subAppId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubAppId(String subAppId) {
|
|
||||||
this.subAppId = subAppId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 服务商模式下的子商户号
|
|
||||||
*/
|
|
||||||
public String getSubMchId() {
|
|
||||||
return this.subMchId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubMchId(String subMchId) {
|
|
||||||
this.subMchId = subMchId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。
|
|
||||||
*/
|
|
||||||
public String getNotifyUrl() {
|
|
||||||
return this.notifyUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNotifyUrl(String notifyUrl) {
|
|
||||||
this.notifyUrl = notifyUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 交易类型
|
|
||||||
* <pre>
|
* <pre>
|
||||||
* JSAPI--公众号支付
|
* JSAPI--公众号支付
|
||||||
* NATIVE--原生扫码支付
|
* NATIVE--原生扫码支付
|
||||||
* APP--app支付
|
* APP--app支付
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public String getTradeType() {
|
private String tradeType;
|
||||||
return this.tradeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTradeType(String tradeType) {
|
|
||||||
this.tradeType = 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() {
|
private String signType;
|
||||||
return this.signType;
|
private SSLContext sslContext;
|
||||||
}
|
|
||||||
|
|
||||||
public void setSignType(String signType) {
|
|
||||||
this.signType = signType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SSLContext getSslContext() {
|
|
||||||
return this.sslContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSslContext(SSLContext sslContext) {
|
|
||||||
this.sslContext = sslContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信支付是否使用仿真测试环境
|
* 证书apiclient_cert.p12的文件的绝对路径.
|
||||||
|
*/
|
||||||
|
private String keyPath;
|
||||||
|
/**
|
||||||
|
* 微信支付是否使用仿真测试环境.
|
||||||
* 默认不使用
|
* 默认不使用
|
||||||
*/
|
*/
|
||||||
public boolean useSandbox() {
|
private boolean useSandboxEnv = false;
|
||||||
return this.useSandboxEnv;
|
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.request.WxPayAuthcode2OpenidRequest;
|
||||||
import com.github.binarywang.wxpay.bean.result.*;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user