支付总括,模拟登录计算

在开发者界面用能够看出不少ptqrlogin起先的 name

smart qqC#支出总计:

亚洲必赢官网 1亚洲必赢官网 2/**//// <summary>  登录
亚洲必赢官网 3        /// </summary>
亚洲必赢官网 4        /// <param name=”url”></param>
亚洲必赢官网 5        /// <param name=”paramList”></param>
亚洲必赢官网 6        /// <returns></returns>
亚洲必赢官网 7        public static string Login(String url, String paramList)
亚洲必赢官网 8亚洲必赢官网 9        亚洲必赢官网 10{
亚洲必赢官网 11            HttpWebResponse res = null;
亚洲必赢官网 12            string strResult = “”;
亚洲必赢官网 13            try
亚洲必赢官网 14亚洲必赢官网 15            亚洲必赢官网 16{
亚洲必赢官网 17支付总括,模拟登录计算。                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
亚洲必赢官网 18                req.Method = “POST”;
亚洲必赢官网 19                req.ContentType = “application/x-www-form-urlencoded”;
亚洲必赢官网 20                req.AllowAutoRedirect = false;
亚洲必赢官网 21                CookieContainer cookieCon = new CookieContainer();
亚洲必赢官网 22                req.CookieContainer = cookieCon;
亚洲必赢官网 23                StringBuilder UrlEncoded = new StringBuilder();
亚洲必赢官网 24亚洲必赢官网 25                Char[] reserved = 亚洲必赢官网 26{ ‘?’, ‘=’, ‘&’ };
亚洲必赢官网 27                byte[] SomeBytes = null;
亚洲必赢官网 28                if (paramList != null)
亚洲必赢官网 29亚洲必赢官网 30                亚洲必赢官网 31{
亚洲必赢官网 32                    int i = 0, j;
亚洲必赢官网 33                    while (i < paramList.Length)
亚洲必赢官网 34亚洲必赢官网 35                    亚洲必赢官网 36{
亚洲必赢官网 37                        j = paramList.IndexOfAny(reserved, i);
亚洲必赢官网 38                        if (j == -1)
亚洲必赢官网 39亚洲必赢官网 40                        亚洲必赢官网 41{
亚洲必赢官网 42                            UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length – i)));
亚洲必赢官网 43                            break;
亚洲必赢官网 44                        }
亚洲必赢官网 45                        UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, j – i)));
亚洲必赢官网 46                        UrlEncoded.Append(paramList.Substring(j, 1));
亚洲必赢官网 47                        i = j + 1;
亚洲必赢官网 48                    }
亚洲必赢官网 49                    SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
亚洲必赢官网 50                    req.ContentLength = SomeBytes.Length;
亚洲必赢官网 51                    Stream newStream = req.GetRequestStream();
亚洲必赢官网 52                    newStream.Write(SomeBytes, 0, SomeBytes.Length);
亚洲必赢官网 53                    newStream.Close();
亚洲必赢官网 54                }
亚洲必赢官网 55                else
亚洲必赢官网 56亚洲必赢官网 57                亚洲必赢官网 58{
亚洲必赢官网 59                    req.ContentLength = 0;
亚洲必赢官网 60                }
亚洲必赢官网 61
亚洲必赢官网 62                res = (HttpWebResponse)req.GetResponse();
亚洲必赢官网 63                cookieheader = req.CookieContainer.GetCookieHeader(new Uri(url));
亚洲必赢官网 64                Stream ReceiveStream = res.GetResponseStream();
亚洲必赢官网 65                Encoding encode = System.Text.Encoding.GetEncoding(“GBK”);
亚洲必赢官网 66                StreamReader sr = new StreamReader(ReceiveStream, encode);
亚洲必赢官网 67                Char[] read = new Char[256];
亚洲必赢官网 68                int count = sr.Read(read, 0, 256);
亚洲必赢官网 69                while (count > 0)
亚洲必赢官网 70亚洲必赢官网 71                亚洲必赢官网 72{
亚洲必赢官网 73                    String str = new String(read, 0, count);
亚洲必赢官网 74                    strResult += str;
亚洲必赢官网 75                    count = sr.Read(read, 0, 256);
亚洲必赢官网 76                }
亚洲必赢官网 77            }
亚洲必赢官网 78            catch (Exception e)
亚洲必赢官网 79亚洲必赢官网 80            亚洲必赢官网 81{
亚洲必赢官网 82                strResult = e.ToString();
亚洲必赢官网 83            }
亚洲必赢官网 84            finally
亚洲必赢官网 85亚洲必赢官网 86            亚洲必赢官网 87{
亚洲必赢官网 88                if (res != null)
亚洲必赢官网 89亚洲必赢官网 90                亚洲必赢官网 91{
亚洲必赢官网 92                    res.Close();
亚洲必赢官网 93                }
亚洲必赢官网 94            }
亚洲必赢官网 95            return strResult;
亚洲必赢官网 96        }
亚洲必赢官网 97亚洲必赢官网 98        /**//// <summary>  获取页面HTML
亚洲必赢官网 99        /// </summary>
亚洲必赢官网 100        /// <param name=”url”></param>
亚洲必赢官网 101        /// <param name=”paramList”></param>
亚洲必赢官网 102        /// <returns></returns>
亚洲必赢官网 103        public static string getPage(String url, String paramList)
亚洲必赢官网 104亚洲必赢官网 105        亚洲必赢官网 106{
亚洲必赢官网 107            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
亚洲必赢官网 108            req.Headers[“If-None-Match”] = “36d0ed736e88c71:d9f”;
亚洲必赢官网 109            req.Referer = “”;
亚洲必赢官网 110            CookieContainer cookieCon = new CookieContainer();
亚洲必赢官网 111            req.CookieContainer = cookieCon;
亚洲必赢官网 112            req.CookieContainer.SetCookies(new Uri(url), cookieheader);
亚洲必赢官网 113            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
亚洲必赢官网 114            StreamReader sr = new StreamReader(res.GetResponseStream(),Encoding.Default);
亚洲必赢官网 115            string strResult = sr.ReadToEnd();
亚洲必赢官网 116            sr.Close();
亚洲必赢官网 117            return strResult;
亚洲必赢官网 118        }

