支付寶對賬單下載


這個接口是下載離線賬單的,需要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();
    }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM