@@ -117,8 +117,8 @@ public class EntPayBankRequest extends BaseWxPayRequest { | |||||
} | } | ||||
@Override | @Override | ||||
protected boolean ignoreSignType() { | |||||
return true; | |||||
protected String[] getIgnoredParamsForSign() { | |||||
return new String[]{"sign_type"}; | |||||
} | } | ||||
@Override | @Override | ||||
@@ -54,7 +54,7 @@ public class EntPayQueryRequest extends BaseWxPayRequest { | |||||
} | } | ||||
@Override | @Override | ||||
protected boolean ignoreSignType() { | |||||
return true; | |||||
protected String[] getIgnoredParamsForSign() { | |||||
return new String[]{"sign_type"}; | |||||
} | } | ||||
} | } |
@@ -198,7 +198,7 @@ public class EntPayRequest extends BaseWxPayRequest { | |||||
} | } | ||||
@Override | @Override | ||||
protected boolean ignoreSignType() { | |||||
return true; | |||||
protected String[] getIgnoredParamsForSign() { | |||||
return new String[]{"sign_type"}; | |||||
} | } | ||||
} | } |
@@ -188,17 +188,17 @@ public abstract class BaseWxPayRequest implements Serializable { | |||||
} | } | ||||
/** | /** | ||||
* 签名时,是否忽略signType. | |||||
* 签名时,是否忽略appid. | |||||
*/ | */ | ||||
protected boolean ignoreSignType() { | |||||
protected boolean ignoreAppid() { | |||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* 签名时,是否忽略appid. | |||||
* 签名时,忽略的参数. | |||||
*/ | */ | ||||
protected boolean ignoreAppid() { | |||||
return false; | |||||
protected String[] getIgnoredParamsForSign() { | |||||
return new String[0]; | |||||
} | } | ||||
/** | /** | ||||
@@ -248,7 +248,6 @@ public abstract class BaseWxPayRequest implements Serializable { | |||||
} | } | ||||
//设置签名字段的值 | //设置签名字段的值 | ||||
this.setSign(SignUtils.createSign(this, this.getSignType(), config.getMchKey(), | |||||
this.ignoreSignType())); | |||||
this.setSign(SignUtils.createSign(this, this.getSignType(), config.getMchKey(), this.getIgnoredParamsForSign())); | |||||
} | } | ||||
} | } |
@@ -16,4 +16,9 @@ public class WxPayDefaultRequest extends BaseWxPayRequest { | |||||
protected void checkConstraints() { | protected void checkConstraints() { | ||||
//do nothing | //do nothing | ||||
} | } | ||||
@Override | |||||
protected boolean ignoreAppid() { | |||||
return true; | |||||
} | |||||
} | } |
@@ -7,7 +7,7 @@ import me.chanjar.weixin.common.annotation.Required; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 拉取订单评价数据接口的请求参数封装类 | |||||
* 拉取订单评价数据接口的请求参数封装类. | |||||
* Created by BinaryWang on 2017/9/2. | * Created by BinaryWang on 2017/9/2. | ||||
* </pre> | * </pre> | ||||
* | * | ||||
@@ -20,14 +20,11 @@ import me.chanjar.weixin.common.annotation.Required; | |||||
@AllArgsConstructor | @AllArgsConstructor | ||||
@XStreamAlias("xml") | @XStreamAlias("xml") | ||||
public class WxPayQueryCommentRequest extends BaseWxPayRequest { | public class WxPayQueryCommentRequest extends BaseWxPayRequest { | ||||
@Override | |||||
protected boolean ignoreSignType() { | |||||
return true; | |||||
} | |||||
private static final long serialVersionUID = 2633600418272768186L; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 字段名:开始时间 | |||||
* 字段名:开始时间. | |||||
* 变量名:begin_time | * 变量名:begin_time | ||||
* 是否必填:是 | * 是否必填:是 | ||||
* 类型:String(19) | * 类型:String(19) | ||||
@@ -41,7 +38,7 @@ public class WxPayQueryCommentRequest extends BaseWxPayRequest { | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 字段名:结束时间 | |||||
* 字段名:结束时间. | |||||
* 变量名:end_time | * 变量名:end_time | ||||
* 是否必填:是 | * 是否必填:是 | ||||
* 类型:String(19) | * 类型:String(19) | ||||
@@ -55,7 +52,7 @@ public class WxPayQueryCommentRequest extends BaseWxPayRequest { | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 字段名:位移 | |||||
* 字段名:位移. | |||||
* 变量名:offset | * 变量名:offset | ||||
* 是否必填:是 | * 是否必填:是 | ||||
* 类型:uint(64) | * 类型:uint(64) | ||||
@@ -69,7 +66,7 @@ public class WxPayQueryCommentRequest extends BaseWxPayRequest { | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 字段名:条数 | |||||
* 字段名:条数. | |||||
* 变量名:limit | * 变量名:limit | ||||
* 是否必填:否 | * 是否必填:否 | ||||
* 类型:uint(32) | * 类型:uint(32) | ||||
@@ -81,11 +78,14 @@ public class WxPayQueryCommentRequest extends BaseWxPayRequest { | |||||
private Integer limit; | private Integer limit; | ||||
/** | /** | ||||
* 检查约束情况 | |||||
* 检查约束情况. | |||||
*/ | */ | ||||
@Override | @Override | ||||
protected void checkConstraints() throws WxPayException { | protected void checkConstraints() throws WxPayException { | ||||
} | } | ||||
@Override | |||||
protected String[] getIgnoredParamsForSign() { | |||||
return new String[]{"limit","sign_type"}; | |||||
} | |||||
} | } |
@@ -21,8 +21,8 @@ import lombok.NoArgsConstructor; | |||||
@XStreamAlias("xml") | @XStreamAlias("xml") | ||||
public class WxPaySendRedpackRequest extends BaseWxPayRequest { | public class WxPaySendRedpackRequest extends BaseWxPayRequest { | ||||
@Override | @Override | ||||
protected boolean ignoreSignType() { | |||||
return true; | |||||
protected String[] getIgnoredParamsForSign() { | |||||
return new String[]{"sign_type"}; | |||||
} | } | ||||
/** | /** | ||||
@@ -1,19 +1,46 @@ | |||||
package com.github.binarywang.wxpay.service; | package com.github.binarywang.wxpay.service; | ||||
import java.io.File; | |||||
import java.util.Date; | |||||
import java.util.Map; | |||||
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; | ||||
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.WxPayDownloadBillRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayDownloadFundFlowRequest; | |||||
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.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.WxPayBillResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayFundFlowResult; | |||||
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.WxPaySendRedpackResult; | |||||
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.exception.WxPayException; | import com.github.binarywang.wxpay.exception.WxPayException; | ||||
import java.io.File; | |||||
import java.util.Date; | |||||
import java.util.Map; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 微信支付相关接口. | * 微信支付相关接口. | ||||
@@ -530,7 +557,7 @@ public interface WxPayService { | |||||
* @param beginDate 开始时间 | * @param beginDate 开始时间 | ||||
* @param endDate 结束时间 | * @param endDate 结束时间 | ||||
* @param offset 位移 | * @param offset 位移 | ||||
* @param limit 条数 | |||||
* @param limit 条数,建议填null,否则接口会报签名错误 | |||||
*/ | */ | ||||
String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit) throws WxPayException; | String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit) throws WxPayException; | ||||
} | } |
@@ -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,8 +31,40 @@ 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.WxPayDownloadFundFlowRequest; | |||||
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.WxPayFundFlowBaseResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayFundFlowResult; | |||||
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.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; | ||||
@@ -23,17 +76,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.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; | ||||
@@ -291,7 +333,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { | |||||
configMap.put("appid", appId); | configMap.put("appid", appId); | ||||
final WxPayAppOrderResult result = WxPayAppOrderResult.builder() | final WxPayAppOrderResult result = WxPayAppOrderResult.builder() | ||||
.sign(SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), false)) | |||||
.sign(SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), null)) | |||||
.prepayId(prepayId) | .prepayId(prepayId) | ||||
.partnerId(partnerId) | .partnerId(partnerId) | ||||
.appId(appId) | .appId(appId) | ||||
@@ -317,7 +359,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { | |||||
.signType(signType) | .signType(signType) | ||||
.build(); | .build(); | ||||
payResult.setPaySign(SignUtils.createSign(payResult, signType, this.getConfig().getMchKey(), false)); | |||||
payResult.setPaySign(SignUtils.createSign(payResult, signType, this.getConfig().getMchKey(), null)); | |||||
return (T) payResult; | return (T) payResult; | ||||
} | } | ||||
@@ -368,7 +410,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { | |||||
configMap.put("noncestr", nonceStr); | configMap.put("noncestr", nonceStr); | ||||
configMap.put("appid", appId); | configMap.put("appid", appId); | ||||
// 此map用于客户端与微信服务器交互 | // 此map用于客户端与微信服务器交互 | ||||
payInfo.put("sign", SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), false)); | |||||
payInfo.put("sign", SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), null)); | |||||
payInfo.put("prepayId", prepayId); | payInfo.put("prepayId", prepayId); | ||||
payInfo.put("partnerId", partnerId); | payInfo.put("partnerId", partnerId); | ||||
payInfo.put("appId", appId); | payInfo.put("appId", appId); | ||||
@@ -382,7 +424,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { | |||||
payInfo.put("nonceStr", nonceStr); | payInfo.put("nonceStr", nonceStr); | ||||
payInfo.put("package", "prepay_id=" + prepayId); | payInfo.put("package", "prepay_id=" + prepayId); | ||||
payInfo.put("signType", SignType.MD5); | payInfo.put("signType", SignType.MD5); | ||||
payInfo.put("paySign", SignUtils.createSign(payInfo, null, this.getConfig().getMchKey(), false)); | |||||
payInfo.put("paySign", SignUtils.createSign(payInfo, null, this.getConfig().getMchKey(), null)); | |||||
} | } | ||||
return payInfo; | return payInfo; | ||||
@@ -406,7 +448,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { | |||||
params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000)); | params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000)); | ||||
params.put("nonce_str", String.valueOf(System.currentTimeMillis())); | params.put("nonce_str", String.valueOf(System.currentTimeMillis())); | ||||
String sign = SignUtils.createSign(params, null, this.getConfig().getMchKey(), false); | |||||
String sign = SignUtils.createSign(params, null, this.getConfig().getMchKey(), null); | |||||
params.put("sign", sign); | params.put("sign", sign); | ||||
for (String key : params.keySet()) { | for (String key : params.keySet()) { | ||||
@@ -632,7 +674,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { | |||||
} | } | ||||
} catch (WxPayException wxPayException) { | } catch (WxPayException wxPayException) { | ||||
throw wxPayException; | throw wxPayException; | ||||
} catch (Exception e){ | |||||
} catch (Exception e) { | |||||
this.log.error("解析对账单文件时出错", e); | this.log.error("解析对账单文件时出错", e); | ||||
throw new WxPayException("解压zip文件出错"); | throw new WxPayException("解压zip文件出错"); | ||||
} | } | ||||
@@ -1,19 +1,5 @@ | |||||
package com.github.binarywang.wxpay.service.impl; | package com.github.binarywang.wxpay.service.impl; | ||||
import com.github.binarywang.wxpay.bean.entpay.*; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayDefaultRequest; | |||||
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; | |||||
import com.github.binarywang.wxpay.exception.WxPayException; | |||||
import com.github.binarywang.wxpay.service.EntPayService; | |||||
import com.github.binarywang.wxpay.service.WxPayService; | |||||
import com.github.binarywang.wxpay.util.SignUtils; | |||||
import org.apache.commons.codec.binary.Base64; | |||||
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; | |||||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | |||||
import org.bouncycastle.openssl.PEMParser; | |||||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; | |||||
import javax.crypto.Cipher; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileReader; | import java.io.FileReader; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
@@ -21,6 +7,28 @@ import java.nio.file.Files; | |||||
import java.nio.file.Path; | import java.nio.file.Path; | ||||
import java.security.PublicKey; | import java.security.PublicKey; | ||||
import java.security.Security; | import java.security.Security; | ||||
import javax.crypto.Cipher; | |||||
import org.apache.commons.codec.binary.Base64; | |||||
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; | |||||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | |||||
import org.bouncycastle.openssl.PEMParser; | |||||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; | |||||
import com.github.binarywang.wxpay.bean.entpay.EntPayBankQueryRequest; | |||||
import com.github.binarywang.wxpay.bean.entpay.EntPayBankQueryResult; | |||||
import com.github.binarywang.wxpay.bean.entpay.EntPayBankRequest; | |||||
import com.github.binarywang.wxpay.bean.entpay.EntPayBankResult; | |||||
import com.github.binarywang.wxpay.bean.entpay.EntPayQueryRequest; | |||||
import com.github.binarywang.wxpay.bean.entpay.EntPayQueryResult; | |||||
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest; | |||||
import com.github.binarywang.wxpay.bean.entpay.EntPayResult; | |||||
import com.github.binarywang.wxpay.bean.entpay.GetPublicKeyResult; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayDefaultRequest; | |||||
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; | |||||
import com.github.binarywang.wxpay.exception.WxPayException; | |||||
import com.github.binarywang.wxpay.service.EntPayService; | |||||
import com.github.binarywang.wxpay.service.WxPayService; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
@@ -65,8 +73,8 @@ public class EntPayServiceImpl implements EntPayService { | |||||
WxPayDefaultRequest request = new WxPayDefaultRequest(); | WxPayDefaultRequest request = new WxPayDefaultRequest(); | ||||
request.setMchId(this.payService.getConfig().getMchId()); | request.setMchId(this.payService.getConfig().getMchId()); | ||||
request.setNonceStr(String.valueOf(System.currentTimeMillis())); | request.setNonceStr(String.valueOf(System.currentTimeMillis())); | ||||
request.setSign(SignUtils.createSign(request, null, this.payService.getConfig().getMchKey(), | |||||
true)); | |||||
request.checkAndSign(this.payService.getConfig()); | |||||
String url = "https://fraud.mch.weixin.qq.com/risk/getpublickey"; | String url = "https://fraud.mch.weixin.qq.com/risk/getpublickey"; | ||||
String responseContent = this.payService.post(url, request.toXML(), true); | String responseContent = this.payService.post(url, request.toXML(), true); | ||||
@@ -1,5 +1,18 @@ | |||||
package com.github.binarywang.wxpay.util; | package com.github.binarywang.wxpay.util; | ||||
import java.lang.reflect.Field; | |||||
import java.lang.reflect.Modifier; | |||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import java.util.SortedMap; | |||||
import java.util.TreeMap; | |||||
import org.apache.commons.codec.digest.DigestUtils; | |||||
import org.apache.commons.lang3.ArrayUtils; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; | import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; | ||||
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; | import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; | ||||
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; | import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; | ||||
@@ -7,12 +20,6 @@ import com.google.common.collect.Lists; | |||||
import com.google.common.collect.Maps; | import com.google.common.collect.Maps; | ||||
import com.thoughtworks.xstream.annotations.XStreamAlias; | import com.thoughtworks.xstream.annotations.XStreamAlias; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.apache.commons.codec.digest.DigestUtils; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import java.lang.reflect.Field; | |||||
import java.lang.reflect.Modifier; | |||||
import java.util.*; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
@@ -25,7 +32,7 @@ import java.util.*; | |||||
@Slf4j | @Slf4j | ||||
public class SignUtils { | public class SignUtils { | ||||
/** | /** | ||||
* 请参考并使用 {@link #createSign(Object, String, String, boolean)}. | |||||
* 请参考并使用 {@link #createSign(Object, String, String, String[])}. | |||||
*/ | */ | ||||
@Deprecated | @Deprecated | ||||
public static String createSign(Object xmlBean, String signKey) { | public static String createSign(Object xmlBean, String signKey) { | ||||
@@ -33,45 +40,43 @@ public class SignUtils { | |||||
} | } | ||||
/** | /** | ||||
* 请参考并使用 {@link #createSign(Map, String, String, boolean)}. | |||||
* 请参考并使用 {@link #createSign(Map, String, String, String[])} . | |||||
*/ | */ | ||||
@Deprecated | @Deprecated | ||||
public static String createSign(Map<String, String> params, String signKey) { | public static String createSign(Map<String, String> params, String signKey) { | ||||
return createSign(params, null, signKey, false); | |||||
return createSign(params, null, signKey, new String[0]); | |||||
} | } | ||||
/** | /** | ||||
* 微信支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3). | * 微信支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3). | ||||
* | * | ||||
* @param xmlBean Bean里的属性如果存在XML注解,则使用其作为key,否则使用变量名 | |||||
* @param signType 签名类型,如果为空,则默认为MD5 | |||||
* @param signKey 签名Key | |||||
* @param isIgnoreSignType 签名时,是否忽略signType | |||||
* @param xmlBean Bean里的属性如果存在XML注解,则使用其作为key,否则使用变量名 | |||||
* @param signType 签名类型,如果为空,则默认为MD5 | |||||
* @param signKey 签名Key | |||||
* @param ignoredParams 签名时需要忽略的特殊参数 | |||||
* @return 签名字符串 | * @return 签名字符串 | ||||
*/ | */ | ||||
public static String createSign(Object xmlBean, String signType, String signKey, boolean isIgnoreSignType) { | |||||
return createSign(xmlBean2Map(xmlBean), signType, signKey, isIgnoreSignType); | |||||
public static String createSign(Object xmlBean, String signType, String signKey, String[] ignoredParams) { | |||||
return createSign(xmlBean2Map(xmlBean), signType, signKey, ignoredParams); | |||||
} | } | ||||
/** | /** | ||||
* 微信支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3). | * 微信支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3). | ||||
* | * | ||||
* @param params 参数信息 | |||||
* @param signType 签名类型,如果为空,则默认为MD5 | |||||
* @param signKey 签名Key | |||||
* @param ignoreSignType 签名时,是否忽略signType | |||||
* @param params 参数信息 | |||||
* @param signType 签名类型,如果为空,则默认为MD5 | |||||
* @param signKey 签名Key | |||||
* @param ignoredParams 签名时需要忽略的特殊参数 | |||||
* @return 签名字符串 | * @return 签名字符串 | ||||
*/ | */ | ||||
public static String createSign(Map<String, String> params, String signType, String signKey, boolean ignoreSignType) { | |||||
public static String createSign(Map<String, String> params, String signType, String signKey, String[] ignoredParams) { | |||||
SortedMap<String, String> sortedMap = new TreeMap<>(params); | SortedMap<String, String> sortedMap = new TreeMap<>(params); | ||||
StringBuilder toSign = new StringBuilder(); | StringBuilder toSign = new StringBuilder(); | ||||
for (String key : sortedMap.keySet()) { | for (String key : sortedMap.keySet()) { | ||||
String value = params.get(key); | String value = params.get(key); | ||||
boolean shouldSign = false; | boolean shouldSign = false; | ||||
if (ignoreSignType && "sign_type".equals(key)) { | |||||
shouldSign = false; | |||||
} else if (StringUtils.isNotEmpty(value) | |||||
if (StringUtils.isNotEmpty(value) && !ArrayUtils.contains(ignoredParams, key) | |||||
&& !Lists.newArrayList("sign", "key", "xmlString", "xmlDoc", "couponList").contains(key)) { | && !Lists.newArrayList("sign", "key", "xmlString", "xmlDoc", "couponList").contains(key)) { | ||||
shouldSign = true; | shouldSign = true; | ||||
} | } | ||||
@@ -110,12 +115,12 @@ public class SignUtils { | |||||
* @return true - 签名校验成功,false - 签名校验失败 | * @return true - 签名校验成功,false - 签名校验失败 | ||||
*/ | */ | ||||
public static boolean checkSign(Map<String, String> params, String signType, String signKey) { | public static boolean checkSign(Map<String, String> params, String signType, String signKey) { | ||||
String sign = createSign(params, signType, signKey, false); | |||||
String sign = createSign(params, signType, signKey, new String[0]); | |||||
return sign.equals(params.get("sign")); | return sign.equals(params.get("sign")); | ||||
} | } | ||||
/** | /** | ||||
* 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象 | |||||
* 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象. | |||||
* | * | ||||
* @param bean 包含@XStreamAlias的xml bean对象 | * @param bean 包含@XStreamAlias的xml bean对象 | ||||
* @return map对象 | * @return map对象 | ||||
@@ -1,30 +1,52 @@ | |||||
package com.github.binarywang.wxpay.service.impl; | package com.github.binarywang.wxpay.service.impl; | ||||
import java.nio.file.Files; | |||||
import java.nio.file.Path; | |||||
import java.util.Calendar; | |||||
import java.util.Date; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.testng.annotations.*; | |||||
import com.github.binarywang.utils.qrcode.QrcodeUtils; | import com.github.binarywang.utils.qrcode.QrcodeUtils; | ||||
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.WxPayOrderNotifyResultTest; | |||||
import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult; | 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.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.WxPayMicropayRequest; | |||||
import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest; | |||||
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.WxPayBillResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayFundFlowResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult; | |||||
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.WxPaySendRedpackResult; | |||||
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult; | |||||
import com.github.binarywang.wxpay.constant.WxPayConstants.AccountType; | |||||
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; | ||||
import com.github.binarywang.wxpay.constant.WxPayConstants.AccountType; | |||||
import com.github.binarywang.wxpay.exception.WxPayException; | import com.github.binarywang.wxpay.exception.WxPayException; | ||||
import com.github.binarywang.wxpay.service.WxPayService; | import com.github.binarywang.wxpay.service.WxPayService; | ||||
import com.github.binarywang.wxpay.testbase.ApiTestModule; | import com.github.binarywang.wxpay.testbase.ApiTestModule; | ||||
import com.github.binarywang.wxpay.testbase.XmlWxPayConfig; | import com.github.binarywang.wxpay.testbase.XmlWxPayConfig; | ||||
import com.google.inject.Inject; | import com.google.inject.Inject; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.testng.annotations.*; | |||||
import java.nio.file.Files; | |||||
import java.nio.file.Path; | |||||
import java.util.Calendar; | |||||
import java.util.Date; | |||||
import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; | import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; | ||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
@@ -407,13 +429,12 @@ public class BaseWxPayServiceImplTest { | |||||
Date endDate = calendar.getTime(); | Date endDate = calendar.getTime(); | ||||
calendar.add(Calendar.DAY_OF_MONTH, -88); | calendar.add(Calendar.DAY_OF_MONTH, -88); | ||||
Date beginDate = calendar.getTime(); | Date beginDate = calendar.getTime(); | ||||
String result = this.payService.queryComment(beginDate, endDate, 0, null); | |||||
String result = this.payService.queryComment(beginDate, endDate, 0, 1); | |||||
this.logger.info(result); | this.logger.info(result); | ||||
} | } | ||||
/** | /** | ||||
* @see {@link com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResultTest} | |||||
* @throws Exception | |||||
* @see WxPayOrderNotifyResultTest#testFromXML() | |||||
*/ | */ | ||||
@Test | @Test | ||||
public void testParseOrderNotifyResult() throws Exception { | public void testParseOrderNotifyResult() throws Exception { | ||||
@@ -1,10 +1,11 @@ | |||||
package com.github.binarywang.wxpay.util; | package com.github.binarywang.wxpay.util; | ||||
import org.testng.annotations.*; | |||||
import com.google.common.base.Splitter; | import com.google.common.base.Splitter; | ||||
import org.testng.annotations.Test; | |||||
import static com.github.binarywang.wxpay.constant.WxPayConstants.SignType.HMAC_SHA256; | import static com.github.binarywang.wxpay.constant.WxPayConstants.SignType.HMAC_SHA256; | ||||
import static org.testng.Assert.assertEquals; | |||||
import static org.testng.Assert.*; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
@@ -20,7 +21,7 @@ public class SignUtilsTest { | |||||
public void testCreateSign() throws Exception { | public void testCreateSign() throws Exception { | ||||
String signKey = "192006250b4c09247ec02edce69f6a2d"; | String signKey = "192006250b4c09247ec02edce69f6a2d"; | ||||
String message = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; | String message = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; | ||||
assertEquals(SignUtils.createSign((Splitter.on("&").withKeyValueSeparator("=").split(message)), null, signKey, false), | |||||
assertEquals(SignUtils.createSign((Splitter.on("&").withKeyValueSeparator("=").split(message)), null, signKey, null), | |||||
"9A0A8659F005D6984697E2CA0A9CF3B7"); | "9A0A8659F005D6984697E2CA0A9CF3B7"); | ||||
} | } | ||||
@@ -29,7 +30,7 @@ public class SignUtilsTest { | |||||
String signKey = "192006250b4c09247ec02edce69f6a2d"; | String signKey = "192006250b4c09247ec02edce69f6a2d"; | ||||
final String message = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; | final String message = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; | ||||
String sign = SignUtils.createSign(Splitter.on("&").withKeyValueSeparator("=").split(message), | String sign = SignUtils.createSign(Splitter.on("&").withKeyValueSeparator("=").split(message), | ||||
HMAC_SHA256, signKey, false); | |||||
HMAC_SHA256, signKey, null); | |||||
assertEquals(sign, "6A9AE1657590FD6257D693A078E1C3E4BB6BA4DC30B23E0EE2496E54170DACD6"); | assertEquals(sign, "6A9AE1657590FD6257D693A078E1C3E4BB6BA4DC30B23E0EE2496E54170DACD6"); | ||||
} | } | ||||