账单类型实现

This commit is contained in:
egzosn
2021-02-23 01:39:35 +08:00
parent db4c051007
commit b3540dc41f
16 changed files with 538 additions and 31 deletions

View File

@@ -3,13 +3,18 @@ package com.egzosn.pay.wx.api;
import java.util.Date;
import java.util.Map;
import com.egzosn.pay.common.bean.BillType;
/**
* 账单接口
*
* @author: faymanwang
* email: 1057438332@qq.com
* time: 2020/7/31 11:21
*/
public interface WxBillService {
@Deprecated
Map<String, Object> downloadbill(Date billDate, String billType, String path);
}

View File

@@ -32,6 +32,7 @@ public interface WxConst {
String MCH_ID = "mch_id";
String NONCE_STR = "nonce_str";
String OUT_TRADE_NO = "out_trade_no";
String GZIP = "GZIP";
}

View File

@@ -38,6 +38,7 @@ import static com.egzosn.pay.wx.bean.WxTransferType.TRANSFERS;
import com.alibaba.fastjson.JSONObject;
import com.egzosn.pay.common.api.BasePayService;
import com.egzosn.pay.common.bean.BillType;
import com.egzosn.pay.common.bean.MethodType;
import com.egzosn.pay.common.bean.PayMessage;
import com.egzosn.pay.common.bean.PayOrder;
@@ -58,6 +59,7 @@ import com.egzosn.pay.common.util.sign.SignUtils;
import com.egzosn.pay.common.util.sign.encrypt.RSA2;
import com.egzosn.pay.common.util.str.StringUtils;
import com.egzosn.pay.wx.bean.RedpackOrder;
import com.egzosn.pay.wx.bean.WxPayBillType;
import com.egzosn.pay.wx.bean.WxPayError;
import com.egzosn.pay.wx.bean.WxPayMessage;
import com.egzosn.pay.wx.bean.WxRefundResult;
@@ -560,10 +562,15 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
/**
* 目前只支持日账单
*
* @param billDate 账单类型商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型trade、signcustomertrade指商户基于支付宝交易收单的业务账单signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单
* @param billType 账单时间日账单格式为yyyy-MM-dd月账单格式为yyyy-MM。
* @param billDate 下载对账单的日期格式20140603
* @param billType 账单类型
* ALL默认值返回当日所有订单信息不含充值退款订单
* SUCCESS返回当日成功支付的订单不含充值退款订单
* REFUND返回当日退款订单不含充值退款订单
* RECHARGE_REFUND返回当日充值退款订单
* @return 返回支付方下载对账单的结果
*/
@Deprecated
@Override
public Map<String, Object> downloadbill(Date billDate, String billType) {
Map<String, Object> parameters = getDownloadBillParam(billDate, billType, false);
@@ -581,6 +588,43 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
return ret;
}
/**
* 目前只支持日账单
*
* @param billDate 下载对账单的日期格式20140603
* @param billType 账单类型
* ALL默认值返回当日所有订单信息不含充值退款订单
* SUCCESS返回当日成功支付的订单不含充值退款订单
* REFUND返回当日退款订单不含充值退款订单
* RECHARGE_REFUND返回当日充值退款订单
* @return 返回支付方下载对账单的结果, 如果【账单类型】为gzip的话则返回值中key为data值为gzip的输入流
*/
public Map<String, Object> downloadBill(Date billDate, BillType billType) {
//获取公共参数
Map<String, Object> parameters = getPublicParameters();
parameters.put("bill_type", billType);
//目前只支持日账单
parameters.put("bill_date", DateUtils.formatDate(billDate, DateUtils.YYYYMMDD));
setParameters(parameters, "tar_type", billType.getTarType());
//设置签名
setSign(parameters);
Map<String, Object> ret = new HashMap<String, Object>(3);
ret.put(RETURN_CODE, SUCCESS);
ret.put(RETURN_MSG_CODE, "ok");
if (StringUtils.isEmpty(billType.getTarType())) {
String respStr = requestTemplate.postForObject(getReqUrl(WxTransactionType.DOWNLOADBILL), XML.getMap2Xml(parameters), String.class);
if (respStr.indexOf("<") == 0) {
return XML.toJSONObject(respStr);
}
ret.put("data", respStr);
return ret;
}
InputStream respStream = requestTemplate.postForObject(getReqUrl(WxTransactionType.DOWNLOADBILL), XML.getMap2Xml(parameters), InputStream.class);
ret.put("data", respStream);
return ret;
}
/**
* 目前只支持日账单,增加账单返回格式
*
@@ -589,6 +633,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
* @param path 账单返回格式 账单存储的基础路径,按月切割
* @return 返回支付方下载对账单的结果
*/
@Deprecated
@Override
public Map<String, Object> downloadbill(Date billDate, String billType, String path) {
Map<String, Object> parameters = getDownloadBillParam(billDate, billType, true);
@@ -622,6 +667,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
* @return 解压后输入流
* @throws IOException IOException
*/
@Deprecated
public static InputStream uncompress(InputStream input) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPInputStream ungzip = new GZIPInputStream(input);
@@ -641,6 +687,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
* @param inputStream 输入流
* @throws IOException IOException
*/
@Deprecated
private void writeToLocal(String destination, InputStream inputStream)
throws IOException {
@@ -651,7 +698,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
if (!file.getParentFile().exists()) {
boolean result = file.getParentFile().mkdirs();
if (!result) {
System.out.println("创建失败");
LOG.warn("创建失败");
}
}
OutputStream out = new FileOutputStream(file);
@@ -662,7 +709,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
len += size;
out.write(buf, 0, size);
}
System.out.println("最终写入字节数大小:" + len);
LOG.info("最终写入字节数大小:" + len);
inputStream.close();
out.close();
}
@@ -677,6 +724,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
* @param tarType 账单返回格式 默认返回流false gzip 时候true
* @return
*/
@Deprecated
private Map<String, Object> getDownloadBillParam(Date billDate, String billType, boolean tarType) {
//获取公共参数
Map<String, Object> parameters = getPublicParameters();
@@ -689,7 +737,6 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
return parameters;
}
/**
* @param transactionIdOrBillDate 支付平台订单号或者账单日期, 具体请 类型为{@link String }或者 {@link Date },类型须强制限制,类型不对应则抛出异常{@link PayErrorException}
* @param outTradeNoBillType 商户单号或者 账单类型
@@ -704,7 +751,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
if (transactionType == WxTransactionType.DOWNLOADBILL) {
if (transactionIdOrBillDate instanceof Date) {
return downloadbill((Date) transactionIdOrBillDate, outTradeNoBillType);
return downloadBill((Date) transactionIdOrBillDate, WxPayBillType.forType(outTradeNoBillType));
}
throw new PayErrorException(new PayException(FAILURE, "非法类型异常:" + transactionIdOrBillDate.getClass()));
}
@@ -728,12 +775,12 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
* @param order 转账订单
* <pre>
*
* 注意事项:
* ◆ 当返回错误码为“SYSTEMERROR”时请不要更换商户订单号一定要使用原商户订单号重试否则可能造成重复支付等资金风险。
* ◆ XML具有可扩展性因此返回参数可能会有新增而且顺序可能不完全遵循此文档规范如果在解析回包的时候发生错误请商户务必不要换单重试请商户联系客服确认付款情况。如果有新回包字段会更新到此API文档中。
* ◆ 因为错误代码字段err_code的值后续可能会增加所以商户如果遇到回包返回新的错误码请商户务必不要换单重试请商户联系客服确认付款情况。如果有新的错误码会更新到此API文档中。
* ◆ 错误代码描述字段err_code_des只供人工定位问题时做参考系统实现时请不要依赖这个字段来做自动化处理。
* </pre>
* 注意事项:
* ◆ 当返回错误码为“SYSTEMERROR”时请不要更换商户订单号一定要使用原商户订单号重试否则可能造成重复支付等资金风险。
* ◆ XML具有可扩展性因此返回参数可能会有新增而且顺序可能不完全遵循此文档规范如果在解析回包的时候发生错误请商户务必不要换单重试请商户联系客服确认付款情况。如果有新回包字段会更新到此API文档中。
* ◆ 因为错误代码字段err_code的值后续可能会增加所以商户如果遇到回包返回新的错误码请商户务必不要换单重试请商户联系客服确认付款情况。如果有新的错误码会更新到此API文档中。
* ◆ 错误代码描述字段err_code_des只供人工定位问题时做参考系统实现时请不要依赖这个字段来做自动化处理。
* </pre>
* @return 对应的转账结果
*/
@Override

