支付宝的对接文档

https://opendocs.alipay.com/apis/02byuu

import com.alipay.api.AlipayClient;public vid aliPayBills(String billDate, PayAccountConfig accountConfig) throws Exception {AlipayClient alipayClient = getInstance();AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest();Map<String, String> params = new HashMap<>();params.put("bill_type", "signcustomer");params.put("bill_date", billDate);request.setBizContent(JSON.toJSONString(params));AlipayDataDataserviceBillDownloadurlQueryResponse response = alipayClient.certificateExecute(request);if (response.isSuccess()) {String payBillsPath = aliPayBillsPath;//获取支付宝对账单URL(url有效时间为30秒)String url = response.getBillDownloadUrl();log.info("***************获取到的支付宝对账单的URL:" + url + "**********************");String newZip = payBillsPath + new Date().getTime() + ".zip";// 开始下载 (下载文件为zip)SaveFile.downloadNet(url, newZip, payBillsPath);//解压(解压后有两个文件,明细,明细汇总)SaveFile.unZip(newZip, payBillsPath);log.info("***************下载,解压完成**********************");//获取解压后的两个文件File[] fs = new File(payBillsPath).listFiles();//用来保存明细的数据ArrayList<String[]> csvList = new ArrayList<>();String fileName = "";//获取对账单明细(只需要处理明细文件)for (File file : fs) {if (!file.getAbsolutePath().contains("汇总") && !file.getAbsolutePath().contains("zip")) {fileName = file.getAbsolutePath();csvList = getFileCell(fileName);}}File file2 = new File(fileName);FileInputStream inputStream = new FileInputStream(file2);MultipartFile multipartFile = new MockMultipartFile(file2.getName(), file2.getName(), ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);String originalFilename = multipartFile.getOriginalFilename();OssUtil.uploadFile(bucketName, originalFilename, multipartFile, "/paybills");for (File file : fs) {if (file.isFile()) {SaveFile.delFile(file.getAbsolutePath());} else {SaveFile.delFolder(file.getAbsolutePath());}}return csvList;} else {System.out.println("调用失败");return null;}}

工具类:支护宝API请求初始化

public static AlipayClient getInstance() throws Exception {if (Instance == null) {synchronized (AlipayClient.class) {if (Instance == null) {//构造clientCertAlipayRequest certAlipayRequest = new CertAlipayRequest();//设置网关地址certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");//设置应用IdcertAlipayRequest.setAppId(appId);//设置应用私钥certAlipayRequest.setPrivateKey(privateKey);//设置请求格式,固定值jsoncertAlipayRequest.setFormat("json");//设置字符集certAlipayRequest.setCharset(CPayConfig.CHARSET);//设置签名类型certAlipayRequest.setSignType(CPayConfig.ALI_SIGN_TYPE);//设置应用公钥证书路径certAlipayRequest.setCertPath(appCertPath);//设置支付宝公钥证书路径certAlipayRequest.setAlipayPublicCertPath(aliPayCertPath);//设置支付宝根证书路径certAlipayRequest.setRootCertPath(aliPayRootCertPath);//构造clientreturn new DefaultAlipayClient(certAlipayRequest);}}}return Instance;}

文件工具

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.zip.ZipEntry;/*** 根据url下载文件到本地指定目录* 然后上传到服务器** @Author stone* @Date 2020/07/21* @return*/
@Slf4j
public class SaveFile {/*** 使用GBK编码可以避免压缩中文文件名乱码*/private static final String CHINESE_CHARSET = "GBK";/*** 文件读取缓冲区大小*/private static final int CACHE_SIZE = 1024;/*** 根据Url下载文件** @param urlStr* @param fileName* @param savePath* @throws IOException*/public static void downLoadFromUrl(String urlStr, String fileName,String savePath) throws IOException {URL url = new URL(urlStr);HttpURLConnection conn = (HttpURLConnection) url.openConnection();//设置超时间为3秒conn.setConnectTimeout(3 * 1000);//防止屏蔽程序抓取而返回403错误conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");//得到输入流InputStream inputStream = conn.getInputStream();//获取自己数组byte[] getData = readInputStream(inputStream);//文件保存位置File saveDir = new File(savePath);if (!saveDir.exists()) {saveDir.mkdir();}File file = new File(saveDir + File.separator + fileName);FileOutputStream fos = new FileOutputStream(file);fos.write(getData);if (fos != null) {fos.close();}if (inputStream != null) {inputStream.close();}log.info("info: {} download success ", url);}public static void delFile(String path) {File file = new File(path);if (!file.exists()) return;if (file.isFile() || file.list() == null) {file.delete();log.info("the file:{} has been deleted", file.getName());}}public static void delFolder(String folderPath) {try {delAllFile(folderPath); // 删除完里面所有内容String filePath = folderPath;filePath = filePath.toString();java.io.File myFilePath = new java.io.File(filePath);myFilePath.delete(); // 删除空文件夹} catch (Exception e) {e.printStackTrace();}}public static boolean delAllFile(String path) {boolean flag = false;File file = new File(path);if (!file.exists()) {return flag;}if (!file.isDirectory()) {return flag;}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]);// 先删除文件夹里面的文件delFolder(path + "/" + tempList[i]);// 再删除空文件夹flag = true;}}return flag;}/*** 从输入流中获取字节数组** @param inputStream* @return* @throws IOException*/public static byte[] readInputStream(InputStream inputStream) throws IOException {byte[] buffer = new byte[1024];int len = 0;ByteArrayOutputStream bos = new ByteArrayOutputStream();while ((len = inputStream.read(buffer)) != -1) {bos.write(buffer, 0, len);}bos.close();return bos.toByteArray();}public static void downloadNet(String path, String filePath,String filePath1)throws MalformedURLException {// 下载网络文件int bytesum = 0;int byteread = 0;URL url = new URL(path);//文件保存位置File saveDir = new File(filePath1);if (!saveDir.exists()) {saveDir.mkdir();}try {URLConnection conn = url.openConnection();InputStream inStream = conn.getInputStream();FileOutputStream fs = new FileOutputStream(filePath);byte[] buffer = new byte[1204];while ((byteread = inStream.read(buffer)) != -1) {bytesum += byteread;fs.write(buffer, 0, byteread);}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}/*** 解压到指定目录** @param zipFilePath* @param destDir* @throws Exception*/public static void unZip(String zipFilePath, String destDir)throws Exception {ZipFile zipFile = new ZipFile(zipFilePath, CHINESE_CHARSET);Enumeration<?> emu = zipFile.getEntries();BufferedInputStream bis;FileOutputStream fos;BufferedOutputStream bos;File file, parentFile;ZipEntry entry;byte[] cache = new byte[CACHE_SIZE];while (emu.hasMoreElements()) {entry = (ZipEntry) emu.nextElement();if (entry.isDirectory()) {new File(destDir + entry.getName()).mkdirs();continue;}bis = new BufferedInputStream(zipFile.getInputStream((ZipArchiveEntry) entry));file = new File(destDir + entry.getName());parentFile = file.getParentFile();if (parentFile != null && (!parentFile.exists())) {parentFile.mkdirs();}fos = new FileOutputStream(file);bos = new BufferedOutputStream(fos, CACHE_SIZE);int nRead = 0;while ((nRead = bis.read(cache, 0, CACHE_SIZE)) != -1) {fos.write(cache, 0, nRead);}bos.flush();bos.close();fos.close();bis.close();}zipFile.close();}
}

JVAV - 对接支付宝- 下载对账单接口相关推荐

  1. 对接支付宝单笔转账接口

    对接支付宝单笔转账接口 功能介绍 接入准备 调用支付宝api需要以下参数: 项目引入 操作流程 创建小程序 配置小程序 集成配置 SDK 助手 详细操作流程 获取appId 获取证书 获取AES密钥 ...

  2. [转]个人网站对接支付宝,微信支付接口史上最详细教程

    对接支付宝支付接口,官方文档已经写的很清楚了,但是也有很多像我一样的小白,第一次对接支付宝支付接口,会有些迷茫,所以我在此写下这篇文章,给我和我一样的同学,一点思路吧.三分钟就可以申请,支付宝个人即时 ...

  3. 网站对接支付宝,微信支付接口史上最详细教程

    联系qq:1104752746对接支付宝支付接口,官方文档已经写的很清楚了,但是也有很多像我一样的小白,第一次对接支付宝支付接口,会有些迷茫,所以我在此写下这篇文章,给我和我一样的同学,一点思路吧.三 ...

  4. 对接支付宝网站支付接口

    今天因为业务需要线上支付充值,所以需要对接支付宝的网站支付接口.首先去支付宝开发者中心看了一遍demo:网址如下:https://docs.open.alipay.com/270/106291/ 大致 ...

  5. Django对接支付宝Alipay支付接口

    最新文章更新见我的个人主页: https://xzajyjs.cn 我们在使用Django构建网站时常需要对接第三方支付平台的支付接口,这里就以支付宝为例(其他平台大同小异),使用支付宝开放平台的沙箱 ...

  6. php对接支付宝当面付接口视频教程,支付宝当面付接口demo(面对面扫码支付)

    [实例简介] 一.免责申明 DEMO仅供参考,实际开发中需要结合具体业务场景修改使用. 二.运行环境: .net framework 3.5以上:visual studio 2010以上 三.使用说明 ...

  7. java 对接支付宝单笔转账接口

    证书模式及非证书模式转账 查询证书路径 public String queryPath() throws FileNotFoundException, ServerException {String ...

  8. 支付宝html5接入,app和h5怎样对接支付宝支付接口?

    1.支付宝开放平台https://open.alipay.com 新增应用并签约手机网站支付/APP支付. 2.服务端使用java, 集成支付宝sdk. 3.为方便以后更多支付方式扩展, 先定义接口, ...

  9. 网站对接支付宝进行支付

    本文介绍PC网页对接支付宝,完成批量向支付宝账户转账的功能(使用Java实现),首先我的水平是这样的:接到这个工作任务后,可以说我是大白,之前我做过银行的项目,懂签名和验签是怎么一回事,但是对接支付宝 ...

  10. php微信商户下载对账单,浅析微信支付:下载对账单和资金账单

    本文是[浅析微信支付]系列文章的第九篇,主要讲解商户下载对账单接口和资金账单接口的实现和一些注意事项. 浅析微信支付系列已经更新九篇了哟-,没有看过的朋友们可以看一下哦. 在商户平台中,商家也可以下载 ...

最新文章

  1. SQL Cache Invalidation
  2. strstr、strspn如何使用
  3. 图片马可以直接连接吗_商标买来可以直接使用吗?
  4. [CTSC2017]吉夫特(思维+巧妙)
  5. C# 反射机制(转)
  6. SpringBoot集成Spring Security(一)登录注销
  7. NoSQL和传统数据库的区别
  8. 简单十步让你全面理解SQL
  9. android文本框自动补全,[Android]AutoCompleteTextView自动补全文本框
  10. python报表自动化系列 - 在Windows中打开指定目录
  11. iperf android使用方法,FW: 使用Iperf工具测试android系统网络wifi的吞吐量wifithrougput...
  12. [RMQ] [线段树] POJ 3368 Frequent Values
  13. JavaScript - textarea 滚动至顶部或底部
  14. 蔻享学术下载器:KouShare-dl
  15. 解决google浏览器自动填充密码问题
  16. Unity UGUI Rect
  17. Kodu程序的菜单---Kodu少儿编程第七天
  18. QQ能上,但是网页打不开?
  19. 美国大学计算机工程专业排名,2018美国大学计算机工程专业排名_美国大学计算机工程排名...
  20. H5 雪碧图 移动的机器猫

热门文章

  1. 坚守13年的极飞,终靠“务农”拿下12亿融资!专访彭斌:要为行业找技术,而不是为技术找行业...
  2. 如何更改域计算机用户名和密码错误,win7加入域失败:未知的用户名或密码错误 | 绿萝...
  3. ssh的发展历程与基本原理
  4. nebulagraph exchange3.0.x
  5. 微信与企业微信内嵌浏览器的UserAgent
  6. html打印多了空白页,为什么打印Word文档会多打印出一空白页
  7. 量子物理与计算机,量子计算机与量子物理
  8. 基于java的点歌系统设计_KTV点歌系统的设计与实现(毕业论文).doc
  9. 微信小程序PNG图片去白底
  10. 计算机网络水晶头闪,网线水晶头坏了怎么办 小妙招一分钟解决你的问题