c#下载微信跟支付宝交易账单

  • 下载微信交易账单
                   //账单日期只能下载前一天的string datetime = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");string body = "";string URL = "/v3/bill/fundflowbill" + "?bill_date=" + datetime;//生成签名认证var auth = BuildAuthAsync("GET", body, URL);string Authorization = $"WECHATPAY2-SHA256-RSA2048 {auth}";string bill_date = datetime;string url = "https://api.mch.weixin.qq.com/v3/bill/fundflowbill";url = url + "?" + "bill_date=" + bill_date.ToString();HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);request.Timeout = 20000;  //超时时间request.Method = "GET";  //请求方式request.KeepAlive = true;request.Headers.Add("Authorization", Authorization);request.Accept = "application/json";request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36";HttpWebResponse response = (HttpWebResponse)request.GetResponse();string postContent = new StreamReader(response.GetResponseStream()).ReadToEnd();JObject json = JObject.Parse(postContent);var download_url = json["download_url"].ToString();var hash_type = json["hash_type"].ToString();var hash_value = json["hash_value"].ToString();if (download_url != ""){int index = download_url.IndexOf(".com") + 4;string downurl = download_url.Substring(index);var Token = BuildAuthAsync("GET", body, downurl);Token = $"WECHATPAY2-SHA256-RSA2048 {Token}";string FilePath = "D:\\PublicDocumentsFile\\WaChat\\" + datetime + ".csv";using (WebClient client = new WebClient()){client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3");client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");client.Headers.Add("Authorization", Token);// 发送GET请求下载文件  byte[] fileData = client.DownloadData(download_url);// 将文件保存到本地  File.WriteAllBytes(FilePath, fileData);}DataTable dt = ReadCSV(FilePath);for (int i = 0; i < dt.Rows.Count - 2; i++){string BookkeepingTime = dt.Rows[i]["记账时间"].ToString().Substring(1);string BusinessOrderNumber = dt.Rows[i]["微信支付业务单号"].ToString().Substring(1);string SerialNumber = dt.Rows[i]["资金流水单号"].ToString().Substring(1);string BusinessName = dt.Rows[i]["业务名称"].ToString().Substring(1);string BusinessType = dt.Rows[i]["业务类型"].ToString().Substring(1);string RevenueExpenditure = dt.Rows[i]["收支类型"].ToString().Substring(1);decimal Amount = Convert.ToDecimal(dt.Rows[i]["收支金额(元)"].ToString().Substring(1));decimal AccountBalance = Convert.ToDecimal(dt.Rows[i]["账户结余(元)"].ToString().Substring(1));string SubmitApplicant = dt.Rows[i]["资金变更提交申请人"].ToString().Substring(1);string Remarks = dt.Rows[i]["备注"].ToString().Substring(1);string VoucherNumber = dt.Rows[i]["业务凭证号"].ToString().Substring(1);}}
  • 微信生成签名方法
  /// <summary>/// 构造签名串/// </summary>/// <param name="method">HTTP请求方式(全大写)</param>/// <param name="body">API接口请求参数的json字符串</param>/// <param name="uri">API接口的相对路径</param>/// <returns></returns>protected string BuildAuthAsync(string method, string body, string uri){var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();string nonce = Path.GetRandomFileName();string message = $"{method}\n{uri}\n{timestamp}\n{nonce}\n{body}\n";string signature = RequestSign(message);times = timestamp.ToString();noncerodom = nonce;sign = signature;return $"mchid=\"{mchid}\",nonce_str=\"{nonce}\",timestamp=\"{timestamp}\",serial_no=\"{serial_no}\",signature=\"{signature}\"";}/// <summary>/// 生成签名/// </summary>/// <param name="message"></param>/// <returns></returns>protected string RequestSign(string message){//加载证书 _apiCertPath API证书物理路径 _certPwd API证书密码(默认是商户号)X509Certificate2 cer = new X509Certificate2("../../apiclient_cert.p12", mchid, X509KeyStorageFlags.Exportable);if (cer != null){RSA rsa = cer.GetRSAPrivateKey();//获取私钥//查看在不同平台上的具体类型byte[] data = Encoding.UTF8.GetBytes(message);return Convert.ToBase64String(rsa.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));}else{return "";}}
  • c#下载支付宝交易账单
                string ZFBAPPID = ""; //支付宝的AppID不是应用IDstring ZFBPublicKey = ""; //支付宝公钥string ZFBPrivateKey = "";//支付宝私钥//获取前一天的交易账单string datetime = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");AlipayConfig alipayConfig = new AlipayConfig();alipayConfig.ServerUrl = "https://openapi.alipay.com/gateway.do";alipayConfig.AppId = ZFBAPPID;alipayConfig.PrivateKey = ZFBPrivateKey;alipayConfig.Format = "json";alipayConfig.AlipayPublicKey = ZFBPublicKey;alipayConfig.Charset = "UTF-8";alipayConfig.SignType = "RSA2";IAopClient alipayClient = new DefaultAopClient(alipayConfig);AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest();AlipayDataDataserviceBillDownloadurlQueryModel model = new AlipayDataDataserviceBillDownloadurlQueryModel();//model.Smid = "";model.BillType = "trade";model.BillDate = datetime;request.SetBizModel(model);AlipayDataDataserviceBillDownloadurlQueryResponse response = alipayClient.Execute(request);if (response.Code == "10000"){string strDate = DateTime.Now.AddDays(-1).ToString("yyyyMMdd");//支付宝下载默认是压缩文件string savePath = "D:\\PublicDocumentsFile\\AliPayZIP\\" + datetime + ".zip";//下载地址WebClient client = new WebClient();client.DownloadFile(response.BillDownloadUrl, savePath);//支付宝默认是两个CSV文件string FilePath = "D:\\PublicDocumentsFile\\AliPay\\20884416067761510156_" + strDate + "_业务明细.csv";string FilePath1 = "D:\\PublicDocumentsFile\\AliPay\\20884416067761510156_" + strDate + "_业务明细(汇总).csv";string zipPath = savePath;//解压的csv文件路径  string csvPath = ""; string zipFilePath = savePath;// 判断文件是否存在,存在的话先删除文件 if (File.Exists(FilePath)){File.Delete(FilePath);File.Delete(FilePath1);}//解压压缩包System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, csvPath);DataTable dt = new DataTable();string[] csvLines = File.ReadAllLines(FilePath, Encoding.GetEncoding("GBK"));string headerLine = csvLines[4];string[] headers = headerLine.Split(',');foreach (string header in headers){dt.Columns.Add(header);}// 将CSV文件的数据读取到DataTable中,从第五行开始获取截止到倒数第四行for (int i = 5; i < csvLines.Length - 4; i++){string[] data = csvLines[i].Split(',');DataRow row = dt.NewRow();for (int j = 0; j < headers.Length; j++){row[headers[j]] = data[j];}dt.Rows.Add(row);}for (int i = 0; i < dt.Rows.Count; i++){string AlipayTransactionNumber = dt.Rows[i]["支付宝交易号"].ToString();string MerchantOrderNumber = dt.Rows[i]["商户订单号"].ToString();string BusinessType = dt.Rows[i]["业务类型"].ToString();string TradeName = dt.Rows[i]["商品名称"].ToString();string CreationTime = dt.Rows[i]["创建时间"].ToString();string CompletionTime = dt.Rows[i]["完成时间"].ToString();string StoreNumber = dt.Rows[i]["门店编号"].ToString();string StoreName = dt.Rows[i]["门店名称"].ToString();string Operator = dt.Rows[i]["操作员"].ToString();string TerminalNumber = dt.Rows[i]["终端号"].ToString();string OppositeAccount = dt.Rows[i]["对方账户"].ToString();decimal Amount = Convert.ToDecimal(dt.Rows[i]["订单金额(元)"].ToString());decimal MerchantActualReceipt = Convert.ToDecimal(dt.Rows[i]["商家实收(元)"].ToString());decimal AlipayRedEnvelope = Convert.ToDecimal(dt.Rows[i]["支付宝红包(元)"].ToString());decimal JiFenBao = Convert.ToDecimal(dt.Rows[i]["集分宝(元)"].ToString());decimal AlipayDiscount = Convert.ToDecimal(dt.Rows[i]["支付宝优惠(元)"].ToString());decimal MerchantDiscount = Convert.ToDecimal(dt.Rows[i]["商家优惠(元)"].ToString());decimal VoucherVerificationAmount = Convert.ToDecimal(dt.Rows[i]["券核销金额(元)"].ToString());string CouponName = dt.Rows[i]["券名称"].ToString();decimal ConsumptionAmount = Convert.ToDecimal(dt.Rows[i]["商家红包消费金额(元)"].ToString());decimal CardConsumptionAmount = Convert.ToDecimal(dt.Rows[i]["卡消费金额(元)"].ToString());string RequestNumber = dt.Rows[i]["退款批次号/请求号"].ToString();decimal ServiceFee = Convert.ToDecimal(dt.Rows[i]["服务费(元)"].ToString());decimal Dividend = Convert.ToDecimal(dt.Rows[i]["分润(元)"].ToString());string Remarks = dt.Rows[i]["备注"].ToString();}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/213688.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

