#355 修复为支持拉取订单评价数据接口而引入的签名bug

This commit is contained in:
Binary Wang
2017-10-17 17:40:33 +08:00
parent 447c73e43a
commit 64f0e7cf6b
11 changed files with 168 additions and 108 deletions

View File

@@ -14,6 +14,8 @@ import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import static com.github.binarywang.wxpay.constant.WxPayConstants.SignType.ALL_SIGN_TYPES;
/**
* <pre>
* Created by Binary Wang on 2016-10-24.
@@ -189,8 +191,9 @@ public abstract class WxPayBaseRequest {
* </pre>
*
* @param config 支付配置对象,用于读取相应系统配置信息
* @param isIgnoreSignType 签名时是否忽略signType
*/
public void checkAndSign(WxPayConfig config) throws WxPayException {
public void checkAndSign(WxPayConfig config, boolean isIgnoreSignType) throws WxPayException {
this.checkFields();
if (StringUtils.isBlank(getAppid())) {
@@ -209,11 +212,24 @@ public abstract class WxPayBaseRequest {
this.setSubMchId(config.getSubMchId());
}
if (StringUtils.isBlank(getSignType())) {
if (config.getSignType() != null && !ALL_SIGN_TYPES.contains(config.getSignType())) {
throw new WxPayException("非法的signType配置" + config.getSignType() + ",请检查配置!");
}
this.setSignType(StringUtils.trimToNull(config.getSignType()));
} else {
if (!ALL_SIGN_TYPES.contains(this.getSignType())) {
throw new WxPayException("非法的sign_type参数" + this.getSignType());
}
}
if (StringUtils.isBlank(getNonceStr())) {
this.setNonceStr(String.valueOf(System.currentTimeMillis()));
}
//设置签名字段的值
this.setSign(SignUtils.createSign(this, config.getMchKey(), this.signType));
this.setSign(SignUtils.createSign(this, this.getSignType(), config.getMchKey(),
isIgnoreSignType));
}
}

View File

@@ -165,12 +165,12 @@ public class WxPayRefundRequest extends WxPayBaseRequest {
private String refundDesc;
@Override
public void checkAndSign(WxPayConfig config) throws WxPayException {
public void checkAndSign(WxPayConfig config, boolean isIgnoreSignType) throws WxPayException {
if (StringUtils.isBlank(this.getOpUserId())) {
this.setOpUserId(config.getMchId());
}
super.checkAndSign(config);
super.checkAndSign(config, isIgnoreSignType);
}
@Override

View File

@@ -349,7 +349,7 @@ public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {
}
@Override
public void checkAndSign(WxPayConfig config) throws WxPayException {
public void checkAndSign(WxPayConfig config, boolean isIgnoreSignType) throws WxPayException {
if (StringUtils.isBlank(this.getNotifyURL())) {
this.setNotifyURL(config.getNotifyUrl());
}
@@ -358,7 +358,7 @@ public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {
this.setTradeType(config.getTradeType());
}
super.checkAndSign(config);
super.checkAndSign(config, isIgnoreSignType);
}
}

View File

@@ -216,12 +216,13 @@ public abstract class WxPayBaseResult {
/**
* 校验返回结果签名
*
* @param signType 签名类型
* @param checkSuccess 是否同时检查结果是否成功
*/
public void checkResult(WxPayServiceAbstractImpl wxPayService, boolean checkSuccess) throws WxPayException {
public void checkResult(WxPayServiceAbstractImpl wxPayService, String signType, boolean checkSuccess) throws WxPayException {
//校验返回结果签名
Map<String, String> map = toMap();
if (getSign() != null && !SignUtils.checkSign(map, wxPayService.getConfig().getMchKey())) {
if (getSign() != null && !SignUtils.checkSign(map, signType, wxPayService.getConfig().getMchKey())) {
this.getLogger().debug("校验结果签名失败,参数:{}", map);
throw new WxPayException("参数格式校验错误!");
}