亚洲必赢官网 119

全部开发下来其实有些都不是很难,从一起头二维码
获取到最终的收发新闻,基本上都是人云亦云浏览器的操作。都是依据http通信。一下就是此次新手学习http协议的最重要的四个类

调用:

亚洲必赢官网 120/// <summary>  登录
亚洲必赢官网 121        /// </summary>
亚洲必赢官网 122        /// <param name=”url”></param>
亚洲必赢官网 123        /// <param name=”paramList”></param>
亚洲必赢官网 124        /// <returns></returns>
亚洲必赢官网 125        public static string Login(String url, String paramList)
亚洲必赢官网 126        {
亚洲必赢官网 127            HttpWebResponse res = null;
亚洲必赢官网 128            string strResult = “”;
亚洲必赢官网 129            try
亚洲必赢官网 130            {
亚洲必赢官网 131                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
亚洲必赢官网 132                req.Method = “POST”;
亚洲必赢官网 133                req.ContentType = “application/x-www-form-urlencoded”;
亚洲必赢官网 134                req.AllowAutoRedirect = false;
亚洲必赢官网 135                CookieContainer cookieCon = new CookieContainer();
亚洲必赢官网 136                req.CookieContainer = cookieCon;
亚洲必赢官网 137                StringBuilder UrlEncoded = new StringBuilder();
亚洲必赢官网 138                Char[] reserved = { ‘?’, ‘=’, ‘&’ };
亚洲必赢官网 139                byte[] SomeBytes = null;
亚洲必赢官网 140                if (paramList != null)
亚洲必赢官网 141                {
亚洲必赢官网 142                    int i = 0, j;
亚洲必赢官网 143                    while (i < paramList.Length)
亚洲必赢官网 144                    {
亚洲必赢官网 145                        j = paramList.IndexOfAny(reserved, i);
亚洲必赢官网 146                        if (j == -1)
亚洲必赢官网 147                        {
亚洲必赢官网 148                            UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length – i)));
亚洲必赢官网 149                            break;
亚洲必赢官网 150                        }
亚洲必赢官网 151                        UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, j – i)));
亚洲必赢官网 152                        UrlEncoded.Append(paramList.Substring(j, 1));
亚洲必赢官网 153                        i = j + 1;
亚洲必赢官网 154                    }
亚洲必赢官网 155                    SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
亚洲必赢官网 156                    req.ContentLength = SomeBytes.Length;
亚洲必赢官网 157                    Stream newStream = req.GetRequestStream();
亚洲必赢官网 158                    newStream.Write(SomeBytes, 0, SomeBytes.Length);
亚洲必赢官网 159                    newStream.Close();
亚洲必赢官网 160                }
亚洲必赢官网 161                else
亚洲必赢官网 162                {
亚洲必赢官网 163                    req.ContentLength = 0;
亚洲必赢官网 164                }
亚洲必赢官网 165
亚洲必赢官网 166                res = (HttpWebResponse)req.GetResponse();
亚洲必赢官网 167                cookieheader = req.CookieContainer.GetCookieHeader(new Uri(url));
亚洲必赢官网 168                Stream ReceiveStream = res.GetResponseStream();
亚洲必赢官网 169                Encoding encode = System.Text.Encoding.GetEncoding(“GBK”);
亚洲必赢官网 170                StreamReader sr = new StreamReader(ReceiveStream, encode);
亚洲必赢官网 171                Char[] read = new Char[256];
亚洲必赢官网 172                int count = sr.Read(read, 0, 256);
亚洲必赢官网 173                while (count > 0)
亚洲必赢官网 174                {
亚洲必赢官网 175                    String str = new String(read, 0, count);
亚洲必赢官网 176                    strResult += str;
亚洲必赢官网 177                    count = sr.Read(read, 0, 256);
亚洲必赢官网 178                }
亚洲必赢官网 179            }
亚洲必赢官网 180            catch (Exception e)
亚洲必赢官网 181            {
亚洲必赢官网 182                strResult = e.ToString();
亚洲必赢官网 183            }
亚洲必赢官网 184            finally
亚洲必赢官网 185            {
亚洲必赢官网 186                if (res != null)
亚洲必赢官网 187                {
亚洲必赢官网 188                    res.Close();
亚洲必赢官网 189                }
亚洲必赢官网 190            }
亚洲必赢官网 191亚洲必赢官网 ,            return strResult;
亚洲必赢官网 192        }
亚洲必赢官网 193        /// <summary>  获取页面HTML
亚洲必赢官网 194        /// </summary>
亚洲必赢官网 195        /// <param name=”url”></param>
亚洲必赢官网 196        /// <param name=”paramList”></param>
亚洲必赢官网 197        /// <returns></returns>
亚洲必赢官网 198        public static string getPage(String url, String paramList)
亚洲必赢官网 199        {
亚洲必赢官网 200            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
亚洲必赢官网 201            req.Headers[“If-None-Match”] = “36d0ed736e88c71:d9f”;
亚洲必赢官网 202            req.Referer = “”;
亚洲必赢官网 203            CookieContainer cookieCon = new CookieContainer();
亚洲必赢官网 204            req.CookieContainer = cookieCon;
亚洲必赢官网 205            req.CookieContainer.SetCookies(new Uri(url), cookieheader);
亚洲必赢官网 206            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
亚洲必赢官网 207            StreamReader sr = new StreamReader(res.GetResponseStream(),Encoding.Default);
亚洲必赢官网 208            string strResult = sr.ReadToEnd();
亚洲必赢官网 209            sr.Close();
亚洲必赢官网 210            return strResult;
亚洲必赢官网 211        }

