改写部分使用StringUtils.equalsAny方法的代码,避免客户端jar包冲突引起不必要的麻烦

This commit is contained in:
Binary Wang 2017-09-22 10:58:06 +08:00
parent 3e75064c51
commit 7bb3a1270d
2 changed files with 7 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.impl.WxPayServiceAbstractImpl;
import com.github.binarywang.wxpay.util.SignUtils;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@ -25,6 +26,7 @@ import javax.xml.xpath.XPathFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
@ -222,9 +224,10 @@ public abstract class WxPayBaseResult {
throw new WxPayException("参数格式校验错误!");
}
List<String> successStrings = Lists.newArrayList("SUCCESS", "");
//校验结果是否成功
if (!StringUtils.equalsAny(StringUtils.trimToEmpty(getReturnCode()).toUpperCase(), "SUCCESS", "")
|| !StringUtils.equalsAny(StringUtils.trimToEmpty(getResultCode()).toUpperCase(), "SUCCESS", "")) {
if (!successStrings.contains(StringUtils.trimToEmpty(getReturnCode()).toUpperCase())
|| !successStrings.contains(StringUtils.trimToEmpty(getResultCode()).toUpperCase())) {
StringBuilder errorMsg = new StringBuilder();
if (getReturnCode() != null) {
errorMsg.append("返回代码:").append(getReturnCode());

View File

@ -1,10 +1,10 @@
package com.github.binarywang.wxpay.util;
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType;
import com.google.common.collect.Lists;
import me.chanjar.weixin.common.util.BeanUtils;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
@ -56,8 +56,7 @@ public class SignUtils {
StringBuilder toSign = new StringBuilder();
for (String key : sortedMap.keySet()) {
String value = params.get(key);
if (StringUtils.isNotEmpty(value)
&& !StringUtils.equalsAny(key, "sign", "key", "sign_type")) {
if (!Lists.newArrayList("sign", "key", "sign_type").contains(key)) {
toSign.append(key).append("=").append(value).append("&");
}
}