Преглед изворни кода

引入WxPayException,替代原有的异常处理类,并做相应的优化

master
Binary Wang пре 7 година
родитељ
комит
92c8a86199
9 измењених фајлова са 228 додато и 69 уклоњено
  1. +6
    -0
      weixin-java-pay/pom.xml
  2. +8
    -3
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayBaseRequest.java
  3. +2
    -2
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java
  4. +2
    -2
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java
  5. +6
    -10
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBaseResult.java
  6. +153
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/exception/WxPayException.java
  7. +20
    -20
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
  8. +25
    -26
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceImpl.java
  9. +6
    -6
      weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceImplTest.java

+ 6
- 0
weixin-java-pay/pom.xml Прегледај датотеку

@@ -27,6 +27,12 @@
<groupId>org.jodd</groupId>
<artifactId>jodd-http</artifactId>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>


+ 8
- 3
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayBaseRequest.java Прегледај датотеку

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

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.util.SignUtils;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@@ -113,9 +114,13 @@ public abstract class WxPayBaseRequest {
/**
* 检查请求参数内容,包括必填参数以及特殊约束
*/
protected void checkFields() throws WxErrorException {
protected void checkFields() throws WxPayException {
//check required fields
BeanUtils.checkRequiredFields(this);
try {
BeanUtils.checkRequiredFields(this);
} catch (WxErrorException e) {
throw new WxPayException(e.getError().getErrorMsg());
}

//check other parameters
this.checkConstraints();
@@ -210,7 +215,7 @@ public abstract class WxPayBaseRequest {
*
* @param config 支付配置对象,用于读取相应系统配置信息
*/
public void checkAndSign(WxPayConfig config) throws WxErrorException {
public void checkAndSign(WxPayConfig config) throws WxPayException {
this.checkFields();

if (StringUtils.isBlank(getAppid())) {


+ 2
- 2
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java Прегледај датотеку

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

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

@@ -169,7 +169,7 @@ public class WxPayRefundRequest extends WxPayBaseRequest {
}

@Override
public void checkAndSign(WxPayConfig config) throws WxErrorException {
public void checkAndSign(WxPayConfig config) throws WxPayException {
if (StringUtils.isBlank(this.getOpUserId())) {
this.setOpUserId(config.getMchId());
}


+ 2
- 2
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java Прегледај датотеку

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

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

@@ -458,7 +458,7 @@ public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {
}

@Override
public void checkAndSign(WxPayConfig config) throws WxErrorException {
public void checkAndSign(WxPayConfig config) throws WxPayException {
if (StringUtils.isBlank(this.getNotifyURL())) {
this.setNotifyURL(config.getNotifyUrl());
}


+ 6
- 10
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBaseResult.java Прегледај датотеку

@@ -1,13 +1,12 @@
package com.github.binarywang.wxpay.bean.result;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.github.binarywang.wxpay.util.SignUtils;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import org.apache.commons.lang3.StringUtils;
@@ -308,12 +307,12 @@ public abstract class WxPayBaseResult {
/**
* 校验返回结果签名
*/
public void checkResult(WxPayServiceImpl wxPayService) throws WxErrorException {
public void checkResult(WxPayServiceImpl wxPayService) throws WxPayException {
//校验返回结果签名
Map<String, String> map = toMap();
if (getSign() != null && !SignUtils.checkSign(map, wxPayService.getConfig().getMchKey())) {
this.getLogger().debug("校验结果签名失败,参数:{}", map);
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build());
throw new WxPayException("参数格式校验错误!");
}

//校验结果是否成功
@@ -336,12 +335,9 @@ public abstract class WxPayBaseResult {
errorMsg.append(",错误详情:").append(getErrCodeDes());
}

WxError error = WxError.newBuilder()
.setErrorCode(-1)
.setErrorMsg(errorMsg.toString())
.build();
this.getLogger().error("\n结果业务代码异常,返回結果:{},\n{}", map, error);
throw new WxErrorException(error);
this.getLogger().error("\n结果业务代码异常,返回結果:{},\n{}",
map, errorMsg.toString());
throw WxPayException.from(this);
}
}
}

+ 153
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/exception/WxPayException.java Прегледај датотеку

@@ -0,0 +1,153 @@
package com.github.binarywang.wxpay.exception;

import com.github.binarywang.wxpay.bean.result.WxPayBaseResult;
import com.google.common.base.Joiner;

/**
* <pre>
* 微信支付异常结果类
* Created by Binary Wang on 2017-6-6.
* </pre>
*/
public class WxPayException extends Exception {
private String customErrorMsg;
/**
* 返回状态码
*/
private String returnCode;
/**
* 返回信息
*/
private String returnMsg;

/**
* 业务结果
*/
private String resultCode;

/**
* 错误代码
*/
private String errCode;

/**
* 错误代码描述
*/
private String errCodeDes;

/**
* 微信支付返回的结果xml字符串
*/
private String xmlString;

public WxPayException(String customErrorMsg) {
super(customErrorMsg);
this.customErrorMsg = customErrorMsg;
}

private WxPayException(Builder builder) {
super(builder.buildErrorMsg());
returnCode = builder.returnCode;
returnMsg = builder.returnMsg;
resultCode = builder.resultCode;
errCode = builder.errCode;
errCodeDes = builder.errCodeDes;
xmlString = builder.xmlString;
}

public static WxPayException from(WxPayBaseResult payBaseResult) {
return WxPayException.newBuilder()
.xmlString(payBaseResult.getXmlString())
.returnMsg(payBaseResult.getReturnMsg())
.returnCode(payBaseResult.getReturnCode())
.resultCode(payBaseResult.getResultCode())
.errCode(payBaseResult.getErrCode())
.errCodeDes(payBaseResult.getErrCodeDes())
.build();
}

public String getXmlString() {
return this.xmlString;
}

public String getReturnCode() {
return this.returnCode;
}

public String getReturnMsg() {
return this.returnMsg;
}

public String getResultCode() {
return this.resultCode;
}

public String getErrCode() {
return this.errCode;
}

public String getErrCodeDes() {
return this.errCodeDes;
}

public static Builder newBuilder() {
return new Builder();
}

public static final class Builder {
private String returnCode;
private String returnMsg;
private String resultCode;
private String errCode;
private String errCodeDes;
private String xmlString;

private Builder() {
}

public Builder returnCode(String returnCode) {
this.returnCode = returnCode;
return this;
}

public Builder returnMsg(String returnMsg) {
this.returnMsg = returnMsg;
return this;
}

public Builder resultCode(String resultCode) {
this.resultCode = resultCode;
return this;
}

public Builder errCode(String errCode) {
this.errCode = errCode;
return this;
}

public Builder errCodeDes(String errCodeDes) {
this.errCodeDes = errCodeDes;
return this;
}

public Builder xmlString(String xmlString) {
this.xmlString = xmlString;
return this;
}

public WxPayException build() {
return new WxPayException(this);
}

public String buildErrorMsg() {
return Joiner.on(",").skipNulls().join(new String[]{
returnCode == null ? null : String.format("返回代码:[%s]", returnCode),
returnMsg == null ? null : String.format("返回信息:[%s]", returnMsg),
resultCode == null ? null : String.format("结果代码:[%s]", resultCode),
errCode == null ? null : String.format("错误代码:[%s]", errCode),
errCodeDes == null ? null : String.format("错误详情:[%s]", errCodeDes),
xmlString == null ? null : "微信返回的原始报文:\n" + xmlString,
});
}
}
}

+ 20
- 20
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java Прегледај датотеку

@@ -3,7 +3,7 @@ package com.github.binarywang.wxpay.service;
import com.github.binarywang.wxpay.bean.request.*;
import com.github.binarywang.wxpay.bean.result.*;
import com.github.binarywang.wxpay.config.WxPayConfig;
import me.chanjar.weixin.common.exception.WxErrorException;
import com.github.binarywang.wxpay.exception.WxPayException;

import java.io.File;
import java.util.Map;
@@ -33,7 +33,7 @@ public interface WxPayService {
* @param transactionId 微信订单号
* @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。
*/
WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException;
WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxPayException;

/**
* <pre>
@@ -49,7 +49,7 @@ public interface WxPayService {
*
* @param outTradeNo 商户系统内部的订单号
*/
WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException;
WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException;

/**
* 统一下单(详见http://com.github.binarywang.wechat.pay.bean.pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
@@ -58,7 +58,7 @@ public interface WxPayService {
*
* @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置)
*/
WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException;
WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxPayException;

/**
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
@@ -66,7 +66,7 @@ public interface WxPayService {
*
* @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置)
*/
Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxErrorException;
Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxPayException;

/**
* 获取配置
@@ -88,7 +88,7 @@ public interface WxPayService {
* @param request 请求对象
* @return 退款操作结果
*/
WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException;
WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayException;

/**
* <pre>
@@ -108,13 +108,13 @@ public interface WxPayService {
* @return 退款信息
*/
WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, String outRefundNo, String refundId)
throws WxErrorException;
throws WxPayException;

/**
* 读取支付结果通知
* 详见http://com.github.binarywang.wechat.pay.bean.pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
*/
WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException;
WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxPayException;

/**
* 发送微信红包给个人用户
@@ -128,7 +128,7 @@ public interface WxPayService {
*
* @param request 请求对象
*/
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException;
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException;

/**
* <pre>
@@ -141,7 +141,7 @@ public interface WxPayService {
*
* @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890
*/
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException;
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;

/**
* <pre>
@@ -155,7 +155,7 @@ public interface WxPayService {
*
* @param request 请求对象
*/
WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException;
WxEntPayResult entPay(WxEntPayRequest request) throws WxPayException;

/**
* <pre>
@@ -167,7 +167,7 @@ public interface WxPayService {
*
* @param partnerTradeNo 商户订单号
*/
WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException;
WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException;

/**
* <pre>
@@ -225,7 +225,7 @@ public interface WxPayService {
* 是否需要证书:不需要
* </pre>
*/
void report(WxPayReportRequest request) throws WxErrorException;
void report(WxPayReportRequest request) throws WxPayException;

/**
* <pre>
@@ -246,7 +246,7 @@ public interface WxPayService {
* @param deviceInfo 设备号 device_info 非必传参数,终端设备号
* @return 保存到本地的临时文件
*/
WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException;
WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxPayException;

/**
* <pre>
@@ -260,7 +260,7 @@ public interface WxPayService {
* 是否需要证书:不需要。
* </pre>
*/
WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxErrorException;
WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxPayException;

/**
* <pre>
@@ -276,7 +276,7 @@ public interface WxPayService {
* 是否需要证书:请求需要双向证书。
* </pre>
*/
WxPayOrderReverseResult reverseOrder(WxPayOrderReverseRequest request) throws WxErrorException;
WxPayOrderReverseResult reverseOrder(WxPayOrderReverseRequest request) throws WxPayException;

/**
* <pre>
@@ -291,7 +291,7 @@ public interface WxPayService {
*
* @param request 请求对象
*/
String shorturl(WxPayShorturlRequest request) throws WxErrorException;
String shorturl(WxPayShorturlRequest request) throws WxPayException;

/**
* <pre>
@@ -301,7 +301,7 @@ public interface WxPayService {
* @param longUrl 需要被压缩的网址
* @see WxPayService#shorturl(WxPayShorturlRequest)
*/
String shorturl(String longUrl) throws WxErrorException;
String shorturl(String longUrl) throws WxPayException;

/**
* <pre>
@@ -316,7 +316,7 @@ public interface WxPayService {
* @param request 请求对象
* @return openid
*/
String authcode2Openid(WxPayAuthcode2OpenidRequest request) throws WxErrorException;
String authcode2Openid(WxPayAuthcode2OpenidRequest request) throws WxPayException;

/**
* <pre>
@@ -327,5 +327,5 @@ public interface WxPayService {
* @return openid
* @see WxPayService#authcode2Openid(WxPayAuthcode2OpenidRequest)
*/
String authcode2Openid(String authCode) throws WxErrorException;
String authcode2Openid(String authCode) throws WxPayException;
}

+ 25
- 26
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceImpl.java Прегледај датотеку

@@ -4,14 +4,13 @@ import com.github.binarywang.utils.qrcode.QrcodeUtils;
import com.github.binarywang.wxpay.bean.request.*;
import com.github.binarywang.wxpay.bean.result.*;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.util.SignUtils;
import com.google.common.collect.Maps;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import jodd.http.net.SSLSocketHttpConnectionProvider;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -55,7 +54,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException {
public WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/secapi/pay/refund";
@@ -67,7 +66,7 @@ public class WxPayServiceImpl implements WxPayService {

@Override
public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, String outRefundNo, String refundId)
throws WxErrorException {
throws WxPayException {
WxPayRefundQueryRequest request = new WxPayRefundQueryRequest();
request.setOutTradeNo(StringUtils.trimToNull(outTradeNo));
request.setTransactionId(StringUtils.trimToNull(transactionId));
@@ -85,24 +84,24 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException {
public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxPayException {
try {
log.debug("微信支付回调参数详细:{}", xmlData);
WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
log.debug("微信支付回调结果对象:{}", result);
result.checkResult(this);
return result;
} catch (WxErrorException e) {
} catch (WxPayException e) {
log.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new WxErrorException(WxError.newBuilder().setErrorMsg("发生异常" + e.getMessage()).build());
throw new WxPayException("发生异常," + e.getMessage());
}
}

@Override
public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException {
public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack";
@@ -119,7 +118,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException {
public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException {
WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest();
request.setMchBillNo(mchBillNo);
request.setBillType("MCHT");
@@ -133,7 +132,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException {
public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxPayException {
WxPayOrderQueryRequest request = new WxPayOrderQueryRequest();
request.setOutTradeNo(StringUtils.trimToNull(outTradeNo));
request.setTransactionId(StringUtils.trimToNull(transactionId));
@@ -142,7 +141,7 @@ public class WxPayServiceImpl implements WxPayService {
String url = this.getPayBaseUrl() + "/pay/orderquery";
String responseContent = this.post(url, request.toXML());
if (StringUtils.isBlank(responseContent)) {
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无响应结果").build());
throw new WxPayException("无响应结果");
}

WxPayOrderQueryResult result = WxPayBaseResult.fromXML(responseContent, WxPayOrderQueryResult.class);
@@ -152,7 +151,7 @@ public class WxPayServiceImpl implements WxPayService {
}

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

@Override
public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException {
public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/pay/unifiedorder";
@@ -181,7 +180,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxErrorException {
public Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxPayException {
WxPayUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request);
String prepayId = unifiedOrderResult.getPrepayId();
if (StringUtils.isBlank(prepayId)) {
@@ -225,7 +224,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException {
public WxEntPayResult entPay(WxEntPayRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/promotion/transfers";

@@ -236,7 +235,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException {
public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException {
WxEntPayQueryRequest request = new WxEntPayQueryRequest();
request.setPartnerTradeNo(partnerTradeNo);
request.checkAndSign(this.getConfig());
@@ -291,7 +290,7 @@ public class WxPayServiceImpl implements WxPayService {
return QrcodeUtils.createQrcode(content, sideLength, logoFile);
}

public void report(WxPayReportRequest request) throws WxErrorException {
public void report(WxPayReportRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/payitil/report";
@@ -301,7 +300,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException {
public WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxPayException {
WxPayDownloadBillRequest request = new WxPayDownloadBillRequest();
request.setBillType(billType);
request.setBillDate(billDate);
@@ -394,7 +393,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxErrorException {
public WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/pay/micropay";
@@ -405,7 +404,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public WxPayOrderReverseResult reverseOrder(WxPayOrderReverseRequest request) throws WxErrorException {
public WxPayOrderReverseResult reverseOrder(WxPayOrderReverseRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/secapi/pay/reverse";
@@ -416,7 +415,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public String shorturl(WxPayShorturlRequest request) throws WxErrorException {
public String shorturl(WxPayShorturlRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/tools/shorturl";
@@ -427,12 +426,12 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public String shorturl(String longUrl) throws WxErrorException {
public String shorturl(String longUrl) throws WxPayException {
return this.shorturl(new WxPayShorturlRequest(longUrl));
}

@Override
public String authcode2Openid(WxPayAuthcode2OpenidRequest request) throws WxErrorException {
public String authcode2Openid(WxPayAuthcode2OpenidRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/tools/authcodetoopenid";
@@ -443,7 +442,7 @@ public class WxPayServiceImpl implements WxPayService {
}

@Override
public String authcode2Openid(String authCode) throws WxErrorException {
public String authcode2Openid(String authCode) throws WxPayException {
return this.authcode2Openid(new WxPayAuthcode2OpenidRequest(authCode));
}

@@ -472,7 +471,7 @@ public class WxPayServiceImpl implements WxPayService {
/**
* ecoolper(20170418),修改为jodd-http方式
*/
private String postWithKey(String url, String requestStr) throws WxErrorException {
private String postWithKey(String url, String requestStr) throws WxPayException {
try {
SSLContext sslContext = this.getConfig().getSslContext();
if (null == sslContext) {
@@ -487,7 +486,7 @@ public class WxPayServiceImpl implements WxPayService {
return result;
} catch (Exception e) {
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e);
throw new WxPayException(e.getMessage());
}
}



+ 6
- 6
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceImplTest.java Прегледај датотеку

@@ -3,11 +3,11 @@ package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.utils.qrcode.QrcodeUtils;
import com.github.binarywang.wxpay.bean.request.*;
import com.github.binarywang.wxpay.bean.result.*;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.testbase.ApiTestModule;
import com.github.binarywang.wxpay.testbase.XmlWxPayConfig;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.*;
@@ -133,7 +133,7 @@ public class WxPayServiceImplTest {
* Test method for {@link WxPayService#unifiedOrder(WxPayUnifiedOrderRequest)}.
*/
@Test
public void testUnifiedOrder() throws WxErrorException {
public void testUnifiedOrder() throws WxPayException {
WxPayUnifiedOrderResult result = this.payService
.unifiedOrder(WxPayUnifiedOrderRequest.newBuilder()
.body("我去")
@@ -151,7 +151,7 @@ public class WxPayServiceImplTest {
* Test method for {@link WxPayService#queryOrder(java.lang.String, java.lang.String)} .
*/
@Test
public void testQueryOrder() throws WxErrorException {
public void testQueryOrder() throws WxPayException {
this.logger.info(this.payService.queryOrder("11212121", null).toString());
this.logger.info(this.payService.queryOrder(null, "11111").toString());
}
@@ -160,7 +160,7 @@ public class WxPayServiceImplTest {
* Test method for {@link WxPayService#closeOrder(java.lang.String)} .
*/
@Test
public void testCloseOrder() throws WxErrorException {
public void testCloseOrder() throws WxPayException {
this.logger.info(this.payService.closeOrder("11212121").toString());
}

@@ -168,7 +168,7 @@ public class WxPayServiceImplTest {
* Test method for {@link WxPayService#entPay(WxEntPayRequest)}.
*/
@Test
public void testEntPay() throws WxErrorException {
public void testEntPay() throws WxPayException {
WxEntPayRequest request = new WxEntPayRequest();
this.logger.info(this.payService.entPay(request).toString());
}
@@ -177,7 +177,7 @@ public class WxPayServiceImplTest {
* Test method for {@link WxPayService#queryEntPay(java.lang.String)}.
*/
@Test
public void testQueryEntPay() throws WxErrorException {
public void testQueryEntPay() throws WxPayException {
this.logger.info(this.payService.queryEntPay("11212121").toString());
}



Loading…
Откажи
Сачувај