自作者要做的正是 
模拟浏览器的操作,把它转换来大家温馨的客户端。所以只假设浏览器里一些大家都要效仿。接下来判断2维码失效,两秒叁回啊,弄三个Timer

/// <summary>
/// HTTP网络通信类
/// </summary>
public static class HTTP
{

        string postData =
“userName=admin&password=pass&area=2006&Submit=%B5%C7+%C2%BC”;            
        string strLogin, strResult;
        strLogin = Login(“”, postData);

调用:

 

public static CookieContainer cookies = new CookieContainer();
static CookieCollection CookieCollection = new CookieCollection();
static CookieContainer CookieContainer = new CookieContainer();
/// <summary>
/// HTTP请求
/// </summary>
/// <param name=”url”>连接</param>
/// <param name=”enc”>编码</param>
/// <returns></returns>
public static string HttpGet(string url, Encoding enc)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create;
request.Timeout = 10000;//设置10秒超时
request.Proxy = null;
request.Method = “GET”;
request.ContentType = “application/x-www-from-urlencoded”;
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream;
StringBuilder sb = new StringBuilder();
sb.Append(reader.ReadToEnd;
reader.Close();
reader.Dispose();
response.Close();
return sb.ToString();
}
/// <summary>
/// 带referer的http请求连接
/// </summary>
/// <param name=”url”></param>
/// <param name=”referer”></param>
/// <param name=”timeout”></param>
/// <param name=”encode”></param>
/// <param name=”NoProxy”></param>
/// <returns></returns>
public static string Get(string url, string referer =
“”, int
timeout = 100000, Encoding encode = null, bool NoProxy = false)
{
string dat;
HttpWebResponse res = null;
HttpWebRequest req;
try
{
req = (HttpWebRequest)WebRequest.Create;
req.CookieContainer = cookies;
req.AllowAutoRedirect = false;
req.Timeout = timeout;
req.Referer = referer;
if
req.Proxy = null;
req.UserAgent = “Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0)
Gecko/20100101 Firefox/47.0”;
res = (HttpWebResponse)req.GetResponse();

         strResult = getPage(“”, “”);
//输出
         this.webBrowser1.Document.Write(strResult);

        string postData =
“userName=admin&password=pass&area=2006&Submit=%B5%C7+%C2%BC”;            
        string strLogin, strResult;
        strLogin = Login(“”, postData);

 

cookies.Add(res.Cookies);
}
catch (HttpException)
{
return “”;
}
catch (WebException)
{
return “”;
}
StreamReader reader;

