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);
byte[] fileData = client.DownloadData(download_url);
File.WriteAllBytes(FilePath, fileData