下载对账单新增压缩参数
This commit is contained in:
parent
b2e5c108fd
commit
585b0ab63f
@ -37,12 +37,14 @@ import com.foxinmy.weixin4j.type.CurrencyType;
|
|||||||
import com.foxinmy.weixin4j.type.IdQuery;
|
import com.foxinmy.weixin4j.type.IdQuery;
|
||||||
import com.foxinmy.weixin4j.type.IdType;
|
import com.foxinmy.weixin4j.type.IdType;
|
||||||
import com.foxinmy.weixin4j.type.SignType;
|
import com.foxinmy.weixin4j.type.SignType;
|
||||||
|
import com.foxinmy.weixin4j.type.TarType;
|
||||||
import com.foxinmy.weixin4j.type.TradeType;
|
import com.foxinmy.weixin4j.type.TradeType;
|
||||||
import com.foxinmy.weixin4j.type.mch.BillType;
|
import com.foxinmy.weixin4j.type.mch.BillType;
|
||||||
import com.foxinmy.weixin4j.type.mch.RefundAccountType;
|
import com.foxinmy.weixin4j.type.mch.RefundAccountType;
|
||||||
import com.foxinmy.weixin4j.util.Consts;
|
import com.foxinmy.weixin4j.util.Consts;
|
||||||
import com.foxinmy.weixin4j.util.DateUtil;
|
import com.foxinmy.weixin4j.util.DateUtil;
|
||||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||||
|
import com.foxinmy.weixin4j.util.IOUtil;
|
||||||
import com.foxinmy.weixin4j.util.MapUtil;
|
import com.foxinmy.weixin4j.util.MapUtil;
|
||||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||||
import com.foxinmy.weixin4j.util.StringUtil;
|
import com.foxinmy.weixin4j.util.StringUtil;
|
||||||
@ -604,6 +606,8 @@ public class PayApi extends MchApi {
|
|||||||
* REFUND,返回当日退款订单
|
* REFUND,返回当日退款订单
|
||||||
* @param outputStream
|
* @param outputStream
|
||||||
* 输出流
|
* 输出流
|
||||||
|
* @param tarType
|
||||||
|
* 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
|
||||||
* @since V3
|
* @since V3
|
||||||
* @see <a href=
|
* @see <a href=
|
||||||
* "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">
|
* "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">
|
||||||
@ -611,7 +615,7 @@ public class PayApi extends MchApi {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public void downloadBill(Date billDate, BillType billType,
|
public void downloadBill(Date billDate, BillType billType,
|
||||||
OutputStream outputStream) throws WeixinException {
|
OutputStream outputStream, TarType tarType) throws WeixinException {
|
||||||
if (billDate == null) {
|
if (billDate == null) {
|
||||||
Calendar now = Calendar.getInstance();
|
Calendar now = Calendar.getInstance();
|
||||||
now.add(Calendar.DAY_OF_MONTH, -1);
|
now.add(Calendar.DAY_OF_MONTH, -1);
|
||||||
@ -624,36 +628,47 @@ public class PayApi extends MchApi {
|
|||||||
Map<String, String> map = createBaseRequestMap(null);
|
Map<String, String> map = createBaseRequestMap(null);
|
||||||
map.put("bill_date", formatBillDate);
|
map.put("bill_date", formatBillDate);
|
||||||
map.put("bill_type", billType.name());
|
map.put("bill_type", billType.name());
|
||||||
|
if (tarType != null) {
|
||||||
|
map.put("tar_type", tarType.name());
|
||||||
|
}
|
||||||
map.put("sign", weixinSignature.sign(map));
|
map.put("sign", weixinSignature.sign(map));
|
||||||
String param = XmlStream.map2xml(map);
|
String param = XmlStream.map2xml(map);
|
||||||
WeixinResponse response = weixinExecutor.post(
|
WeixinResponse response = weixinExecutor.post(
|
||||||
getRequestUri("downloadbill_uri"), param);
|
getRequestUri("downloadbill_uri"), param);
|
||||||
|
|
||||||
BufferedReader reader = null;
|
if (TarType.GZIP == tarType) {
|
||||||
BufferedWriter writer = null;
|
|
||||||
try {
|
|
||||||
writer = new BufferedWriter(new OutputStreamWriter(outputStream,
|
|
||||||
Consts.UTF_8));
|
|
||||||
reader = new BufferedReader(new InputStreamReader(
|
|
||||||
response.getBody(), Consts.UTF_8));
|
|
||||||
String line = null;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
writer.write(line);
|
|
||||||
writer.newLine();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new WeixinException(e);
|
|
||||||
} finally {
|
|
||||||
try {
|
try {
|
||||||
if (reader != null) {
|
IOUtil.copy(response.getBody(), outputStream);
|
||||||
reader.close();
|
} catch (IOException e) {
|
||||||
}
|
|
||||||
if (writer != null) {
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
} catch (IOException ignore) {
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
BufferedReader reader = null;
|
||||||
|
BufferedWriter writer = null;
|
||||||
|
try {
|
||||||
|
writer = new BufferedWriter(new OutputStreamWriter(
|
||||||
|
outputStream, Consts.UTF_8));
|
||||||
|
reader = new BufferedReader(new InputStreamReader(
|
||||||
|
response.getBody(), Consts.UTF_8));
|
||||||
|
String line = null;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
writer.write(line);
|
||||||
|
writer.newLine();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new WeixinException(e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
if (writer != null) {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -58,6 +58,8 @@ public class MimeType implements Serializable {
|
|||||||
STREAM_MIMETYPES.add(valueOf("image/*"));
|
STREAM_MIMETYPES.add(valueOf("image/*"));
|
||||||
STREAM_MIMETYPES.add(valueOf("audio/*"));
|
STREAM_MIMETYPES.add(valueOf("audio/*"));
|
||||||
STREAM_MIMETYPES.add(valueOf("video/*"));
|
STREAM_MIMETYPES.add(valueOf("video/*"));
|
||||||
|
STREAM_MIMETYPES.add(valueOf("application/zip"));
|
||||||
|
STREAM_MIMETYPES.add(valueOf("application/x-gzip"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MimeType(String type) {
|
public MimeType(String type) {
|
||||||
|
|||||||
@ -39,6 +39,7 @@ import com.foxinmy.weixin4j.sign.WeixinSignature;
|
|||||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||||
import com.foxinmy.weixin4j.type.CustomsCity;
|
import com.foxinmy.weixin4j.type.CustomsCity;
|
||||||
import com.foxinmy.weixin4j.type.IdQuery;
|
import com.foxinmy.weixin4j.type.IdQuery;
|
||||||
|
import com.foxinmy.weixin4j.type.TarType;
|
||||||
import com.foxinmy.weixin4j.type.mch.BillType;
|
import com.foxinmy.weixin4j.type.mch.BillType;
|
||||||
import com.foxinmy.weixin4j.type.mch.RefundAccountType;
|
import com.foxinmy.weixin4j.type.mch.RefundAccountType;
|
||||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||||
@ -511,6 +512,8 @@ public class WeixinPayProxy {
|
|||||||
* 下载对账单的类型 ALL,返回当日所有订单信息, 默认值 SUCCESS,返回当日成功支付的订单
|
* 下载对账单的类型 ALL,返回当日所有订单信息, 默认值 SUCCESS,返回当日成功支付的订单
|
||||||
* REFUND,返回当日退款订单
|
* REFUND,返回当日退款订单
|
||||||
* @para outputStream 输出流
|
* @para outputStream 输出流
|
||||||
|
* @param tarType
|
||||||
|
* 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
|
||||||
* @since V2 & V3
|
* @since V2 & V3
|
||||||
* @see com.foxinmy.weixin4j.api.PayApi
|
* @see com.foxinmy.weixin4j.api.PayApi
|
||||||
* @see <a href=
|
* @see <a href=
|
||||||
@ -519,8 +522,8 @@ public class WeixinPayProxy {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public void downloadBill(Date billDate, BillType billType,
|
public void downloadBill(Date billDate, BillType billType,
|
||||||
OutputStream outputStream) throws WeixinException {
|
OutputStream outputStream, TarType tarType) throws WeixinException {
|
||||||
payApi.downloadBill(billDate, billType, outputStream);
|
payApi.downloadBill(billDate, billType, outputStream, tarType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user