@@ -0,0 +1,257 @@ | |||||
package com.github.binarywang.wxpay.bean.result; | |||||
import java.io.Serializable; | |||||
public class WxPayBillBaseResult implements Serializable | |||||
{ | |||||
/* | |||||
* 交易时间: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% | |||||
*/ | |||||
private static final long serialVersionUID = 1L; | |||||
/**交易时间*/ | |||||
private String tradeTime; | |||||
/**公众账号ID*/ | |||||
private String appId; | |||||
/**商户号*/ | |||||
private String mchId; | |||||
/**子商户号*/ | |||||
private String subMchId; | |||||
/**设备号*/ | |||||
private String deviceInfo; | |||||
/**微信订单号*/ | |||||
private String transationId; | |||||
/**商户订单号*/ | |||||
private String outTradeNo; | |||||
/**用户标识*/ | |||||
private String openId; | |||||
/**交易类型*/ | |||||
private String tradeType; | |||||
/**交易状态*/ | |||||
private String tradeState ; | |||||
/**付款银行*/ | |||||
private String bankType; | |||||
/**货币种类*/ | |||||
private String feeType; | |||||
/**总金额*/ | |||||
private String totalFee; | |||||
/**企业红包金额*/ | |||||
private String couponFee; | |||||
/**微信退款单号*/ | |||||
private String refundId; | |||||
/**商户退款单号*/ | |||||
private String outRefundNo; | |||||
/**退款金额*/ | |||||
private String settlementRefundFee; | |||||
/**企业红包退款金额*/ | |||||
private String couponRefundFee; | |||||
/**退款类型*/ | |||||
private String refundChannel; | |||||
/**退款状态*/ | |||||
private String refundState; | |||||
/**商品名称*/ | |||||
private String body; | |||||
/**商户数据包*/ | |||||
private String attach; | |||||
/**手续费*/ | |||||
private String poundage; | |||||
/**费率*/ | |||||
private String poundageRate; | |||||
public String getTradeTime() | |||||
{ | |||||
return tradeTime; | |||||
} | |||||
public void setTradeTime(String tradeTime) | |||||
{ | |||||
this.tradeTime = tradeTime; | |||||
} | |||||
public String getAppId() | |||||
{ | |||||
return appId; | |||||
} | |||||
public void setAppId(String appId) | |||||
{ | |||||
this.appId = appId; | |||||
} | |||||
public String getMchId() | |||||
{ | |||||
return mchId; | |||||
} | |||||
public void setMchId(String mchId) | |||||
{ | |||||
this.mchId = mchId; | |||||
} | |||||
public String getSubMchId() | |||||
{ | |||||
return subMchId; | |||||
} | |||||
public void setSubMchId(String subMchId) | |||||
{ | |||||
this.subMchId = subMchId; | |||||
} | |||||
public String getDeviceInfo() | |||||
{ | |||||
return deviceInfo; | |||||
} | |||||
public void setDeviceInfo(String deviceInfo) | |||||
{ | |||||
this.deviceInfo = deviceInfo; | |||||
} | |||||
public String getTransationId() | |||||
{ | |||||
return transationId; | |||||
} | |||||
public void setTransationId(String transationId) | |||||
{ | |||||
this.transationId = transationId; | |||||
} | |||||
public String getOutTradeNo() | |||||
{ | |||||
return outTradeNo; | |||||
} | |||||
public void setOutTradeNo(String outTradeNo) | |||||
{ | |||||
this.outTradeNo = outTradeNo; | |||||
} | |||||
public String getOpenId() | |||||
{ | |||||
return openId; | |||||
} | |||||
public void setOpenId(String openId) | |||||
{ | |||||
this.openId = openId; | |||||
} | |||||
public String getTradeType() | |||||
{ | |||||
return tradeType; | |||||
} | |||||
public void setTradeType(String tradeType) | |||||
{ | |||||
this.tradeType = tradeType; | |||||
} | |||||
public String getTradeState() | |||||
{ | |||||
return tradeState; | |||||
} | |||||
public void setTradeState(String tradeState) | |||||
{ | |||||
this.tradeState = tradeState; | |||||
} | |||||
public String getBankType() | |||||
{ | |||||
return bankType; | |||||
} | |||||
public void setBankType(String bankType) | |||||
{ | |||||
this.bankType = bankType; | |||||
} | |||||
public String getFeeType() | |||||
{ | |||||
return feeType; | |||||
} | |||||
public void setFeeType(String feeType) | |||||
{ | |||||
this.feeType = feeType; | |||||
} | |||||
public String getTotalFee() | |||||
{ | |||||
return totalFee; | |||||
} | |||||
public void setTotalFee(String totalFee) | |||||
{ | |||||
this.totalFee = totalFee; | |||||
} | |||||
public String getCouponFee() | |||||
{ | |||||
return couponFee; | |||||
} | |||||
public void setCouponFee(String couponFee) | |||||
{ | |||||
this.couponFee = couponFee; | |||||
} | |||||
public String getRefundId() | |||||
{ | |||||
return refundId; | |||||
} | |||||
public void setRefundId(String refundId) | |||||
{ | |||||
this.refundId = refundId; | |||||
} | |||||
public String getOutRefundNo() | |||||
{ | |||||
return outRefundNo; | |||||
} | |||||
public void setOutRefundNo(String outRefundNo) | |||||
{ | |||||
this.outRefundNo = outRefundNo; | |||||
} | |||||
public String getSettlementRefundFee() | |||||
{ | |||||
return settlementRefundFee; | |||||
} | |||||
public void setSettlementRefundFee(String settlementRefundFee) | |||||
{ | |||||
this.settlementRefundFee = settlementRefundFee; | |||||
} | |||||
public String getCouponRefundFee() | |||||
{ | |||||
return couponRefundFee; | |||||
} | |||||
public void setCouponRefundFee(String couponRefundFee) | |||||
{ | |||||
this.couponRefundFee = couponRefundFee; | |||||
} | |||||
public String getRefundChannel() | |||||
{ | |||||
return refundChannel; | |||||
} | |||||
public void setRefundChannel(String refundChannel) | |||||
{ | |||||
this.refundChannel = refundChannel; | |||||
} | |||||
public String getRefundState() | |||||
{ | |||||
return refundState; | |||||
} | |||||
public void setRefundState(String refundState) | |||||
{ | |||||
this.refundState = refundState; | |||||
} | |||||
public String getBody() | |||||
{ | |||||
return body; | |||||
} | |||||
public void setBody(String body) | |||||
{ | |||||
this.body = body; | |||||
} | |||||
public String getAttach() | |||||
{ | |||||
return attach; | |||||
} | |||||
public void setAttach(String attach) | |||||
{ | |||||
this.attach = attach; | |||||
} | |||||
public String getPoundage() | |||||
{ | |||||
return poundage; | |||||
} | |||||
public void setPoundage(String poundage) | |||||
{ | |||||
this.poundage = poundage; | |||||
} | |||||
public String getPoundageRate() | |||||
{ | |||||
return poundageRate; | |||||
} | |||||
public void setPoundageRate(String poundageRate) | |||||
{ | |||||
this.poundageRate = poundageRate; | |||||
} | |||||
public static long getSerialversionuid() | |||||
{ | |||||
return serialVersionUID; | |||||
} | |||||
} |
@@ -0,0 +1,86 @@ | |||||
package com.github.binarywang.wxpay.bean.result; | |||||
import java.util.List; | |||||
public class WxPayBillResult implements Serializable | |||||
{ | |||||
/** | |||||
* 对账返回对象 | |||||
*/ | |||||
private static final long serialVersionUID = 1L; | |||||
private List<WxPayBillBaseResult> wxPayBillBaseResultLst; | |||||
/**总交易单数*/ | |||||
private String totalRecord; | |||||
/**总交易额*/ | |||||
private String totalFee; | |||||
/**总退款金额*/ | |||||
private String totalRefundFee; | |||||
/**总代金券或立减优惠退款金额*/ | |||||
private String totalCouponFee; | |||||
/**手续费总金额 */ | |||||
private String totalPoundageFee; | |||||
public List<WxPayBillBaseResult> getWxPayBillBaseResultLst() | |||||
{ | |||||
return wxPayBillBaseResultLst; | |||||
} | |||||
public void setWxPayBillBaseResultLst(List<WxPayBillBaseResult> wxPayBillBaseResultLst) | |||||
{ | |||||
this.wxPayBillBaseResultLst = wxPayBillBaseResultLst; | |||||
} | |||||
public String getTotalRecord() | |||||
{ | |||||
return totalRecord; | |||||
} | |||||
public void setTotalRecord(String totalRecord) | |||||
{ | |||||
this.totalRecord = totalRecord; | |||||
} | |||||
public String getTotalFee() | |||||
{ | |||||
return totalFee; | |||||
} | |||||
public void setTotalFee(String totalFee) | |||||
{ | |||||
this.totalFee = totalFee; | |||||
} | |||||
public String getTotalRefundFee() | |||||
{ | |||||
return totalRefundFee; | |||||
} | |||||
public void setTotalRefundFee(String totalRefundFee) | |||||
{ | |||||
this.totalRefundFee = totalRefundFee; | |||||
} | |||||
public String getTotalCouponFee() | |||||
{ | |||||
return totalCouponFee; | |||||
} | |||||
public void setTotalCouponFee(String totalCouponFee) | |||||
{ | |||||
this.totalCouponFee = totalCouponFee; | |||||
} | |||||
public String getTotalPoundageFee() | |||||
{ | |||||
return totalPoundageFee; | |||||
} | |||||
public void setTotalPoundageFee(String totalPoundageFee) | |||||
{ | |||||
this.totalPoundageFee = totalPoundageFee; | |||||
} | |||||
} |
@@ -246,7 +246,7 @@ public interface WxPayService { | |||||
* @param deviceInfo 设备号 device_info 非必传参数,终端设备号 | * @param deviceInfo 设备号 device_info 非必传参数,终端设备号 | ||||
* @return 保存到本地的临时文件 | * @return 保存到本地的临时文件 | ||||
*/ | */ | ||||
File downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException; | |||||
WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
@@ -299,7 +299,7 @@ public class WxPayServiceImpl implements WxPayService { | |||||
} | } | ||||
@Override | @Override | ||||
public File downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException { | |||||
public WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException { | |||||
WxPayDownloadBillRequest request = new WxPayDownloadBillRequest(); | WxPayDownloadBillRequest request = new WxPayDownloadBillRequest(); | ||||
request.setBillType(billType); | request.setBillType(billType); | ||||
request.setBillDate(billDate); | request.setBillDate(billDate); | ||||
@@ -311,11 +311,85 @@ public class WxPayServiceImpl implements WxPayService { | |||||
String url = this.getPayBaseUrl() + "/pay/downloadbill"; | String url = this.getPayBaseUrl() + "/pay/downloadbill"; | ||||
//TODO 返回的内容可能是文件流,也有可能是xml,需要区分对待 | //TODO 返回的内容可能是文件流,也有可能是xml,需要区分对待 | ||||
String responseContent = this.post(url, request.toXML()); | String responseContent = this.post(url, request.toXML()); | ||||
if (responseContent.startsWith("<")){ | |||||
WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class); | |||||
result.checkResult(this); | |||||
return null; | |||||
}else{ | |||||
WxPayBillResult wxPayBillResult = billInformationDeal(responseContent); | |||||
return wxPayBillResult; | |||||
} | |||||
} | |||||
private WxPayBillResult billInformationDeal(String responseContent){ | |||||
WxPayBillResult wxPayBillResult = new WxPayBillResult(); | |||||
String listStr = ""; | |||||
String objStr = ""; | |||||
if (responseContent.indexOf("总交易单数") >= 0){ | |||||
listStr = responseContent.substring(0, responseContent.indexOf("总交易单数")); | |||||
objStr = responseContent.substring(responseContent.indexOf("总交易单数")); | |||||
} | |||||
WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class); | |||||
result.checkResult(this); | |||||
//TODO 待实现,暂时无测试帐号,无法调试 | |||||
return null; | |||||
/* | |||||
* 交易时间: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<WxPayBillBaseResult>(); | |||||
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]); | |||||
wxPayBillBaseResult.setAppId(tempStr[k + 1]); | |||||
wxPayBillBaseResult.setMchId(tempStr[k + 2]); | |||||
wxPayBillBaseResult.setSubMchId(tempStr[k + 3]); | |||||
wxPayBillBaseResult.setDeviceInfo(tempStr[k + 4]); | |||||
wxPayBillBaseResult.setTransationId(tempStr[k + 5]); | |||||
wxPayBillBaseResult.setOutTradeNo(tempStr[k + 6]); | |||||
wxPayBillBaseResult.setOpenId(tempStr[k + 7]); | |||||
wxPayBillBaseResult.setTradeType(tempStr[k + 8]); | |||||
wxPayBillBaseResult.setTradeState(tempStr[k + 9]); | |||||
wxPayBillBaseResult.setBankType(tempStr[k + 10]); | |||||
wxPayBillBaseResult.setFeeType(tempStr[k + 11]); | |||||
wxPayBillBaseResult.setTotalFee(tempStr[k + 12]); | |||||
wxPayBillBaseResult.setCouponFee(tempStr[k + 13]); | |||||
wxPayBillBaseResult.setRefundId(tempStr[k + 14]); | |||||
wxPayBillBaseResult.setOutRefundNo(tempStr[k + 15]); | |||||
wxPayBillBaseResult.setSettlementRefundFee(tempStr[k + 16]); | |||||
wxPayBillBaseResult.setCouponRefundFee(tempStr[k + 17]); | |||||
wxPayBillBaseResult.setRefundChannel(tempStr[k + 18]); | |||||
wxPayBillBaseResult.setRefundState(tempStr[k + 19]); | |||||
wxPayBillBaseResult.setBody(tempStr[k + 20]); | |||||
wxPayBillBaseResult.setAttach(tempStr[k + 21]); | |||||
wxPayBillBaseResult.setPoundage(tempStr[k + 22]); | |||||
wxPayBillBaseResult.setPoundageRate(tempStr[k + 23]); | |||||
wxPayBillBaseResultLst.add(wxPayBillBaseResult); | |||||
k += t.length; | |||||
} | |||||
/* | |||||
* 总交易单数,总交易额,总退款金额,总代金券或立减优惠退款金额,手续费总金额 `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 | @Override | ||||
@@ -49,8 +49,9 @@ public class WxPayServiceImplTest { | |||||
@Test | @Test | ||||
public void testDownloadBill() throws Exception { | public void testDownloadBill() throws Exception { | ||||
File file = this.payService.downloadBill("20170101", "ALL", "GZIP", "1111111"); | |||||
assertNotNull(file); | |||||
WxPayBillResult wxPayBillResult = this.payService.downloadBill("20170101", "ALL", "GZIP", "1111111"); | |||||
//前一天没有账单记录返回null | |||||
assertNotNull(wxPayBillResult); | |||||
//必填字段为空时,抛出异常 | //必填字段为空时,抛出异常 | ||||
this.payService.downloadBill("", "", "", null); | this.payService.downloadBill("", "", "", null); | ||||
} | } | ||||