浏览代码

#801 根据微信支付最新通知调整对账单下载接口的部分字段

master
Binary Wang 6 年前
父节点
当前提交
1d35399a7c
共有 3 个文件被更改,包括 109 次插入90 次删除
  1. +17
    -5
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillInfo.java
  2. +90
    -7
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillResult.java
  3. +2
    -78
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillBaseResult.java → weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillInfo.java 查看文件

@@ -15,7 +15,7 @@ import me.chanjar.weixin.common.util.json.WxGsonBuilder;
*/
@Data
@NoArgsConstructor
public class WxPayBillBaseResult implements Serializable {
public class WxPayBillInfo implements Serializable {
private static final long serialVersionUID = 2226245109137435453L;

@Override
@@ -36,7 +36,7 @@ public class WxPayBillBaseResult implements Serializable {
*/
private String mchId;
/**
* 商户号.
* 特约商户号.
*/
private String subMchId;
/**
@@ -72,11 +72,11 @@ public class WxPayBillBaseResult implements Serializable {
*/
private String feeType;
/**
* 金额.
* 应结订单金额.
*/
private String totalFee;
/**
* 企业红包金额.
* 代金券金额.
*/
private String couponFee;
/**
@@ -92,7 +92,7 @@ public class WxPayBillBaseResult implements Serializable {
*/
private String settlementRefundFee;
/**
* 企业红包退款金额.
* 充值券退款金额.
*/
private String couponRefundFee;
/**
@@ -119,5 +119,17 @@ public class WxPayBillBaseResult implements Serializable {
* 费率.
*/
private String poundageRate;
/**
* 订单金额.
*/
private String totalAmount;
/**
* 申请退款金额.
*/
private String appliedRefundAmount;
/**
* 费率备注.
*/
private String feeRemark;

}

+ 90
- 7
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillResult.java 查看文件

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

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import lombok.Data;
@@ -8,13 +9,14 @@ import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;

/**
* The type Wx pay bill result.
* 微信对账单结果类.
*
* @author BinaryWang
* @author DDLeEHi
*/
@Data
@NoArgsConstructor
public class WxPayBillResult implements Serializable {
private static final String TOTAL_DEAL_COUNT = "总交易单数";
private static final long serialVersionUID = -7687458652694204070L;

@Override
@@ -23,28 +25,109 @@ public class WxPayBillResult implements Serializable {
}

/**
* 对账返回对象.
* 对账明细列表.
*/
private List<WxPayBillBaseResult> wxPayBillBaseResultLst;
private List<WxPayBillInfo> billInfoList;
/**
* 总交易单数.
*/
private String totalRecord;
/**
* 总交易额.
* 应结订单总金额.
*/
private String totalFee;
/**
* 退款金额.
* 退款金额.
*/
private String totalRefundFee;
/**
* 总代金券或立减优惠退款金额.
* 充值券退款总金额.
*/
private String totalCouponFee;
/**
* 手续费总金额.
*/
private String totalPoundageFee;
/**
* 订单总金额.
*/
private String totalAmount;
/**
* 申请退款总金额.
*/
private String totalAppliedRefundFee;

/**
* 从原始对账单字符串里构造出WxPayBillResult对象.
*/
public static WxPayBillResult fromRawBillResultString(String responseContent) {
String listStr = "";
String objStr = "";
if (responseContent.contains(TOTAL_DEAL_COUNT)) {
listStr = responseContent.substring(0, responseContent.indexOf(TOTAL_DEAL_COUNT));
objStr = responseContent.substring(responseContent.indexOf(TOTAL_DEAL_COUNT));
}

List<WxPayBillInfo> results = new ArrayList<>();
// 去空格
String newStr = listStr.replaceAll(",", " ");
// 数据分组
String[] tempStr = newStr.split("`");
// 分组标题
String[] t = tempStr[0].split(" ");
// 计算循环次数
int j = tempStr.length / t.length;
// 纪录数组下标
int k = 1;
for (int i = 0; i < j; i++) {
WxPayBillInfo result = new WxPayBillInfo();
result.setTradeTime(tempStr[k].trim());
result.setAppId(tempStr[k + 1].trim());
result.setMchId(tempStr[k + 2].trim());
result.setSubMchId(tempStr[k + 3].trim());
result.setDeviceInfo(tempStr[k + 4].trim());
result.setTransactionId(tempStr[k + 5].trim());
result.setOutTradeNo(tempStr[k + 6].trim());
result.setOpenId(tempStr[k + 7].trim());
result.setTradeType(tempStr[k + 8].trim());
result.setTradeState(tempStr[k + 9].trim());
result.setBankType(tempStr[k + 10].trim());
result.setFeeType(tempStr[k + 11].trim());
result.setTotalFee(tempStr[k + 12].trim());
result.setCouponFee(tempStr[k + 13].trim());
result.setRefundId(tempStr[k + 14].trim());
result.setOutRefundNo(tempStr[k + 15].trim());
result.setSettlementRefundFee(tempStr[k + 16].trim());
result.setCouponRefundFee(tempStr[k + 17].trim());
result.setRefundChannel(tempStr[k + 18].trim());
result.setRefundState(tempStr[k + 19].trim());
result.setBody(tempStr[k + 20].trim());
result.setAttach(tempStr[k + 21].trim());
result.setPoundage(tempStr[k + 22].trim());
result.setPoundageRate(tempStr[k + 23].trim());
result.setTotalAmount(tempStr[k + 24].trim());
result.setAppliedRefundAmount(tempStr[k + 25].trim());
result.setFeeRemark(tempStr[k + 26].trim());
results.add(result);
k += t.length;
}

WxPayBillResult billResult = new WxPayBillResult();
billResult.setBillInfoList(results);

/*
* 总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额 `2,`0.02,`0.0,`0.0,`0
* 参考以上格式进行取值
*/
String[] totalTempStr = objStr.replaceAll(",", " ").split("`");
billResult.setTotalRecord(totalTempStr[1]);
billResult.setTotalFee(totalTempStr[2]);
billResult.setTotalRefundFee(totalTempStr[3]);
billResult.setTotalCouponFee(totalTempStr[4]);
billResult.setTotalPoundageFee(totalTempStr[5]);
billResult.setTotalAmount(totalTempStr[6]);
billResult.setTotalAppliedRefundFee(totalTempStr[7]);

return billResult;
}
}

+ 2
- 78
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java 查看文件

@@ -49,7 +49,6 @@ 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.WxPayFundFlowBaseResult;
@@ -91,7 +90,6 @@ import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType;
public abstract class BaseWxPayServiceImpl implements WxPayService {
private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com";
private static final String TOTAL_FUND_COUNT = "资金流水总笔数";
private static final String TOTAL_DEAL_COUNT = "总交易单数";

/**
* The Log.
@@ -554,10 +552,10 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
return null;
}

return this.handleAllBill(responseContent);
return WxPayBillResult.fromRawBillResultString(responseContent);
}

private String handleGzipBill(String url, String requestStr) throws WxPayException {
private String handleGzipBill(String url, String requestStr) {
try {
byte[] responseBytes = this.postForBytes(url, requestStr, false);
Path tempDirectory = Files.createTempDirectory("bill");
@@ -581,80 +579,6 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
return null;
}

private WxPayBillResult handleAllBill(String responseContent) {
WxPayBillResult wxPayBillResult = new WxPayBillResult();

String listStr = "";
String objStr = "";
if (responseContent.contains(TOTAL_DEAL_COUNT)) {
listStr = responseContent.substring(0, responseContent.indexOf(TOTAL_DEAL_COUNT));
objStr = responseContent.substring(responseContent.indexOf(TOTAL_DEAL_COUNT));
}

/*
* 交易时间:2017-04-06 01:00:02 公众账号ID: 商户号: 子商户号:0 设备号:WEB 微信订单号: 商户订单号:2017040519091071873216 用户标识: 交易类型:NATIVE
* 交易状态:REFUND 付款银行:CFT 货币种类:CNY 总金额:0.00 企业红包金额:0.00 微信退款单号: 商户退款单号:20170406010000933 退款金额:0.01 企业红包退款金额:0.00
* 退款类型:ORIGINAL 退款状态:SUCCESS 商品名称: 商户数据包: 手续费:0.00000 费率 :0.60%
* 参考以上格式进行取值
*/
List<WxPayBillBaseResult> wxPayBillBaseResultLst = new LinkedList<>();
// 去空格
String newStr = listStr.replaceAll(",", " ");
// 数据分组
String[] tempStr = newStr.split("`");
// 分组标题
String[] t = tempStr[0].split(" ");
// 计算循环次数
int j = tempStr.length / t.length;
// 纪录数组下标
int k = 1;
for (int i = 0; i < j; i++) {
WxPayBillBaseResult wxPayBillBaseResult = new WxPayBillBaseResult();

wxPayBillBaseResult.setTradeTime(tempStr[k].trim());
wxPayBillBaseResult.setAppId(tempStr[k + 1].trim());
wxPayBillBaseResult.setMchId(tempStr[k + 2].trim());
wxPayBillBaseResult.setSubMchId(tempStr[k + 3].trim());
wxPayBillBaseResult.setDeviceInfo(tempStr[k + 4].trim());
wxPayBillBaseResult.setTransactionId(tempStr[k + 5].trim());
wxPayBillBaseResult.setOutTradeNo(tempStr[k + 6].trim());
wxPayBillBaseResult.setOpenId(tempStr[k + 7].trim());
wxPayBillBaseResult.setTradeType(tempStr[k + 8].trim());
wxPayBillBaseResult.setTradeState(tempStr[k + 9].trim());
wxPayBillBaseResult.setBankType(tempStr[k + 10].trim());
wxPayBillBaseResult.setFeeType(tempStr[k + 11].trim());
wxPayBillBaseResult.setTotalFee(tempStr[k + 12].trim());
wxPayBillBaseResult.setCouponFee(tempStr[k + 13].trim());
wxPayBillBaseResult.setRefundId(tempStr[k + 14].trim());
wxPayBillBaseResult.setOutRefundNo(tempStr[k + 15].trim());
wxPayBillBaseResult.setSettlementRefundFee(tempStr[k + 16].trim());
wxPayBillBaseResult.setCouponRefundFee(tempStr[k + 17].trim());
wxPayBillBaseResult.setRefundChannel(tempStr[k + 18].trim());
wxPayBillBaseResult.setRefundState(tempStr[k + 19].trim());
wxPayBillBaseResult.setBody(tempStr[k + 20].trim());
wxPayBillBaseResult.setAttach(tempStr[k + 21].trim());
wxPayBillBaseResult.setPoundage(tempStr[k + 22].trim());
wxPayBillBaseResult.setPoundageRate(tempStr[k + 23].trim());
wxPayBillBaseResultLst.add(wxPayBillBaseResult);
k += t.length;
}
wxPayBillResult.setWxPayBillBaseResultLst(wxPayBillBaseResultLst);

/*
* 总交易单数,总交易额,总退款金额,总代金券或立减优惠退款金额,手续费总金额 `2,`0.02,`0.0,`0.0,`0
* 参考以上格式进行取值
*/
String totalStr = objStr.replaceAll(",", " ");
String[] totalTempStr = totalStr.split("`");
wxPayBillResult.setTotalRecord(totalTempStr[1]);
wxPayBillResult.setTotalFee(totalTempStr[2]);
wxPayBillResult.setTotalRefundFee(totalTempStr[3]);
wxPayBillResult.setTotalCouponFee(totalTempStr[4]);
wxPayBillResult.setTotalPoundageFee(totalTempStr[5]);

return wxPayBillResult;
}

@Override
public WxPayFundFlowResult downloadFundFlow(String billDate, String accountType, String tarType) throws WxPayException {



正在加载...
取消
保存