支付宝查询对账单对账+解压并将数据读取解析入库

支付宝官方文档地址:

https://opendocs.alipay.com/apis/api_15/alipay.data.dataservice.bill.downloadurl.query

作用:

为方便商户快速查账,支持商户通过本接口获取商户离线账单下载地址

代码实现:

pom:

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.0.7</version>
</dependency>

工具类:


package com.lwjwlkj.common.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;

import java.io.*;

/**
 * @Author: CL
 * @Date: 2020/6/23 13:11
 * @Description: 解压工具类
 */
@Slf4j
public class ZipUtil {
   
    public static void unzip(File zipFile, String filePath) {
   
        try (ZipArchiveInputStream inputStream = getZipFile(zipFile)) {
   
            ZipArchiveEntry entry = null;
            while ((entry = inputStream.getNextZipEntry()) != null) {
   
                if (entry.isDirectory()) {
   
                    File directory = new File(filePath, entry.getName());
                    directory.mkdirs();
                } else {
   
                    OutputStream os = null;
                    try {
   
                        os = new BufferedOutputStream(new FileOutputStream(new File(filePath, entry.getName())));
                        //输出文件路径信息
                        System.out.println(entry.getName());
                        IOUtils.copy(inputStream, os);
                    } finally {
   
                        IOUtils.closeQuietly(os);
                    }
                }
            }


        } catch (Exception e) {
   
            log.error("unzip" + e);
        }
    }

    private static ZipArchiveInputStream getZipFile(File zipFile) throws Exception {
   
        return new ZipArchiveInputStream(new FileInputStream(zipFile), "GBK");
    }

    public static void makdirs(String filePath) {
   
        File pathFile = new File(filePath);
        if (!pathFile.exists()) {
   
            pathFile.mkdirs();
        }
    }

    public static void delAllFile(String path) {
   
        File file = new File(path);
        String[] tempList = file.list();
        File temp = null;
        for (int i = 0; i < tempList.length; i++) {
   
            if (path.endsWith(File.separator)) {
   
                temp = new File(path + tempList[i]);
            } else {
   
                temp = new File(path + File.separator + tempList[i]);
            }
            if (temp.isFile()) {
   
                temp.delete();
            }
            if (temp.isDirectory()) {
   
                delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件
            }
        }
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值