View File

@@ -0,0 +1,119 @@
package com.egzosn.pay.wx.bean;
import com.egzosn.pay.common.bean.BillType;
import com.egzosn.pay.common.util.str.StringUtils;
import com.egzosn.pay.wx.api.WxConst;
/**
* 支付宝账单类型
*
* @author Egan
* <pre>
* email egzosn@gmail.com
* date 2021/2/22
* </pre>
*/
public enum WxPayBillType implements BillType {
/**
* 商户基于支付宝交易收单的业务账单;每日账单
*/
ALL("ALL"),
/**
* 商户基于支付宝交易收单的业务账单;每日账单
*/
ALL_GZIP("ALL", WxConst.GZIP),
/**
* 商户基于支付宝交易收单的业务账单;每月账单
*/
SUCCESS(WxConst.SUCCESS),
/**
* 商户基于支付宝交易收单的业务账单;每月账单
*/
SUCCESS_GZIP(WxConst.SUCCESS, WxConst.GZIP),
/**
* 基于商户支付宝余额收入及支出等资金变动的帐务账单;每日账单
*/
REFUND("REFUND"),
/**
* 基于商户支付宝余额收入及支出等资金变动的帐务账单;每日账单
*/
REFUND_GZIP("REFUND", WxConst.GZIP),
/**
* 基于商户支付宝余额收入及支出等资金变动的帐务账单;每月账单
*/
RECHARGE_REFUND("RECHARGE_REFUND"),
/**
* 基于商户支付宝余额收入及支出等资金变动的帐务账单;每月账单
*/
RECHARGE_REFUND_GZIP("RECHARGE_REFUND", WxConst.GZIP);
/**
* 账单类型
*/
private String type;
/**
* 日期格式化表达式
*/
private String tarType;
WxPayBillType(String type) {
this.type = type;
}
WxPayBillType(String type, String tarType) {
this.type = type;
this.tarType = tarType;
}
/**
* 获取类型名称
*
* @return 类型
*/
@Override
public String getType() {
return type;
}
/**
* 获取类型对应的日期格式化表达式
*
* @return 日期格式化表达式
*/
@Override
public String getDatePattern() {
return null;
}
/**
* 获取压缩类型
*
* @return 压缩类型
*/
@Override
public String getTarType() {
return tarType;
}
/**
* 自定义属性
*
* @return 自定义属性
*/
@Override
public String getCustom() {
return null;
}
public static WxPayBillType forType(String type){
for (WxPayBillType wxPayBillType : WxPayBillType.values()){
if (wxPayBillType.getType().equals(type) && StringUtils.isEmpty(wxPayBillType.getTarType())){
return wxPayBillType;
}
}
return WxPayBillType.ALL;
}
}