#569 微信支付几个查询关闭对账下载相关接口增加重载方法,以方便客户端指定更多参数

This commit is contained in:
Binary Wang 2018-05-06 12:12:24 +08:00
parent a21fdf2c78
commit 499750b3df
2 changed files with 121 additions and 103 deletions

View File

@ -1,40 +1,19 @@
package com.github.binarywang.wxpay.service;
import com.github.binarywang.wxpay.bean.WxPayApiData;
import com.github.binarywang.wxpay.bean.coupon.*;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
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.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
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.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.WxPayRefundNotifyResult;
import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult;
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.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.exception.WxPayException;
/**
* <pre>
* 微信支付相关接口.
@ -98,6 +77,23 @@ public interface WxPayService {
*/
WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxPayException;
/**
* <pre>
* 查询订单适合于需要自定义子商户号和子商户appid的情形.
* 详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
* 该接口提供所有微信支付订单的查询商户可以通过查询订单接口主动查询订单状态完成下一步的业务逻辑
* 需要调用查询接口的情况
* 当商户后台网络服务器等出现异常商户系统最终未接收到支付通知
* 调用支付接口后返回系统错误或未知交易状态情况
* 调用被扫支付API返回USERPAYING的状态
* 调用关单或撤销接口API之前需确认支付状态
* 接口地址https://api.mch.weixin.qq.com/pay/orderquery
* </pre>
*
* @param request 查询订单请求对象
*/
WxPayOrderQueryResult queryOrder(WxPayOrderQueryRequest request) throws WxPayException;
/**
* <pre>
* 关闭订单.
@ -114,6 +110,22 @@ public interface WxPayService {
*/
WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException;
/**
* <pre>
* 关闭订单适合于需要自定义子商户号和子商户appid的情形.
* 应用场景
* 以下情况需要调用关单接口
* 1. 商户订单支付失败需要生成新单号重新发起支付要对原订单号调用关单避免重复支付
* 2. 系统下单后用户支付超时系统退出不再受理避免用户继续请调用关单接口
* 注意订单生成后不能马上调用关单接口最短调用时间间隔为5分钟
* 接口地址https://api.mch.weixin.qq.com/pay/closeorder
* 是否需要证书 不需要
* </pre>
*
* @param request 关闭订单请求对象
*/
WxPayOrderCloseResult closeOrder(WxPayOrderCloseRequest request) throws WxPayException;
/**
* 调用统一下单接口并组装生成支付所需参数对象.
*
@ -185,11 +197,19 @@ public interface WxPayService {
throws WxPayException;
/**
* @see WxPayService#parseOrderNotifyResult(String).
* @deprecated use {@link WxPayService#parseOrderNotifyResult(String)} instead
* <pre>
* 微信支付-查询退款适合于需要自定义子商户号和子商户appid的情形.
* 应用场景
* 提交退款申请后通过调用该接口查询退款状态退款有一定延时用零钱支付的退款20分钟内到账
* 银行卡支付的退款3个工作日后重新查询退款状态
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5
* 接口链接https://api.mch.weixin.qq.com/pay/refundquery
* </pre>
*
* @param request 微信退款单号
* @return 退款信息
*/
@Deprecated
WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxPayException;
WxPayRefundQueryResult refundQuery(WxPayRefundQueryRequest request) throws WxPayException;
/**
* 解析支付结果通知.
@ -315,6 +335,24 @@ public interface WxPayService {
*/
WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxPayException;
/**
* <pre>
* 下载对账单适合于需要自定义子商户号和子商户appid的情形.
* 商户可以通过该接口下载历史交易清单比如掉单系统错误等导致商户侧和微信侧数据不一致通过对账单核对后可校正支付状态
* 注意
* 1微信侧未成功下单的交易不会出现在对账单中支付成功后撤销的交易会出现在对账单中跟原支付单订单号一致bill_type为REVOKED
* 2微信在次日9点启动生成前一天的对账单建议商户10点后再获取
* 3对账单中涉及金额的字段单位为
* 4对账单接口只能下载三个月以内的账单
* 接口链接https://api.mch.weixin.qq.com/pay/downloadbill
* 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">下载对账单</a>
* </pre>
*
* @param request 下载对账单请求
* @return 保存到本地的临时文件
*/
WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxPayException;
/**
* <pre>
* 提交刷卡支付.

View File

@ -1,69 +1,19 @@
package com.github.binarywang.wxpay.service.impl;
import java.io.File;
import java.io.IOException;
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 com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
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.wxpay.bean.WxPayApiData;
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.coupon.*;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult;
import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult;
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.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.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.bean.request.*;
import com.github.binarywang.wxpay.bean.result.*;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.constant.WxPayConstants.BillType;
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType;
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType;
@ -74,6 +24,18 @@ import com.github.binarywang.wxpay.util.SignUtils;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import jodd.io.ZipUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
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.TarType;
@ -145,6 +107,11 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
request.setOutRefundNo(StringUtils.trimToNull(outRefundNo));
request.setRefundId(StringUtils.trimToNull(refundId));
return this.refundQuery(request);
}
@Override
public WxPayRefundQueryResult refundQuery(WxPayRefundQueryRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/pay/refundquery";
@ -155,12 +122,6 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
return result;
}
@Override
@Deprecated
public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxPayException {
return this.parseOrderNotifyResult(xmlData);
}
@Override
public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException {
try {
@ -243,6 +204,12 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
WxPayOrderQueryRequest request = new WxPayOrderQueryRequest();
request.setOutTradeNo(StringUtils.trimToNull(outTradeNo));
request.setTransactionId(StringUtils.trimToNull(transactionId));
return this.queryOrder(request);
}
@Override
public WxPayOrderQueryResult queryOrder(WxPayOrderQueryRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/pay/orderquery";
@ -265,6 +232,12 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
WxPayOrderCloseRequest request = new WxPayOrderCloseRequest();
request.setOutTradeNo(StringUtils.trimToNull(outTradeNo));
return this.closeOrder(request);
}
@Override
public WxPayOrderCloseResult closeOrder(WxPayOrderCloseRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/pay/closeorder";
@ -425,14 +398,15 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
params.put("appid", this.getConfig().getAppId());
params.put("mch_id", this.getConfig().getMchId());
params.put("product_id", productId);
params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000));//这里需要秒10位数字
//这里需要秒10位数字
params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000));
params.put("nonce_str", String.valueOf(System.currentTimeMillis()));
String sign = SignUtils.createSign(params, null, this.getConfig().getMchKey(), false);
params.put("sign", sign);
for (String key : params.keySet()) {
codeUrl.append(key + "=" + params.get(key) + "&");
codeUrl.append(key).append("=").append(params.get(key)).append("&");
}
String content = codeUrl.toString().substring(0, codeUrl.length() - 1);
@ -475,12 +449,17 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
request.setTarType(tarType);
request.setDeviceInfo(deviceInfo);
return this.downloadBill(request);
}
@Override
public WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxPayException {
request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/pay/downloadbill";
String responseContent;
if (TarType.GZIP.equals(tarType)) {
if (TarType.GZIP.equals(request.getTarType())) {
responseContent = this.handleGzipBill(url, request.toXML());
} else {
responseContent = this.post(url, request.toXML(), false);
@ -489,7 +468,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
}
}
return this.handleBill(billType, responseContent);
return this.handleBill(request.getBillType(), responseContent);
}
private WxPayBillResult handleBill(String billType, String responseContent) {
@ -517,9 +496,10 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
this.log.error("解压zip文件出错", e);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
this.log.error("解析对账单文件时出错",e);
}
return null;
}