nodejs 异步函数加 await 和不加 await 的区别

在 nodejs 中&#xff0c;异步函数加上 await 和不加 await 的区别在于函数的返回值。 当一个异步函数加上 await 时&#xff0c;它会暂停当前函数的执行&#xff0c;直到异步操作完成并返回结果。这意味着可以直接使用异步操作的结果&#xff0c;而不需要使用 .then() 方法或…

什么是私有云和私有云计算?

私有云也被称为本地云架构&#xff0c;部署在企业的内部数据中心。如今&#xff0c;越来越多的提供商提供自己的私有云服务&#xff0c;以增强甚至取代企业自己的私有云环境。 美国国家标准与技术研究所 (NIST) 对私有云的定义是&#xff1a;“云基础架构为单一组织置备并为其…

【华为鸿蒙系统学习】- HarmonyOS4.0开发|自学篇

​ &#x1f308;个人主页: Aileen_0v0 &#x1f525;热门专栏: 华为鸿蒙系统学习|计算机网络|数据结构与算法 &#x1f4ab;个人格言:"没有罗马,那就自己创造罗马~" 目录 HarmonyOS 4.0 技术介绍&#xff1a; HarmonyOS三大特征&#xff1a; 1.实现硬件互助&#…

Appium 并行测试多个设备