         strResult = getPage(“”, “”);
//输出
         this.webBrowser1.Document.Write(strResult);

smart 类

reader = new StreamReader(res.GetResponseStream(), encode == null ?
Encoding.UTF8 : encode);
dat = reader.ReadToEnd();

#region 第三讲检查二维码状态
private static System.Timers.Timer StatuTimer = new
System.Timers.Timer();
public static void Login()
{
StatuTimer.AutoReset = true;
StatuTimer.Elapsed +=StatuTimer_Elapsed;
StatuTimer.Interval = 2000;
StatuTimer.Start();
}

res.Close();
req.Abort();

public static string Login_err = “其他”;
/// <summary>
/// 检查二维码状态
/// </summary>
public static void Login_GetStatu()
{
string dat;
dat =
HTTP.Get(string.Format(“”,
ptqrtoken));
string[] temp = dat.Split(‘\”);
switch (temp[1])
{
case (“6五”): //二维码失效
Login_err = “2维码失效”;
break;
case (“6六”): //等待扫描
Login_err = “等待扫描”;
break;
case (“67”): //等待确认
Login_err = “等待确认”;
break;
case (“0”): //已经确认
Login_err = “已经认同”;
StatuTimer.Stop();
break;

return dat;
}
/// <summary>
/// 带referer data的http post
/// </summary>
/// <param name=”url”></param>
/// <param name=”data”></param>
/// <param name=”Referer”></param>
/// <param name=”timeout”></param>
/// <param name=”encode”></param>
/// <returns></returns>
public static string Post(string url, string data, string Referer =

method= “POST”, int timeout = 100000, Encoding encode = null)
{
string dat = “”;
HttpWebRequest req;
try
{
req = WebRequest.Create as HttpWebRequest;
req.CookieContainer = cookies;
req.ContentType = “application/x-www-form-urlencoded”;
req.Method = method;
req.Proxy = null;
req.Timeout = timeout;
req.UserAgent = “Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0)
Gecko/20100101 Firefox/47.0”;
req.ProtocolVersion = HttpVersion.Version10;
req.Referer = Referer;

default: break;
}

byte[] mybyte = Encoding.Default.GetBytes;
req.ContentLength = mybyte.Length;

}

Stream stream = req.GetRequestStream();
stream.Write(mybyte, 0, mybyte.Length);

/// <summary>
/// 每两秒检查叁次贰维码状态
/// </summary>
private static void StatuTimer_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
Login_GetStatu();
}
#endregion

HttpWebResponse res = req.GetResponse() as HttpWebResponse;

 

cookies.Add(res.Cookies);
stream.Close();

 

StreamReader SR = new StreamReader(res.GetResponseStream(), encode ==
null ? Encoding.UTF8 : encode);
dat = SR.ReadToEnd();
res.Close();
req.Abort();
}
catch (HttpException)
{
return “”;
}
catch (WebException)
{
return “”;
}

