C# 通过草料api接口获取二维码内容的方法

/// <summary>
        /// 获取二维码内容
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private string GetQrCodeStr(string path)
        {
            try
            {
                var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                var fileBytes = new byte[fs.Length];
                fs.Read(fileBytes, 0, fileBytes.Length);
                fs.Close();
                fs.Dispose();
                var httpRequestClient = new HttpRequestClient();
                httpRequestClient.SetFieldValue("Filedata", Path.GetFileName(path), "image/png", fileBytes);
                var responseText = string.Empty;
                httpRequestClient.Upload("https://upload.api.cli.im/upload.php?kid=cliim", out responseText);
                if (string.IsNullOrEmpty(responseText))
                {
                  
                    return null;
                }
                var caoliaoModel = JsonConvert.DeserializeObject<CaoliaoModel>(responseText);

                var result = WebClientPost("https://cli.im/apis/up/deqrimg", "img=" + caoliaoModel.data.path,
                    "https://cli.im/deqr", null, "application/x-www-form-urlencoded; charset=UTF-8");
                var caoliao = JsonConvert.DeserializeObject<CaoliaoResultModel>(result);
              var  decodeurl2 = caoliao.info.data[0];
                return decodeurl2;
            }
            catch (Exception ex)
            {
               
                return null;
            }
        }

 

  public class Data
    {
        public string name { get; set; }
        public string path { get; set; }
        public string filesize { get; set; }
        public string filesize_byte { get; set; }
    }
    public class CaoliaoModel
    {
        public string status { get; set; }
        public string info { get; set; }
        public Data data { get; set; }
    }
    public class Info
    {
        public string status { get; set; }
        public string info { get; set; }
        public List<string> data { get; set; }
    }
    public class CaoliaoResultModel
    {
        public string status { get; set; }
        public Info info { get; set; }
    }

 

public string WebClientPost(string url,string post, string Referer, CookieContainer cookieContainer,string contenttype= "application/json",bool agentflag = false)
        {
            var webProxy = new WebProxy();
            //if (checkBox1.Checked)
            //{
                if (!string.IsNullOrEmpty(proxyurl))
                {
                    if (proxyurl.Contains(":"))
                    {
                        var array = proxyurl.Split(':');
                        webProxy = new WebProxy(array[0], Convert.ToInt32(array[1]))
                        {
                            Credentials = new NetworkCredential("1497168579", "zz123456.")
                        };
                    }
                    else
                    {
                        webProxy = new WebProxy(proxyurl)
                        {
                            Credentials = new NetworkCredential("1497168579", "zz123456.")
                        };
                    }
                }
            //}
            var postData = Encoding.UTF8.GetBytes(post);

            var webClient = new WebClient();
            if(agentflag) 
                webClient.Proxy = webProxy;
            webClient.Headers.Add("Content-Type", contenttype);
            webClient.Headers.Add("Accept", "*/*");
            webClient.Headers.Add("Referer", Referer);
            webClient.Headers.Add("User-Agent", string.Format("Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/{0}{1}G{2}{3} Ariver/1.0.10 Jupiter/1.0.0 000001@ZLB_iphone_6.9.2 hanweb_iphone_/hanweb/dtdreamweb/bundleVersion6.9.2", DateTime.Today.Month * 11 % 12, DateTime.Today.Day * 6 % 5, DateTime.Now.Hour * 23 % 24, DateTime.Now.Minute * 59 % 60));
            webClient.Headers.Add("CotentLength", postData.Length.ToString());
            var responseData = webClient.UploadData(url, "POST",postData);
            return Encoding.UTF8.GetString(responseData);
        }
private string GetProxy()
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://1497168579.user.xiecaiyun.com/api/proxies?action=getText&key=NP60F6F0BB&count=1&word=&rand=true&norepeat=true&detail=false&ltime=10");
            httpWebRequest.Method = "GET";
            httpWebRequest.Accept = "*/*";
            httpWebRequest.UserAgent = string.Format("Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/{0}{1}G{2}{3} Ariver/1.0.10 Jupiter/1.0.0 000001@ZLB_iphone_6.9.2 hanweb_iphone_/hanweb/dtdreamweb/bundleVersion6.9.2", DateTime.Today.Month * 11 % 12, DateTime.Today.Day * 6 % 5, DateTime.Now.Hour * 23 % 24, DateTime.Now.Minute * 59 % 60);
            using (var webResponse = httpWebRequest.GetResponse())
            {
                var streamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8);
                return streamReader.ReadToEnd();

            }
        }

 

posted @ 2022-08-18 10:24  前缘Q+7589848  阅读(299)  评论(0编辑  收藏  举报