C # WebQQ protocol group robot (2 ),

Source: Internet
Author: User

C # WebQQ protocol group robot (2 ),

The source of this article http://blog.csdn.net/zhujunxxxxx/ If You Need To reprint please indicate the source!

Next to the previous article http://blog.csdn.net/zhujunxxxxx/article/details/38931287my content

The above implementation is related to group operations

The next step is to obtain the friend information.

/// <Summary> /// obtain the friend list information /// </summary> public void GetFriendList () {Dictionary <string, Object> r = new Dictionary <string, object> (); r. add ("h", "hello"); r. add ("hash", this. hash); r. add ("vfwebqq", this. vfwebqq); Dictionary <string, Object> data = new Dictionary <string, Object> (); data. add ("r", JsonConvert. serializeObject (r); string postdata = Tool. makePostData (data); HttpItem item = new HttpIte M () {URL = "http://s.web2.qq.com/api/get_user_friends2", Method = "POST", IsToLower = false, Timeout = 100000, Postdata = postdata, Host = HOST [1], referer = REFERER [1], UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36 ", // The default value of the browser type, version, and operating system options is ContentType = "application/x-www-form-urlencoded", ResultType = ResultType. str Ing}; HttpResult result = http. getHtml (item); JObject ret = (JObject) JsonConvert. deserializeObject (result. html); JObject retjson = (JObject) ret ["result"]; // foreach (JToken jk in retjson ["marknames"]) {this. friendlist. add (jk ["uin"]. toString (), jk ["markname"]. toString ();} // foreach (JToken jk in retjson ["info"]) {if (! This. friendlist. containsKey (jk ["uin"]. toString () this. friendlist. add (jk ["uin"]. toString (), jk ["nick"]. toString ());}}


This method can be used to obtain information about a friend, which is divided into two parts: Friend information with a remark name and friend information without a remark name.

Save this part of information for future use.

Obtain the information of a specific friend (this is also used to obtain your own information)