HTTP 类

return dat;
}
/// <summary>
/// Hash 转换
/// </summary>
/// <param name=”s”></param>
/// <returns></returns>
public static int Hash33
{
var e = 0;
foreach (var t in s)
e += (e << 5) + t;
return int.MaxValue & e;
}
/// <summary>
/// 获取CookieCollection下 所有cookie
/// </summary>
/// <param name=”cc”></param>
/// <returns></returns>
public static string GetAllCookies(CookieCollection cc)
{
//List<Cookie> lstCookies = new List<Cookie>();
string lstCookies = “”;
ArrayList table = (ArrayList)cc.GetType().InvokeMember(“m_list”,
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, cc, new object[] { });

 

if (table != null)
{
for (int i = 0; i < table.Count; i++)
{
string[] tacookie = table[i].ToString().Split;
lstCookies = tacookie[1].ToString;
}
}

/// <summary>
/// 带referer的http请求连接
/// </summary>
/// <param name=”url”></param>
/// <param name=”referer”></param>
/// <param name=”timeout”></param>
/// <param name=”encode”></param>
/// <param name=”NoProxy”></param>
/// <returns></returns>
public static string Get(string url, string referer =
“”, int
timeout = 100000, Encoding encode = null, bool NoProxy = false)
{
string dat;
HttpWebResponse res = null;
HttpWebRequest req;
try
{
req = (HttpWebRequest)WebRequest.Create(url);
req.CookieContainer = cookies;
req.AllowAutoRedirect = false;
req.Timeout = timeout;
req.Referer = referer;
if (NoProxy)
req.Proxy = null;
req.UserAgent = “Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0)
Gecko/20100101 Firefox/47.0”;
res = (HttpWebResponse)req.GetResponse();

return lstCookies;
}
public delegate void Post_Async_Action(string data);
private class Post_Async_Data
{
public HttpWebRequest req;
public Post_Async_Action post_Async_Action;
}
public static void Post_Async(string url, string PostData,
Post_Async_Action action, string Referer =
“”, int
timeout = 100000)
{
HttpWebRequest req = WebRequest.Create as HttpWebRequest;
req.CookieContainer = cookies;
req.ContentType = “application/x-www-form-urlencoded”;
req.Method = “POST”;
req.Referer = Referer;
req.UserAgent = “Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0)
Gecko/20100101 Firefox/47.0”;
req.Proxy = null;
req.ProtocolVersion = HttpVersion.Version10;
req.ContinueTimeout = timeout;

cookies.Add(res.Cookies);
}
catch (HttpException)
{
return “”;
}
catch (WebException)
{
return “”;
}
StreamReader reader;

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes;
Stream stream = req.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();

reader = new StreamReader(res.GetResponseStream(), encode == null ?
Encoding.UTF8 : encode);
dat = reader.ReadToEnd();

Post_Async_Data dat = new Post_Async_Data();
dat.req = req;
dat.post_Async_Action = action;
req.BeginGetResponse(new AsyncCallback(Post_Async_ResponesProceed),
dat);
}

res.Close();
req.Abort();

private static void Post_Async_ResponesProceed(IAsyncResult ar)
{
StreamReader reader = null;
Post_Async_Data dat = ar.AsyncState as Post_Async_Data;
HttpWebRequest req = dat.req;
HttpWebResponse res = req.GetResponse() as HttpWebResponse;
reader = new StreamReader(res.GetResponseStream;
string temp = reader.ReadToEnd();
res.Close();
req.Abort();
dat.post_Async_Action;
}
}

return dat;
}

之所以总括下来差不四只借使清楚一点http协议,基本上网页版的顺序,大家都得以随心所欲的转换来图形桌面版,从而依照本人我业务展成本付。

 

帮助本身接触过
最多的正是Tmall客,天猫商城天猫商城京东店数据,当然这个都是官方api的。kaola jd
tianmao 等购物网址的分类,商品数量爬取分析。

率先次发新手教程很多或许看的不是很通晓,可是有源码。能够依照源码的笺注进行学习。当中最重要的是json的分析了。因为本人也是新手,所以广大都以要查一下材料才领悟的。希望这几讲能给1些就学http协议的新手一些启发(小编也是新手,说错勿怪。)

接下去便是做个图形界面包车型客车smart qq机器人。

网站地图xml地图