一、前置说明 在自动化测试中&#xff0c;经常需要验证多台设备的兼容性&#xff0c;Appium可以用同一套测试运例并行测试多个设备&#xff0c;以达到验证兼容性的目的。 解决思路&#xff1a; 查找已连接的所有设备&#xff1b;为每台设备启动相应的Appium Server&#xff1b…

docker的资源控制:

docker的资源控制&#xff1a; 对容器的使用宿主机的资源进行限制 cpu 内存 磁盘i/0 docker使用linux自带的功能cgroup control grouos是linux内核系统提供的一种可以限制&#xff0c;记录&#xff0c;隔离进程所使用的物理资源 control grouos是linux内核系统提供的一种可…

CSP-202309-2 坐标变换(其二)(模拟,c++,vector建二叉树)

计算机软件能力认证考试系统 问题描述 试题编号&#xff1a;202309-3试题名称&#xff1a;梯度求解时间限制&#xff1a;1.0s内存限制&#xff1a;512.0MB问题描述&#xff1a; 背景 西西艾弗岛运营公司近期在大力推广智能化市政管理系统。这套系统是由西西艾弗岛信息中心研发…

DAPP开发【11】IPFS星际文件管理系统【简介,实践看12】

IPFS&#xff08;InterPlanetary File System&#xff09;是一个点对点的分布式文件系统&#xff0c;旨在创建一个更快速、更安全和更开放的 Web。它不同于传统的 HTTP 协议&#xff0c;因为它不需要使用一个固定的地址来访问文件&#xff0c;而是通过一个基于内容寻址的系统&a…

HeartBeat监控Mysql状态

目录 一、概述 二、 安装部署 三、配置 四、启动服务 五、查看数据 一、概述 使用heartbeat可以实现在kibana界面对 Mysql 服务存活状态进行观察&#xff0c;如有必要&#xff0c;也可在服务宕机后立即向相关人员发送邮件通知 二、 安装部署 参照章节&#xff1a;监控组件…

S32K324 UDS Bootloader开发-下位机篇-App软件开发

文章目录 前言ld文件修改增加编译文件CAN发送与接收发送接收函数调用UDS协议增加校验算法Hex文件合并总结前言 本文参考NXP官网的S32K3 Bootloader,移植实现UDS刷写功能。本文是APP软件的修改 本文参考NXP官网的S32K324 UBL,其中有一些Bug,也有一些和上位机不兼容的地方,在本…

每日一博 - 图解5种Cache策略

