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.pswp.cn/news/213688.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/213688.shtml
英文地址,請注明出處:http://en.pswp.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;請尋求其他的…