Public void GetFriendInfo (string tuin) {string url = "http://s.web2.qq.com/api/get_friend_info2? Tuin = {$ tuin} & verifysession = & code = & vfwebqq = {$ vfwebqq} & t = 1402534798024 "; url = url. replace ("{$ vfwebqq}", vfwebqq); url = url. replace ("{$ tuin}", tuin); HttpItem item = new HttpItem () {URL = url, Encoding = System. text. encoding. getEncoding ("UTF-8"), Method = "get", IsToLower = false, Timeout = 100000, ReadWriteTimeout = 30000, Host = HOST [1], Referer = REFERER [1], userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv: 18.0) Gecko/20100101 Firefox/18.0", // your browser type, version, the default value of the Operating System option is ContentType = "application/x-www-form-urlencoded", ResultType = ResultType. string ,}; HttpResult result = http. getHtml (item );}


Next, send a message to a friend.

Public void SendPersonMsg (string tuin, string msg) {string style = "\" {content} \ ""; string temp = ""; temp + = style. replace ("{content}", msg) + ","; temp = temp. substring (0, temp. length-1); Random rd = new Random (); int msg_id = (rd. next (100000) + 100000); string content = "[{$ msg}, \" \ ", [\" font \ ", {\" name \": \ "\", \ "size \": \ "10 \", \ "style \": [0, 0], \ "color \": \ "000000 \"}] "; content = content. replace ("{$ msg}", temp); Dictionary <string, Object> r = new Dictionary <string, Object> (); r. add ("to", tuin); r. add ("face", 561); r. add ("content", content); r. add ("msg_id", msg_id); r. add ("clientid", this. clientid); r. add ("psessionid", this. psessionid); Dictionary <string, Object> data = new Dictionary <string, Object> (); data. add ("r", JsonConvert. serializeObject (r); data. add ("clientid", this. clientid); data. add ("psessionid", this. psessionid); string postdata = Tool. makePostData (data); HttpItem item = new HttpItem () {URL = "http://d.web2.qq.com/channel/send_buddy_msg2", Accept = "*/*", Method = "POST", IsToLower = false, keepAlive = true, Timeout = 100000, Postdata = postdata, Host = HOST [0], Referer = REFERER [0], UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) appleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2041.4 Safari/537.36 ", ContentType =" application/x-www-form-urlencoded ", ResultType = ResultType. string}; HttpResult result = http. getHtml (item); JObject ret = (JObject) JsonConvert. deserializeObject (result. html );}

Well, this article and the previous article basically implemented the basic functions of WebQQ,

To keep QQ online, for example, if we send a heartbeat request to the server for a certain period of time, the returned value of the heartbeat request is the message we receive, this is very important. If you want to process group messages, you must process them here.

Public void HeartBreak () {/* Dictionary <string, Object> r = new Dictionary <string, Object> (); r. add ("clientid", this. clientid); r. add ("psessionid", this. psessionid); r. add ("key", 0); r. add ("ids", "[]"); Dictionary <string, Object> data = new Dictionary <string, Object> (); data. add ("r", JsonConvert. serializeObject (r); data. add ("clientid", this. clientid); data. add ("psessionid", this. psessionid); string postdata2 = Tool. makePostData (data ); */string postdata = "r = % 7B % 22 clientid % 22% 3A % 22 {$ clientid} % 22% 2C % 22 psessionid % 22% 3A % 22 {$ psessionid} % 22% 2C % 22key % 22% 3A0% 2C % 22ids % 22% 3A % 5B % 5D % 7D & clientid ={$ clientid} & psessionid ={$ psessionid }"; postdata = postdata. replace ("{$ clientid}", this. clientid); postdata = postdata. replace ("{$ psessionid}", this. psessionid); HttpItem item = new HttpItem () {URL = "http://d.web2.qq.com/channel/poll2", Method = "POST", IsToLower = false, Timeout = 100000, Postdata = postdata, host = HOST [0], Referer = REFERER [0], UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) chrome/34.0.1847.116 Safari/537.36 ", // your browser type, version, and operating system options. The default value is ContentType =" application/x-www-form-urlencoded ", resultType = ResultType. string}; HttpResult result = http. getHtml (item); JObject ret = (JObject) JsonConvert. deserializeObject (result. html); JObject retjson = (JObject) ret ["result"] [0]; if (retjson ["poll_type"]. toString () = "group_message") {JObject msg = (JObject) retjson ["value"]; ProcessMsg (msg);} Thread. sleep (2000 );}

There are still some extended content in sending information. I haven't studied this part yet. If anyone has done so, I 'd like to share it with me.

 

 


 


In C language-> what?

-> Is a whole. It is used to point to a struct, class in C ++, and other pointers containing sub-data to obtain sub-data. In other words, if we define a struct in C and declare a pointer pointing to this struct, we need to use "->" to retrieve the data in the struct using the pointer ".
For example:
Struct Data
{
Int a, B, c;
};/* Define struct */
Struct Data * p;/* define struct pointer */
Struct Data A = {1, 2, 3};/* declare variable */
Int x;/* declare a variable x */
P = & A;/* point p to */
X = p-> a;/* indicates that the data item a in the struct pointed to by p is assigned to x */
/* Because p points to A, p-> a = A. a, that is, 1 */

For the first problem, p = p-> next; this should appear in the linked list of C language. next here should be a struct pointer of the same type as p, and its definition format should be:
Struct Data
{
Int;
Struct Data * next;
};/* Define struct */
............
Main ()
{
Struct Data * p;/* declare the pointer Variable p */
......
P = p-> next;/* assign the value in next to p */
}
The linked list pointer is a difficulty in C language, but it is also the key. It is very useful to learn it. To be careful, you must first talk about variables and pointers.
What is a variable? The so-called variables should not be simply thought that the amount will become a variable. Let's use the question of our Dean: "Is the classroom changing ?" Change, because there are different people in the classroom every day, but they do not change, because the classroom is always there, and it does not become larger or smaller. This is the variable: There is a constant address and a variable storage space. Under normal circumstances, we only see the variable in the room, that is, its content, but do not pay attention to the variable address, but the C language pointer is the address of the room. We declare that variables are equivalent to building a house to store things. We can directly watch things in the house, while declaring pointers is equivalent to getting a positioner. When a pointer points to a variable, it is to use the pointer to locate the variable. Then we can use the pointer to find the variable "tracked" and get the content in it.
What about struct? The structure is equivalent to a villa composed of several houses, and several houses are bound for use together. Suppose there are many such villas distributed in a big maze, and each villa has a house. The location information of another villa is put in it. Now you have found the first villa with the positioner and obtained what you want from it (the data part of the linked list ), then, calculate the location of the next villa into your positioner (p = p-> next), and go down to the next villa ...... If you go on like this, you will know that the information of a villa on the ground is gone (p-> next = NULL), and your trip is over. This is the process of traversing a linked list. Now you can understand the meaning of p = p-> next!
Write so much. I hope you can understand.
If you want to learn c and C ++ well, you must be familiar with linked lists and pointers!

In C language-> what?

-> Is a whole. It is used to point to a struct, class in C ++, and other pointers containing sub-data to obtain sub-data. In other words, if we define a struct in C and declare a pointer pointing to this struct, we need to use "->" to retrieve the data in the struct using the pointer ".
For example:
Struct Data
{
Int a, B, c;
};/* Define struct */
Struct Data * p;/* define struct pointer */
Struct Data A = {1, 2, 3};/* declare variable */
Int x;/* declare a variable x */
P = & A;/* point p to */
X = p-> a;/* indicates that the data item a in the struct pointed to by p is assigned to x */
/* Because p points to A, p-> a = A. a, that is, 1 */

For the first problem, p = p-> next; this should appear in the linked list of C language. next here should be a struct pointer of the same type as p, and its definition format should be:
Struct Data
{
Int;
Struct Data * next;
};/* Define struct */
............
Main ()
{
Struct Data * p;/* declare the pointer Variable p */
......
P = p-> next;/* assign the value in next to p */
}
The linked list pointer is a difficulty in C language, but it is also the key. It is very useful to learn it. To be careful, you must first talk about variables and pointers.
What is a variable? The so-called variables should not be simply thought that the amount will become a variable. Let's use the question of our Dean: "Is the classroom changing ?" Change, because there are different people in the classroom every day, but they do not change, because the classroom is always there, and it does not become larger or smaller. This is the variable: There is a constant address and a variable storage space. Under normal circumstances, we only see the variable in the room, that is, its content, but do not pay attention to the variable address, but the C language pointer is the address of the room. We declare that variables are equivalent to building a house to store things. We can directly watch things in the house, while declaring pointers is equivalent to getting a positioner. When a pointer points to a variable, it is to use the pointer to locate the variable. Then we can use the pointer to find the variable "tracked" and get the content in it.
What about struct? The structure is equivalent to a villa composed of several houses, and several houses are bound for use together. Suppose there are many such villas distributed in a big maze, and each villa has a house. The location information of another villa is put in it. Now you have found the first villa with the positioner and obtained what you want from it (the data part of the linked list ), then, calculate the location of the next villa into your positioner (p = p-> next), and go down to the next villa ...... If you go on like this, you will know that the information of a villa on the ground is gone (p-> next = NULL), and your trip is over. This is the process of traversing a linked list. Now you can understand the meaning of p = p-> next!
Write so much. I hope you can understand.
If you want to learn c and C ++ well, you must be familiar with linked lists and pointers!

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.