这个接口是下载离线账单的,需要T+1天生成账单,不能查询当日或者是当月的账单,如果日期是当天或者是当月的会返回“参数不合法”;
下载对账单地址接口只有当面付接口可以下载trade类型的账单,其他支付接口只能下载signcustomer 这个类型的
public String downloadAllBillAlypay() {
System.out.println("支付宝账单下载接口");
AlipayClient alipayClient = new DefaultAlipayClient(aLipayUrl, aLiAppid, aLiPrivateKey, "json", DEFAULT_CHARSET,
aLiPublicKey, SIGN_TYPE);
AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest();//创建API对应的request类
request.setBizContent("{" +
" \"bill_type\":\"signcustomer\"," +
" \"bill_date\":\"2019-06-04\"}"); //设置业务参数
AlipayDataDataserviceBillDownloadurlQueryResponse response = null;
try {
response = alipayClient.execute(request);
} catch (AlipayApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//通过alipayClient调用API,获得对应的response类
System.out.print("response===>"+response.getBody());
JSONObject parseObject = JSON.parseObject(response.getBody());
System.out.println("parseObject===>"+JSON.toJSONString(parseObject));
JSONObject aJsonObject = (JSONObject) parseObject.get("alipay_data_dataservice_bill_downloadurl_query_response");
String urlStr = aJsonObject.get("bill_download_url").toString();
System.out.println("url===>"+urlStr);
// HttpUtilResponse response11 = HttpUtilProxy.get(aJsonObject.get("bill_download_url").toString(), null, 15*1000);
// System.out.println("response11===>"+JSONObject.toJSONString(response11));
//指定希望保存的文件路径
String filePath = "D:/zhangdan/fund_bill_20190604.zip";
URL url = null;
HttpURLConnection httpUrlConnection = null;
InputStream fis = null;
FileOutputStream fos = null;
try {
url = new URL(urlStr);
httpUrlConnection = (HttpURLConnection) url.openConnection();
httpUrlConnection.setConnectTimeout(5 * 1000);
httpUrlConnection.setDoInput(true);
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setUseCaches(false);
httpUrlConnection.setRequestMethod("GET");
httpUrlConnection.setRequestProperty("Charsert", "UTF-8");
httpUrlConnection.connect();
fis = httpUrlConnection.getInputStream();
byte[] temp = new byte[1024];
int b;
fos = new FileOutputStream(new File(filePath));
while ((b = fis.read(temp)) != -1) {
fos.write(temp, 0, b);
fos.flush();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(fis!=null) fis.close();
if(fos!=null) fos.close();
if(httpUrlConnection!=null) httpUrlConnection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
return response.getBody();
}