文章目录 概述读策略Cache AsideRead Through 写策略Write ThroughWrite AroundWrite Back 使用场景举例 概述 缓存是在系统中存储数据的临时存储器&#xff0c;用于提高访问速度。缓存策略定义了如何在缓存和主存之间管理数据 读策略 Read data from the system: &#x1f5…

vue3原生方法滚动列表

效果图 代码 import { ref, onBeforeUnmount, onUnmounted } from "vue"; //定时器初始化 let timer ref(null); //ref绑定初始化 let roll ref(null); //等同于vue2中的beforeDestroy onBeforeUnmount(() > {//清除定时器clearTimeout(timer.value); }); //等同…

AGI时代探导开发的智能化落地之路:中国企业低代码及无代码应用价值报告V6

今天分享的AGI系列深度研究报告&#xff1a;《AGI时代探导开发的智能化落地之路&#xff1a;中国企业低代码及无代码应用价值报告V6》。 &#xff08;报告出品方&#xff1a;甲子光年智库&#xff09; 报告共计&#xff1a;47页 点击添加图片描述&#xff08;最多60个字&…

机器学习与人工智能:一场革命性的变革

机器学习与人工智能&#xff1a;一场革命性的变革 人工智能的概述什么是机器学习定义解释 数据集结构机器学习应用场景 人工智能的概述 1956年8月&#xff0c;在美国汉诺斯小镇宁静的达特茅斯学院中&#xff0c;约翰麦卡锡&#xff08;John McCarthy&#xff09;、马文闵斯基&…

数据链路层的作用和三个基本问题

目录 一. 数据链路层的作用二. 数据链路层解决的三个问题2.1 数据链路和帧2.2 三个基本问题(重要)2.2.1 封装成帧2.2.2 透明传输2.2.3 差错检测 \quad 一. 数据链路层的作用 \quad \quad \quad 光有链路不能传输数据, 还要加上协议, 这样才是数据链路 数据链路层的作用就是负责…

RHEL8_Linux虚拟数据优化器VDO

本章主要介绍虚拟化数据优化器 什么是虚拟数据优化器VDO创建VDO设备以节约硬盘空间 1.了解什么是VDO VDO全称是Virtual Data Optimize&#xff08;虚拟数据优化)&#xff0c;主要是为了节省硬盘空间。 现在假设有两个文件file1和 file2&#xff0c;大小都是10G。file1和 fil…

.NET 材料检测系统崩溃分析

Windbg 分析 1. 到底是哪里的崩溃 一直跟踪我这个系列的朋友应该知道分析崩溃第一个命令就是 !analyze -v &#xff0c;让windbg帮我们自动化异常分析。 0:033> !analyze -v CONTEXT: (.ecxr) rax00000039cccff2d7 rbx00000039c85fc2b0 rcx00000039cccff2d8 rdx000000000…

洛谷P3807 Lucas定理

传送门&#xff1a; P3807 【模板】卢卡斯定理/Lucas 定理 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/P3807题干&#xff1a; 给定整数n,m,p 的值&#xff0c;求出C&#xff08;nm&#xff0c;n&#xff09;​mod p 的值。 输入数据保证…

5分钟搞懂K8S Pod Terminating/Unknown故障排查

Kubernetes集群中的Pod有时候会进入Terminating或Unknown状态&#xff0c;本文列举了6种可能的原因&#xff0c;帮助我们排查这种现象。原文: K8s Troubleshooting — Pod in Terminating or Unknown Status 有时我们会看到K8S集群中的pod进入"Terminating"或"U…

每日一练【查找总价格为目标值的两个商品】

一、题目描述 题目链接 购物车内的商品价格按照升序记录于数组 price。请在购物车中找到两个商品的价格总和刚好是 target。若存在多种情况&#xff0c;返回任一结果即可。 示例 1&#xff1a; 输入&#xff1a;price [3, 9, 12, 15], target 18 输出&#xff1a;[3,15] …

成都工业学院Web技术基础(WEB)实验一:HTML5排版标签使用

写在前面 1、基于2022级计算机大类实验指导书 2、代码仅提供参考&#xff0c;前端变化比较大&#xff0c;按照要求&#xff0c;只能做到像&#xff0c;不能做到一模一样 3、图片和文字仅为示例&#xff0c;需要自行替换 4、如果代码不满足你的要求&#xff0c;请寻求其他的…