The previous article introduced how to borrow WEBQQ Agreement landing QQ, this article mainly talk about how to achieve mass message. As far as I know, there are 3 types of messages, namely, friend messages, group messages, and temporary session messages (this is usually a mass of group members). 3 messages correspond to 3 methods (3 post methods), which are described in turn.
1. Mass Friend message
To mass a friend message, first get the Message object, which is also the friend list. Only to get the identity of each QQ friend, only to know who to send messages. So, the first step in the group is actually to get the object, here is to get a friend list. Here is the POST request information for the Get Friends list:
Request url:http://s.web2.qq.com/api/get_user_friends2request method:postcontent-type:application/ X-www-form-urlencodedreferer:http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1form-data:r= {"VFWEBQQ": "23aedade67a2278b9a807015eb4bcad5771671c3a7c5a5e7c017034b9ba9d3f28407f179e5f34566", "Hash": " 51c8576a0e1b5a7d "}
URL address is very simple, see the name also know the meaning of the post method. Be sure to remember to set the request header Content-type to application/x-www-form-urlencoded (the Retcode returned without setting the POST request is not 0). Also to set the request header Referer, otherwise it will fail (many of the following methods to set Referer). And then the form data, as before, the JSON string must be preceded with "r=". VFWEBQQ, as I mentioned in the previous article, gets the value returned by VFWEBQQ alone, not the value returned by the second login success. Hash is a certain way to obtain the value of encryption, the same as the password is encrypted by the JS file. This side first attached JS Link: http://0.web.qstatic.com/webqqpic/pubapps/0/50/eqq.all.js. The encryption method is in this JS, the code is formatted to find the P = function (b, j) This method (the parameters may not be b,j, the method will change every time), only the method is extracted, the encryption is used to this method. b That is the login QQ account, J is the PTWEBQQ that was acquired before landing. Below first put out after I mention to change the function name after the hash encryption method (at least today or this method, even if the method changed, JS file address is not changed, the method structure is roughly similar, even if do not know how to encrypt, in the JS file to find a similar method is also easy):
function Gethash (b, j) {for (var a = [], i = 0; i < j.length; i++) a[i% 4] ^= j.charcodeat (i); var w = ["EC", "OK"],d = [];d [0] = b >> & 255 ^ w[0].charcodeat (0);d [1] = b >> & 255 ^ w[0].charcodeat (1);d [2] = b >& Gt 8 & 255 ^ w[1].charcodeat (0);d [3] = b & 255 ^ w[1].charcodeat (1); w = [];for (i = 0; i < 8; i++) w[i] = i% 2 = = 0? A[i >> 1]: d[i >> 1];a = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "B", "C", "D", "E", "F"];d = ""; for (i = 0; i < w.length; i++) D + = A[w[i] >> 4 & 15],d + a[w[i] & 15];return D};
Here is a Java call JS method:
/** * Get post parameter hash of QQ Friend list * * @param paras * @return * @throws scriptexception * @throws filenotfoundexception * @thro WS nosuchmethodexception */public static string Gethash (String QQ, String ptwebqq) {Object T = null;try {Scriptenginemanag Er m = new Scriptenginemanager (); ScriptEngine se = M.getenginebyname ("javascript"); Se.eval (new FileReader (New File ("Resources/js/eqq.all.js")); t = Se.eval ("Gethash" "+ QQ +" \ ", \" "+ ptwebqq +" \ ")"); return t.tostring (); catch (Exception e) {e.printstacktrace ();} return t.tostring ();}
Finally attach the method to send the POST request, first assemble the sent JSON string, here remember,json data goes through URL transcoding (outside "r=" does not need to transcode)
Getfriendliststr = "{\" vfwebqq\ ": \" "+ vfwebqq +" \ ", \" hash\ ": \" "+ hash +" \ "}"; getfriendliststr = "r=" + Urlencoder.encode (Getfriendliststr, "utf-8");
Here is the Post method:
Get buddy list public static Boolean getfriendlist () throws Exception {//POST request Defaulthttpclient client = new Defaulthttpclien T (); HttpPost Postjson = new HttpPost ("Http://s.web2.qq.com/api/get_user_friends2");p ostjson.setheader ("Referer", "http ://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1 "); Httpclientparams.setcookiepolicy (Client.getparams (), cookiepolicy.browser_compatibility); Client.getParams (). Setparameter (Coreconnectionpnames.connection_timeout), Client.getparams (). Setparameter ( Coreconnectionpnames.so_timeout, 5000); stringentity entity = new stringentity (GETFRIENDLISTSTR); Entity.setcontenttype ("application/x-www-form-urlencoded" );p ostjson.setentity (entity);//Set Cookiestoreif (cs! = null) {Client.setcookiestore (CS);} Get the returned JSON packet HttpResponse HttpResponse = Client.execute (Postjson); Httpentity httpent = httpresponse.getentity ();//Save cookiestorecs = Client.getcookiestore (); String Line; StringBuffer sb = new StringBuffer (); if (httpent! = null) {BufferedReader BR = NEW BufferedReader (New InputStreamReader (Httpent.getcontent (), "UTF-8")); while (line = Br.readline ()) = null) { Sb.append (line);} Br.close ();} Jsonobject obj = new Jsonobject (sb.tostring ()), if (Obj.getint ("retcode") = = 0) {Jsonobject res = obj.getjsonobject ("Resul T "); Qqmsghandler.getinstance (). Getfriendlist (res);//process information, get Friend list return true;} else {return false;}}
The JSON data that the request was successfully returned is as follows:
{"Retcode": 0, "result": {"Friends": [{"Flag": 0, "UIn": 2741681712, "categories": 0},{"flag": 0, "UIn": 2117029336, " Categories ": 0}]," Marknames ": []," categories ": []," vipinfo ": [{" Vip_level ": 0," U ": 2741681712," IS_VIP ": 0},{" Vip_ Level ": 0," U ": 2117029336," IS_VIP ": 0}]," info ": [{" Face ": 303," flag ": 294126146," Nick ":" Scumvirus "," UIn " : 2741681712},{"Face": 564, "flag": 8388608, "Nick": "Scumvirus", "UIn": 2117029336}]}}
In Friends There is categories this attribute, may be the friend group's flag bit, but here I did not study, because I only did the mass all friend message. Interested friends can be in-depth analysis of the group of friends, so that you can specify only to a group of friends to send messages, so that those who live and work a QQ people to send messages will be more convenient. Info is similar to friends, but does not have a group message and has more user nicknames. So I only intercepted the data in info as a friend list, UIn is the identity of each friend, Nick is the nickname. Face do not know what, I did not go into the study, flag is also a sign, but the specific role I do not know, because the implementation of the Mass function UIn as the logo is sufficient. The middle of the vipinfo should be related to QQ members of the information, but generally do not have the QQ robot this aspect of demand, I directly ignored.
The next thing you need to do is send a friend message. In fact, the bulk of the message is to send a message to each friend (I did not try to write in the JSON array in the form of all the messages, do not know if you can achieve a mass).
Request url:http://d.web2.qq.com/channel/send_buddy_msg2request method:postreferer:http://d.web2.qq.com/ Proxy.html?v=20130916001&callback=1&id=2form-data:r={"to": 2741681712, "Content": "[\" 123\ ", [\" font\ ", {\" Name\ ": \" song body \ ", \" size\ ": 10,\" style\ ": [0,0,0],\" color\ ": \" 000000\ "}]]", "Face": 564, "ClientID": 53999199, "msg_id" : 38600001, "Psessionid": " 8368046764001d636f6e6e7365727665725f77656271714031302e3133392e372e313630000054bd00000bcd026e04003654298d6d0000000a404e364 b386b707858676d000000286740432cf4f2628258046027ab71e7c932587058acf842d2c727a076b663ff32b4082a088f3c4521 "}
Still a POST request, but take the Referer,json string format as shown above. To is the sending object is the friend's uin,content to send the text of the relevant information, I sent the most common message, all parameters are the default, if you want to send something different, change the parameters. ClientID same as landing, random 8-9 bit, casually write, my program This parameter is written fixed default value. msg_id to send the identity of the message, casually write a number, and then each post a self-increment of 1 as a distinction (even if it does not seem to affect each time, but the best +1), Psessionid is also a successful return of the login parameters. The code is no different from the previous one.
2. Mass group messages
First, get the object, that is, the group list. • The post request to get the group message is as follows:
Request url:http://s.web2.qq.com/api/get_group_name_list_mask2request method:postcontent-type:application/ X-www-form-urlencodedreferer:http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1form-data:r= {"VFWEBQQ": "23aedade67a2278b9a807015eb4bcad5771671c3a7c5a5e7c017034b9ba9d3f28407f179e5f34566", "Hash": " 51c8576a0e1b5a7d "}
Method roughly the same as when you get a friend list, only the URL address is different, the others are the same (including JSON data). The JSON data returned is as follows:
{"Retcode": 0, "result": {"gmasklist": [], "gnamelist": [{"Flag": 1090520065, "name": "Banana hides in the bedding does not give H package", "GID": 4065055661, " Code ": 818309331},{" flag ": 17826817," name ":" Scumvirus "," gid ": 1068943425," code ": 1244601995},{" flag ": 16778241," Name ": Eternal, Night", "gid": 818744232, "code": 171813541},{"flag": 16778241, "name": "Scumvirus Robot", "GID": 2646811562, "code" : 3760910371}], "Gmarklist": []}}
GID is the group identifier, which is the object we send the group message to. But code is also an indicator of the group, but different from GID.
Here is a brief explanation of UIn and GID is the friend identification and group identification, for the same object (a friend or 1 groups), the same account each login to obtain the same identity, but different accounts get different. For example, a, B in Group C, but a login to obtain C after the GID for the 1,b login to obtain C's GID may be 2, anyway, different from a obtained. But code is not the same, each time the login to get to the same group of GID is the same, such as on the wing, night this group, my 2 account login to obtain the GID is 818744232 this value, has remained unchanged. GID can only be sent as a group message identity, to get information about group members, it is code as a group identity, which is mentioned when sending a temporary session message.
The request to send the group message is as follows:
Request url:http://d.web2.qq.com/channel/send_qun_msg2request method:postcontent-type:application/ X-www-form-urlencodedreferer:http://d.web2.qq.com/proxy.html?v=20130916001&callback=1&id=2form-data:r= {"Group_uin": 1068943425, "Content": "[\" 123\ ", [\" font\ ", {\" name\ ": \" arial \ ", \" size\ ": 10,\" style\ ": [0,0,0],\" Color\ " : \ "000000\"}]] "," Face ": 564," ClientID ": 53999199," msg_id ": 38600002," Psessionid ":" 8368046764001d636f6e6e7365727665725f77656271714031302e3133392e372e313630000054bd00000bcd026e04003654298d6d0000000a404e364 b386b707858676d000000286740432cf4f2628258046027ab71e7c932587058acf842d2c727a076b663ff32b4082a088f3c4521 "}
Basically the same as sending a friend message, Group_uin in JSON data is the GID previously acquired, the other is no different from sending friend messages.
3. Sending a temporary session message
The temporary session here only refers to the sending of sessions to members of the group that are already in the group. After all, send a message to get the identity of the object, this logo is not QQ account, but UIn, if you only know a person's QQ number, but and he is not a friend, and not in the same group, then is unable to obtain his relative to your uin, that is, send the message is not established.
Back to the point, as stated above, we are going to get the uin of the group members relative to themselves through the group. First of all, we need to get the information of all the members in the group, and we need to use the code mentioned earlier. The POST request is as follows:
Request url:http://s.web2.qq.com/api/get_group_info_ext2?gcode=1244601995&vfwebqq= 670f701a39ab1b21c05007564cf8936d6000b1f5a34093689aaa7ff67e8a3ede932d3ecb1b98f27c&t=1433068633058request Method:getreferer:http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1
Here is very simple, just a get method to get all the members of a group of information, Gcode that is said before the CODE,VFWEBQQ, T is time stamp, directly with System.currenttimemillis () to get it good.
The JSON data returned is as follows:
{"Retcode": 0, "result": {"stats": [{"Client_type": $, "UIn": 2368295990, "stat": Ten}], "Minfo": [{"Nick": "Scumvirus" , "Province": "Hubei", "gender": "Male", "UIn": 2741681712, "Country": "China", "City": "Wuhan"},{"Nick": "Scumvirus", "Province": " Hubei "," gender ":" Male "," UIn ": 570904041," Country ":" China "," City ":" Wuhan "},{" Nick ":" No Game no Bot "," Province ":" Hubei "," gender " : "Female", "UIn": 2368295990, "Country": "China", "City": "Wuhan"},{"Nick": "Scumvirus", "Province": "Hubei", "gender": "Male", " UIn ": 2117029336," Country ":" China "," City ":" Wuhan "}]," Ginfo ": {" Face ": 0," Memo ":" yy108371257 "," class ": +," Fingermemo ":" " , "code": 1244601995, "Createtime": 1321090723, "flag": 17826817, "level": 0, "name": "Scumvirus", "gid": 1068943425, " Owner ": 2741681712," members ": [{" Muin ": 2741681712," Mflag ": 192},{" Muin ": 570904041," Mflag ": 0},{" Muin ": 2368295990," Mflag ": 0},{" Muin ": 2117029336," Mflag ": 0}]," option ": 2}," Vipinfo ": [{" Vip_level ": 0," U ": 2741681712," IS_VIP ": 0},{" Vip_level ": 0," U ": 570904041," IS_VIP ": 0},{" Vip_level ": 0," U ": 2368295990," IS_VIP ": 0},{" Vip_level ": 0," U ": 2117029336 , "IS_vip ": 0}]}}
This is only concerned about Minfo, which has both user nickname, residence, gender, as well as the UIn logo we want.
The next is to send a temporary message, but in this method than the previous 2 methods to take one more step, he will get group_sid this parameter to send a temporary session message, but this parameter is also very good to get, a GET request on the line. The request is as follows:
Request url:http://d.web2.qq.com/channel/get_c2cmsg_sig2?id=<span style= "font-family:arial, Helvetica, Sans-serif; " >1068943425</span>&to_uin=570904041&clientid=53999199&psessionid= 8368046764001d636f6e6e7365727665725f77656271714031302e3133392e372e313630000054bd00000bcd026e04003654298d6d0000000a404e364 b386b707858676d000000285f293205986c0c9381ea5471ac8bdfd996fb8ca4765bcebab0230c3b0fb85cf513378825ebe2ade8& Service_type=0&t=1433069146558request method:getreferer:http://d.web2.qq.com/proxy.html?v=20130916001& callback=1&id=2
ID is the group identifier Gid,to_uin that you want to send the object's UIn identity, service_type I do not know what is, the default fill 0 is not wrong, the other parameters have been mentioned not much said.
The JSON data returned is as follows:
{"Retcode": 0, "result": {"type": 0, "value": " B1A949941BC21EA0E56529D6C71B9065083E0AB74CA8EE8CEDB0135440FE17B54FB8A807E202A0E491F40CF403D5E22E "," flags ": {" Text ": 1," pic ": 1," File ": 1," audio ": 1," video ": 1}}}
Take only the value of which is the group_sig we want.
The following is the message sent, the request is as follows:
Request url:http://d.web2.qq.com/channel/send_sess_msg2request method:postreferer:http://d.web2.qq.com/ Proxy.html?v=20130916001&callback=1&id=2form-data:r={"to": 570904041, "Content": "[\" 123\ ", [\" font\ ", {\" Name\ ": \" song body \ ", \" size\ ": 10,\" style\ ": [0,0,0],\" color\ ": \" 000000\ "}]]", "Face": 564, "ClientID": 53999199, "msg_id" : 93440002, "Psessionid": " 8368046764001d636f6e6e7365727665725f77656271714031302e3133392e372e313630000054bd00000bcd026e04003654298d6d0000000a404e364 B386b707858676d00000028d173ff0fccee9875162f70075476dfb3712e59456440efca2a0db0fb063216d74084919fd7185f16 "," Group_sig ":" b1a949941bc21ea0e56529d6c71b9065083e0ab74ca8ee8cedb0135440fe17b54fb8a807e202a0e491f40cf403d5e22e ", "Service_type": 0}
To that is the target uin,group_sig that we have just acquired parameters, service_type default fill 0 bar, anyway, not wrong.
3 kinds of message send have the return value, only determine whether Recode is 0 to know whether the send is successful. The above is all that is described in this article.
Note: If the message content has a carriage return, it may fail to send. I do not know the carriage return character how to transcode, anyway, how hair is a failure, easy language forum someone in January 15 wrote a solution was adopted, but I follow the Java way to write or send failed, because I do not understand easy language, so maybe I understand wrong.
Say something else a little bit more.
At present I have seen 2 kinds of QQ robot, one is cool Q, it is a copy of the old QQ version of the interface to do, you can see the list of friends (this I also mentioned how to get a friend list, it just shows the list, the same), if you want to send a message to certain people or groups, then you can also make a Each item is preceded by a jcheckbox to allow the user to choose. The other one is the morning breeze QQ robot. But that's what I did, not a list, just a bunch of feature sets on it. However, the method has been, how the interface design depends on the needs of users.
1068943425
QQ Chat Robot Mass Tool (Java Edition) (ii)