First, start from scratch to make a web QQ robot, the first step to get Smart QQ QR code

Source: Internet
Author: User

Beginner Tutorials:

Preface: Recently looked at a long time ago to do the QQ robot failed, and recently also in the job, the time is very comfortable. Decided to start a new web QQ Robot PC protocol parsing out a little time later to do.

Preparatory work:

Compilation tool: vs2017

Programming languages: C # or. Net

Start building an SDK new file-project-Select Class Library-(WEBQQSDK)-Add a class SMARTQQ

The first step, login to the smart QQ, to this HTTP protocol, do robot interaction Bar, TX to this version of a lot of features removed, basic group chat, private chat and other information is still in. (Use Google Chrome to access http://web2.qq.com/press F12 to enter the developer window to enter Network-all)

Start the connection to the QR code name is/ptqrshow. The request connection of the QR code

https://ssl.ptlogin2.qq.com/ptqrshow?appid=501004106&e=2&l=M&s=3&d=72&v=4&t= 0.05929581762262637&daid=164&pt_3rd_aid=0

The yellow one is random. Later you can get a random. I've done an HTTP communication class before, and these will be open source to the code cloud above.

private static Random Rand = new Random ();
static int ptqrtoken = 0;//Check the QR code status needs to be verified
<summary>
The first step is to get the QR code
</summary>
<returns></returns>
public static Image Login_getqrcode ()
{

HttpWebRequest req = (HttpWebRequest) webrequest.create ("https://ssl.ptlogin2.qq.com/ptqrshow?appid=501004106& E=2&l=m&s=3&d=72&v=4&t=#{t}&daid=164&pt_3rd_aid=0 ". Replace ("#{t}", Rand. Nextdouble (). ToString ()));
Req. Cookiecontainer = http.cookies;//Set Cookies
HttpWebResponse res = (HttpWebResponse) req. GetResponse ();//request to Response can compare the developer interface data
Ptqrtoken = HTTP. Hash33 (HTTP. Getallcookies (Res. Cookies);//save, check the QR code status needs to be verified.
Return Image.fromstream (Res. GetResponseStream ());

}

This has been acquired to the QR code. Create a new Login Form window, pull a PictureBox component, and a button.

Window Login Code

private void Button1_Click (object sender, EventArgs e)
{
pictureBox1.Image = Smartqq.login_getqrcode ();
}

Run

Run the result, this is the login QR code. The first step is done here.

HTTP class

<summary>
HTTP network Communication Class
</summary>
public static Class HTTP
{

public static Cookiecontainer cookies = new Cookiecontainer ();
<summary>
Hash Conversion
</summary>
<param name= "S" ></param>
<returns></returns>
public static int Hash33 (string s)
{
var e = 0;
foreach (Var t in s)
E + = (e << 5) + t;
return int. MaxValue & E;
}
<summary>
Get all Cookies under cookiecollection
</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 (). Trim ();
}
}


return lstcookies;
}
}

First, start from scratch to make a web QQ robot, the first step to get Smart QQ QR code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.