Sina Weibo dms, instant chat interface Research

Source: Internet
Author: User

Because you want to write a chrome plugin for hair dms, you know,,,,


Because it is a plugin, do not study the simulation landing, the cookie problem do not consider, you can use Ajax arbitrary access to all the Weibo address


But if two people never communicate, then the first hair DMS is to have the verification code


But there is a situation does not need, that is, with Sina IM, is the bottom right corner of the instant chat that thing, the study found that if you need to call the interface of instant Chat, the following steps need to


Before the first step: Get the server, pipeline


Ajax,get send content to: http://nas.im.api.weibo.com/im/webim.jsp


v:1.1 Returntype:json uid:1824450144 Callback:callback returned two items, all saved

{"channel": "/im/51sr84_1824450144", "Server": "http://13.79.web1.im.weibo.com/"}




The first step: shaking hands handleshake

The server address +im is the root address, for example: (the server has been taken on the previous step)

Http://11.79.web1.im.weibo.com/im

Ajax,get send content to this address

Jsonp:callback message: [{"Version": "1.0", "minimumversion": "0.9", "channel": "/meta/handshake", " Supportedconnectiontypes ": {" 0 ":" callback-polling "}," id ": 1}] Because Sina is using script to simulate a get to request this interface across domains, so each return of the content, Automatically returns the content to the callback function that you set up, we can only eval in Ajax, for example:

Callback ([{"id": "1", "MinimumVersion": "1.0", "supportedconnectiontypes": ["WebSocket", "callback-polling", "long-polling"], "Successful": TRUE, "channel": "/meta/handshake", "ext": {"TimeSync": {"ts": 1377155460536, "TC": 1377155466453, "P": 0, " A ": 5917}," Ack ": true}," ClientId ":" 1n8zz1g60ncoj1hxuumbuutbw9f5ri "," Version ":" 1.0 "}]


As long as we define a callback function in advance, this step, we get an important parameter, that is ClientID, save.

PS: Look at the data returned above, but also support websocket, but do not know what the specific protocol is, can not call


Step Two: Connecting Connect

To send a message, you also need to connect

Ajax,get send the following to the root address


Jsonp:callback message: [{"channel": "/meta/connect", "ConnectionType": "Callback-polling", "id": 3, "clientId": " 1n8zz1g60ncoj1hxuumbuutbw9f5ri "}]
Pay attention to the use of callback above, the above data, pay attention to that ClientID, is the first step of the handshake to get

The return content after the connection is basically useless, as follows:

Callback ([{"id": "3", "successful": True, "advice": {"interval": 0, "Reconnect": "Retry", "Timeout": 180000}, "channel": " /meta/connect "}])

Tell you if it's successful, wait.


Step Three: Register subscribe

can also be translated into attendance, and so on, the beholder

Ajax,get Send the following data

Jsonp:callback message: [{"channel": "/meta/subscribe", "Subscription": " here is the Chanel to get started", "id": 4, " ClientId ":" The first step to take the ClientId"},{" Channel: "/im/req", "data": {"Online": "1", "Limit": "", "seq": "Min", "cmd ":" Roster "}," id ": 2," clientId ":" 1n8zz1g60ncoj1hxuumbuutbw9f5ri "}]

You can see the message is a number of groups, meaning that in fact, each time you can send more than one piece of information, the first is a registration information, then it should be a message that I came online, you can delete


Part fourth: You can send a message.

Jsonp:callback message: [{Channel]: "/im/req", "data": {"UID": "1905031563", "seq": "1905031563", "msg": "Satan Law", "cmd": " Msg "}," id ":" clientId ":" 1R2FN1QX5AA1EHO5OT122PGYLDMKMCI "}] uid change to the UID you want to send and SEQ, the message you know
OK, actually there are other interfaces, this is no longer elaborate

I wrote a microblog plugin https://github.com/suxianbaozi/autoreply



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.