浏览代码

非法参数的异常统一使用WxPayException

master
Binary Wang 7 年前
父节点
当前提交
70d90c8b9b
共有 11 个文件被更改,包括 28 次插入25 次删除
  1. +1
    -1
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayBaseRequest.java
  2. +4
    -3
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayDownloadBillRequest.java
  3. +3
    -2
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderQueryRequest.java
  4. +3
    -2
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderReverseRequest.java
  5. +3
    -2
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundQueryRequest.java
  6. +3
    -3
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java
  7. +4
    -4
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java
  8. +3
    -4
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBaseResult.java
  9. +2
    -2
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
  10. +1
    -1
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImpl.java
  11. +1
    -1
      weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java

+ 1
- 1
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayBaseRequest.java 查看文件

@@ -122,7 +122,7 @@ public abstract class WxPayBaseRequest {
/**
* 检查约束情况
*/
protected abstract void checkConstraints();
protected abstract void checkConstraints() throws WxPayException;

public String getAppid() {
return this.appid;


+ 4
- 3
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayDownloadBillRequest.java 查看文件

@@ -1,5 +1,6 @@
package com.github.binarywang.wxpay.bean.request;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.annotation.Required;
import org.apache.commons.lang3.ArrayUtils;
@@ -128,13 +129,13 @@ public class WxPayDownloadBillRequest extends WxPayBaseRequest {
}

@Override
protected void checkConstraints() {
protected void checkConstraints() throws WxPayException {
if (StringUtils.isNotBlank(this.getTarType()) && !"GZIP".equals(this.getTarType())) {
throw new IllegalArgumentException("tar_type值如果存在,只能为GZIP");
throw new WxPayException("tar_type值如果存在,只能为GZIP");
}

if (!ArrayUtils.contains(BILL_TYPE, this.getBillType())) {
throw new IllegalArgumentException(String.format("bill_tpye目前必须为%s其中之一,实际值:%s",
throw new WxPayException(String.format("bill_tpye目前必须为%s其中之一,实际值:%s",
Arrays.toString(BILL_TYPE), this.getBillType()));
}
}


+ 3
- 2
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderQueryRequest.java 查看文件

@@ -1,5 +1,6 @@
package com.github.binarywang.wxpay.bean.request;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.lang3.StringUtils;

@@ -64,10 +65,10 @@ public class WxPayOrderQueryRequest extends WxPayBaseRequest {
}

@Override
protected void checkConstraints() {
protected void checkConstraints() throws WxPayException {
if ((StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)) ||
(StringUtils.isNotBlank(transactionId) && StringUtils.isNotBlank(outTradeNo))) {
throw new IllegalArgumentException("transaction_id 和 out_trade_no 不能同时存在或同时为空,必须二选一");
throw new WxPayException("transaction_id 和 out_trade_no 不能同时存在或同时为空,必须二选一");
}
}
}

+ 3
- 2
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayOrderReverseRequest.java 查看文件

@@ -1,5 +1,6 @@
package com.github.binarywang.wxpay.bean.request;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.lang3.StringUtils;

@@ -91,9 +92,9 @@ public class WxPayOrderReverseRequest extends WxPayBaseRequest {
}

@Override
protected void checkConstraints() {
protected void checkConstraints() throws WxPayException {
if (StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)) {
throw new IllegalArgumentException("transaction_id 和 out_trade_no不能同时为空!");
throw new WxPayException("transaction_id 和 out_trade_no不能同时为空!");
}
}



+ 3
- 2
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundQueryRequest.java 查看文件

@@ -1,5 +1,6 @@
package com.github.binarywang.wxpay.bean.request;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.lang3.StringUtils;

@@ -135,12 +136,12 @@ public class WxPayRefundQueryRequest extends WxPayBaseRequest {
}

@Override
protected void checkConstraints() {
protected void checkConstraints() throws WxPayException {
if ((StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)
&& StringUtils.isBlank(outRefundNo) && StringUtils.isBlank(refundId)) ||
(StringUtils.isNotBlank(transactionId) && StringUtils.isNotBlank(outTradeNo)
&& StringUtils.isNotBlank(outRefundNo) && StringUtils.isNotBlank(refundId))) {
throw new IllegalArgumentException("transaction_id,out_trade_no,out_refund_no,refund_id 必须四选一");
throw new WxPayException("transaction_id,out_trade_no,out_refund_no,refund_id 必须四选一");
}

}


+ 3
- 3
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java 查看文件

@@ -271,16 +271,16 @@ public class WxPayRefundRequest extends WxPayBaseRequest {
}

@Override
protected void checkConstraints() {
protected void checkConstraints() throws WxPayException {
if (StringUtils.isNotBlank(this.getRefundAccount())) {
if (!ArrayUtils.contains(REFUND_ACCOUNT, this.getRefundAccount())) {
throw new IllegalArgumentException(String.format("refund_account目前必须为%s其中之一,实际值:%s",
throw new WxPayException(String.format("refund_account目前必须为%s其中之一,实际值:%s",
Arrays.toString(REFUND_ACCOUNT), this.getRefundAccount()));
}
}

if (StringUtils.isBlank(this.getOutTradeNo()) && StringUtils.isBlank(this.getTransactionId())) {
throw new IllegalArgumentException("transaction_id 和 out_trade_no 不能同时为空,必须提供一个");
throw new WxPayException("transaction_id 和 out_trade_no 不能同时为空,必须提供一个");
}
}



+ 4
- 4
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java 查看文件

@@ -500,18 +500,18 @@ public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {
}

@Override
protected void checkConstraints() {
protected void checkConstraints() throws WxPayException {
// if (!ArrayUtils.contains(TRADE_TYPES, this.getTradeType())) {
// throw new IllegalArgumentException(String.format("trade_type目前必须为%s其中之一,实际值:%s",
// throw new WxPayException(String.format("trade_type目前必须为%s其中之一,实际值:%s",
// Arrays.toString(TRADE_TYPES), this.getTradeType()));
// }

if ("JSAPI".equals(this.getTradeType()) && this.getOpenid() == null) {
throw new IllegalArgumentException("当 trade_type是'JSAPI'时未指定openid");
throw new WxPayException("当 trade_type是'JSAPI'时未指定openid");
}

if ("NATIVE".equals(this.getTradeType()) && this.getProductId() == null) {
throw new IllegalArgumentException("当 trade_type是'NATIVE'时未指定product_id");
throw new WxPayException("当 trade_type是'NATIVE'时未指定product_id");
}
}



+ 3
- 4
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBaseResult.java 查看文件

@@ -316,8 +316,8 @@ public abstract class WxPayBaseResult {
}

//校验结果是否成功
if (!"SUCCESS".equalsIgnoreCase(getReturnCode())
|| !"SUCCESS".equalsIgnoreCase(getResultCode())) {
if (!StringUtils.equalsAny(StringUtils.trimToEmpty(getReturnCode()).toUpperCase(), "SUCCESS", "")
|| !StringUtils.equalsAny(StringUtils.trimToEmpty(getResultCode()).toUpperCase(), "SUCCESS", "")) {
StringBuilder errorMsg = new StringBuilder();
if (getReturnCode() != null) {
errorMsg.append("返回代码:").append(getReturnCode());
@@ -335,8 +335,7 @@ public abstract class WxPayBaseResult {
errorMsg.append(",错误详情:").append(getErrCodeDes());
}

this.getLogger().error("\n结果业务代码异常,返回結果:{},\n{}",
map, errorMsg.toString());
this.getLogger().error("\n结果业务代码异常,返回結果:{},\n{}", map, errorMsg.toString());
throw WxPayException.from(this);
}
}


+ 2
- 2
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java 查看文件

@@ -160,11 +160,11 @@ public class WxPayConfig {

public SSLContext initSSLContext() throws WxPayException {
if (StringUtils.isBlank(mchId)) {
throw new IllegalArgumentException("请确保商户号mchId已设置");
throw new WxPayException("请确保商户号mchId已设置");
}

if (StringUtils.isBlank(this.keyPath)) {
throw new IllegalArgumentException("请确保证书文件地址keyPath已配置");
throw new WxPayException("请确保证书文件地址keyPath已配置");
}

InputStream inputStream;


+ 1
- 1
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImpl.java 查看文件

@@ -161,7 +161,7 @@ public abstract class WxPayServiceAbstractImpl implements WxPayService {
@Override
public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException {
if (StringUtils.isBlank(outTradeNo)) {
throw new IllegalArgumentException("out_trade_no不能为空");
throw new WxPayException("out_trade_no不能为空");
}

WxPayOrderCloseRequest request = new WxPayOrderCloseRequest();


+ 1
- 1
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java 查看文件

@@ -139,7 +139,7 @@ public class WxPayServiceAbstractImplTest {
.unifiedOrder(WxPayUnifiedOrderRequest.newBuilder()
.body("我去")
.totalFee(1)
.spbillCreateIp("111111")
.spbillCreateIp("11.1.11.1")
.notifyURL("111111")
.tradeType("JSAPI")
.openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid())


正在加载...
取消
保存