zoukankan      html  css  js  c++  java
  • 支付宝对账单下载

    这个接口是下载离线账单的,需要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();
        }
    

      

  • 相关阅读:
    conan本地安装包
    Python PIL 怎么知道写入图片格式的kb大小
    怎么对C++枚举(不是类)里面的东西进行随机
    当双方Visual studio windows SDK不一样的时候的解决办法
    不小心使用vcpkg之后再使用conan,一直报链接错误
    关于obj文件的理解
    卸载VS2015之后,安装VS2017出错
    性状、生成器、闭包、OPcache【Modern PHP】
    docker容器修改hosts文件,重启失效问题解决
    微信公众号-模板消息通用接口封装
  • 原文地址:https://www.cnblogs.com/lyb0103/p/11506974.html
Copyright © 2011-2022 走看看