美文网首页
微博私信协议

微博私信协议

作者: 后山小鲨鱼 | 来源:发表于2021-07-16 15:57 被阅读0次

用的是公开的协议
如有侵权,联系删除。
进入到某个用户的私信页面,发送私信。

可以发现,是个post请求
主要关注data里面的数据
text :要发送的内容
uid:要发送私信的用户id
clientid:一个加密的参数,服务端返回,或js生成
source:本人的id,但和用户主页的id不同,还不知道从哪里来。

刷新一下页面,重新捕获一下链接,看是否能找到clientid
在某个链接里面发现了他

这条链接是post请求

https://web.im.weibo.com/im/handshake
data:[{"id":"1","version":"1.0","minimumVersion":"1.0","channel":"/meta/handshake","supportedConnectionTypes":["long-polling","callback-polling"],"advice":{"timeout":60000,"interval":0}}]

data没有特殊的值,固定就好。

clientid的话,也可以在某个js文件中找到

https://conchfairy.sinajs.cn/chat/js/app.000f4c48.js
这样的话,参数就找齐了。
需要注意一点的是各个链接content-type的类型。

import requests
from urllib.parse import quote
import json
import re
import time

class wp():
    def __init__(self):
        self.cookie = '你的cookie'
        self.get_clientid()
        self.getsoureid()

    # 得到sourceid
    def getsoureid(self):
        url = 'https://conchfairy.sinajs.cn/chat/js/app.000f4c48.js'
        headers = {
            'Cookie':self.cookie,

        }
        rg = requests.get(url,headers = headers)
        rt = rg.text
        sourceid = re.findall(r'source=(\d+)"',rt)[-1]
        self.sourceid = sourceid

    # 得到clientid
    def get_clientid(self):
        url = 'https://web.im.weibo.com/im/handshake'
        headers = {
            'Content-Type': 'application/json;charset=UTF-8',
            'Cookie': self.cookie,
            'Referer': 'https://api.weibo.com/'
        }
        data = [{"id":"1","version":"1.0","minimumVersion":"1.0","channel":"/meta/handshake","supportedConnectionTypes":["long-polling","callback-polling"],"advice":{"timeout":60000,"interval":0}}]
        r = requests.post(url,headers = headers,data = json.dumps(data),verify = False)
        if r.status_code == 200:
            rj = r.json()
            print(rj)
            self.clientid = rj[0]['clientId']

    # 私信
    def sixin(self,uid,content):
        source = self.sourceid
        content = quote(content)
        url = 'https://api.weibo.com/webim/2/direct_messages/new.json'
        data = f'text={content}&uid={uid}&extensions=%7B%22clientid%22%3A%22{self.clientid}%22%7D&is_encoded=0&decodetime=1&source={source}'
        print(data)
        headers = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Cookie': self.cookie,
            'Referer': 'https://api.weibo.com/chat/'

        }
        rp = requests.post(url,headers = headers,data = data)
        print(rp.status_code)
        if rp.status_code == 200:
            print(rp.text)


仅用于自己的账号,请不要批量操作,非法操作。

相关文章

  • 微博私信协议

    用的是公开的协议如有侵权,联系删除。进入到某个用户的私信页面,发送私信。 可以发现,是个post请求主要关注dat...

  • 微博私信

    我从来不知道微博有陌生人私信这个功能。因为它是折叠的,大概是为了使用者不被打扰。 前不久在微博小号发现,2019年...

  • 摄影作品‖突如其来向你跑来

    约拍私信‖微信lsy13673966576 微博私信‖努力努力再努力的刘某 QQ私信‖2359380362

  • 提供阿卡西记录公益阅读

    免费 微博私信:@红鲤鱼与绿鲤鱼654

  • Gwen为你答

    每日抽取私信抽取高质量问题解答。 微博TeacherGwen直接私信即可。

  • 鑫哥网络随笔:(6)贴吧和微博引流的技巧

    微博这个平台,核心就是搜索,他的流量入口有微博热闹,微博实时,超级话题。 至于私信,截流,微信群发广告,这些都是...

  • 旧爱,很无奈

    01 多年没有联系的前任突然在微博里发私信给我。 对,你没看错,是微博私信。 所以,可想而知,我们当初都闹掰到什么...

  • 一次濒临被骗的经历

    中午正在画画,微博发送了一条远在英伦的同事私信,通常情况是不怎么会留意微博私信的,不知道今天着了...

  • 微博私信机器人实现

    今天打算设置个微博粉丝平台的机器人自动回复,之前曾为微信公众号弄了个机器人,由于微信公众号的第三方很多,比如微之家...

  • 一天十个188元买原创若大的自媒体界除了龚文祥以外没有人敢这么大

    为鼓励微博原创,欢迎大家微博私信投稿爆料电商相关的内容,或原创电商及微电商干货140字私信给我,一旦我截屏采用并a...

网友评论

      本文标题:微博私信协议

      本文链接:https://www.haomeiwen.com/subject/serbpltx.html