首页 > 其他分享 >QQ空间协议从登录到实现各种功能完整代码(专栏完结)

QQ空间协议从登录到实现各种功能完整代码(专栏完结)

时间:2024-10-30 22:45:41浏览次数:3  
标签:QQ qq cookies https 专栏 完结 qzone com response

QQ协议扫码登录、账号密码登录、说说、评论、点赞、访客、留言实现及代码——专栏完结

本文章为包和实现代码汇总,每个功能的具体实现和分析过程请看本专栏对应的文章,不管扣代码还是分析都是超详细的教程

本文为本专栏的完结汇总文章

一、扫码登录 

扫码登录流程:发送获取二维码包,然后在响应的Cookie中拿到qrsig,GET请求一次qq空间主页拿到login_sig,通过qrsig利用算法得到ptqrtoken循环请求二维码状态包,扫码成功后会响应一个check的链接,带上Cookie访问一次即可

ptqrtoken算法代码以及详细分析请看以下文章

QQ空间扫码登录协议实现

 1.1获取二维码包

1.2login_sig 获取

GET https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https://qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&=&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https://qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=手机QQ空间&pt_qr_link=https://z.qzone.com/download.html&self_regurl=https://qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=https://z.qzone.com/download.html&pt_no_auth=0 

1.3登录状态包

GET  https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https://qzs.qq.com/qzone/v5/loginsucc.html?para=izone&ptqrtoken=1251677953&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-6-1726759691918&js_ver=24090913&js_type=1&login_sig=gRa0dbFM2zvBBtBq7SsT-5zMNE8-*kvEBcmL2j206E3ifj9cEsSt0RauGnlIcaHX&pt_uistyle=40&aid=549000912&daid=5&=&o1vId=2b82096ccefcae244d20335bbe82233c&pt_js_version=e8983a1a

1.4实现代码

def hash33(t):  #参数:qrsig
    e = 0
    for n in range(len(t)):
        e = (e << 5) + ord(t[n])  
    return e & 2147483647  # 返回ptqrtoken

def get_qr_image_with_cookies(cookies, headers): #保存二维码
    global global_cookies
    # 设置二维码请求的 URL
    qr_url = "https://ssl.ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=3&d=72&v=4&t=0.39175954831717164&daid=5&pt_3rd_aid=0&u1=https://qzs.qzone.qq.com/qzone/v5/loginsucc.html?para=izone"
 
    # 为二维码请求设置新的请求头
    headers.update({
        "Host": "ssl.ptlogin2.qq.com",
        "Accept": "image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5",
        "Referer": "https://xui.ptlogin2.qq.com/",
        "Sec-Fetch-Dest": "image",
        "Sec-Fetch-Mode": "no-cors",
        "Sec-Fetch-Site": "same-site",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache"
    })
 
    # 发送带有请求头和 Cookie 的请求以获取二维码
    response = requests.get(qr_url, headers=headers, cookies=cookies)
 
    # 检查请求是否成功
    if response.status_code == 200:
        # 保存二维码图片到本地
        with open("qrcode_with_new_cookie.png", "wb") as f:
            f.write(response.content)
        print("二维码已成功保存为 'qrcode_with_new_cookie.png'")
 
        # 打印新获取的 Cookie
        '''print("新获取的 Cookie:")
        for cookie in response.cookies:
            print(f"{cookie.name}: {cookie.value}")'''
 
        # 将新获取的 Cookie 合并到全局的 Cookie 中
        global_cookies.update(response.cookies)
    else:
        print(f"二维码请求失败,状态码:{response.status_code}")

def get_initial_cookies():
    global global_cookies
    # 发送 GET 请求到指定的 URL 来获取初始 Cookie
    url = "https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https://qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&=&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https://qzs.qqzone.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=手机QQ空间&pt_qr_link=http://z.qzone.com/download.html&self_regurl=https://qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http://z.qzone.com/download.html&pt_no_auth=1"
 
    headers = {
        "Host": "xui.ptlogin2.qq.com",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Connection": "keep-alive",
        "Upgrade-Insecure-Requests": "1",
        "Cache-Control": "max-age=0"
    }
 
    # 发起 GET 请求
    response = requests.get(url, headers=headers)
 
    # 检查请求是否成功
    if response.status_code == 200:
        # 合并获取的 Cookie 到全局变量中
        global_cookies.update(response.cookies)
        return global_cookies, headers
    else:
        print(f"请求失败,状态码:{response.status_code}")
        return None, None

二、账号密码登录 

 账号密码登录第一步和第二步和二维码登录一样,都是获取二维码包和二维码状态包,所以这里只总结后面的包,输入账号密码后会发送一个验证码包,计算好加密参数后再通过登录包即可实现账号密码登录,账号密码登录最难的是p参数的加密算法

p参数以及超级详细登录过程分析请看文章

QQ空间登录协议逆向分析|账号密码登录

 2.1验证码包

GET请求  https://ssl.ptlogin2.qq.com/check?regmaster=&pt_tea=2&pt_vcode=1&uin=3592795816&appid=549000912&js_ver=24090913&js_type=1&login_sig=nJL8y1akA3VvL6a*Ow5YWDHTGeDc-bGa6kOKPOXxcAvnoyf11FRaQMmh6iuwImpQ&u1=https://qzs.qq.com/qzone/v5/loginsucc.html?para=izone&r=0.8028792184028488&pt_uistyle=40&daid=5&pt_3rd_aid=0&o1vId=2b82096ccefcae244d20335bbe82233c&pt_js_version=e8983a1a

2.2登录包

GET  https://ssl.ptlogin2.qq.com/login?u=3592795816&verifycode=!AHD&pt_vcode_v1=0&pt_verifysession_v1=d209e30814a3ed57d25582d156452fb6cc8b09549b7119366d6fdf1e7f51d80452e7e96375acf888f6ed439f61d2919dc848a8cbef2491ea&p=nzhWRFgmertBtuWg8UdNPAEP*1SvzBQUF*15oxH9lpmS3ezrwMD*fsXMsA5Z7*gtMrjc4YlvdAfQBsuS21ZhWDQBG6EVGEDmh0rl3D58Q8jQsw7aLZGfBSuvXYZUk*uynaf6Y8NRuCE1O1zRrIIDbmpaerkg*KrSKrJruJHaxfkYnsCnPJ5eiihFoNne0Wk6uHyv-fuDgY8KmbXBttHY8VE2CfRixzP0wxi*bs39aoQ8XR7CyzY9ILl6FXohv9MqOjM-dkQoySEQngZEp0shnjt1Or2*6KDRAaGCvwJiEFJJ10J82*jziPhEwlzPxOmVV0wmAcw48YKUL*PfFD-QGQ__&pt_randsalt=2&pt_ev_token=pg*GymwZf8Usl2nma7yn5-K*wGC2F7U7u3ghMabxYADisu74gpNpDiqQYXduQ3dh&u1=https://qzs.qq.com/qzone/v5/loginsucc.html?para=izone&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=2-9-1726675195974&js_ver=24090913&js_type=1&login_sig=nJL8y1akA3VvL6a*Ow5YWDHTGeDc-bGa6kOKPOXxcAvnoyf11FRaQMmh6iuwImpQ&pt_uistyle=40&aid=549000912&daid=5&ptdrvs=sj0KT*DVpTNcsfhRgPc2-yt2uXbB7fNBf81xpmiOLfX5YnV5hfuF8lZzETgNZ-B6blq8KxmJ1rs_&sid=7073017071800088268&=&o1vId=2b82096ccefcae244d20335bbe82233c&pt_js_version=e8983a1a

2.3 代码

def login_finish(cookies, headers,url,state,name): #最终登录
    global global_cookies
    print('-----------------登录-----------------')
    print(state, name)
    qr_url = url
    print(qr_url)
    # 设置新的请求头
    headers.update({
        "Host": "ptlogin2.qzone.qq.com",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8",
        "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Sec-GPC": "1",
        "Connection": "keep-alive",
        "Sec-Fetch-Dest": "document",
        "Sec-Fetch-Mode": "navigate",
        "Sec-Fetch-Site": "none",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache",
        "Priority": "u=0,i",
        "Upgrade-Insecure-Requests": "1"
    })
    response = requests.get(qr_url, headers=headers, cookies=cookies, allow_redirects=False)
    print(response.content)
    # 检查请求是否成功
    if response.status_code == 302:
        # 打印新获取的 Cookie
        content = response.content.decode('utf-8')
        print(content)
        global_cookies.update(response.cookies)
        print("登录成功--------->最终 Cookie:")
        for cookie in global_cookies:
            print(f"{cookie.name}: {cookie.value}")
    else:
        print(f"请求失败,状态码:{response.status_code}")
    print(state, name, "成功登录")

def get_initial_cookies(): #数据包1
    global global_cookies
    # 发送 GET 请求到指定的 URL 来获取初始 Cookie
    url = "https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https://qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&=&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https://qzs.qqzone.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=手机QQ空间&pt_qr_link=http://z.qzone.com/download.html&self_regurl=https://qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http://z.qzone.com/download.html&pt_no_auth=1"
 
    headers = {
        "Host": "xui.ptlogin2.qq.com",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Connection": "keep-alive",
        "Upgrade-Insecure-Requests": "1",
        "Cache-Control": "max-age=0"
    }
 
    # 发起 GET 请求
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        # 合并获取的 Cookie 
        global_cookies.update(response.cookies)
        return global_cookies, headers
    else:
        print(f"请求失败,状态码:{response.status_code}")
        return None, None


def get_qr_image_with_cookies(cookies, headers): #数据包2
    global global_cookies
    # 设置二维码请求的 URL
    qr_url = "https://ssl.ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=3&d=72&v=4&t=0.39175954831717164&daid=5&pt_3rd_aid=0&u1=https://qzs.qzone.qq.com/qzone/v5/loginsucc.html?para=izone"
 
    # 为二维码请求设置新的请求头
    headers.update({
        "Host": "ssl.ptlogin2.qq.com",
        "Accept": "image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5",
        "Referer": "https://xui.ptlogin2.qq.com/",
        "Sec-Fetch-Dest": "image",
        "Sec-Fetch-Mode": "no-cors",
        "Sec-Fetch-Site": "same-site",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache"
    })
 
    response = requests.get(qr_url, headers=headers, cookies=cookies)
    # 检查请求是否成功
    if response.status_code == 200:
        # 保存二维码图片到本地
        with open("qrcode_with_new_cookie.png", "wb") as f:
            f.write(response.content)
        print("二维码已成功保存为 'qrcode_with_new_cookie.png'")
 
        # 将新获取的 Cookie
        global_cookies.update(response.cookies)
    else:
        print(f"二维码请求失败,状态码:{response.status_code}")

def get_vercode(cookies, headers,qquin,loginsig): #数据包3
    global global_cookies
    global global_code
    global global_sid
    qr_url = "https://ssl.ptlogin2.qq.com/check?regmaster=&pt_tea=2&pt_vcode=1&uin="+qquin+"&appid=549000912&js_ver=24090913&js_type=1&login_sig="+loginsig+"&u1=https://qzs.qzone.qq.com/qzone/v5/loginsucc.html?para=izone&r=0.48032086977232935&pt_uistyle=40&daid=5&pt_3rd_aid=0&o1vId=989ddff17a71e99927948b1101c6592d&pt_js_version=e8983a1a"
    #设置新的请求头
    headers.update({
        "Host": "ssl.ptlogin2.qq.com",
        "Accept": "image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5",
        "Referer": "https://xui.ptlogin2.qq.com/",
        "Sec-Fetch-Dest": "image",
        "Sec-Fetch-Mode": "no-cors",
        "Sec-Fetch-Site": "same-site",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache"
    })
 
    response = requests.get(qr_url, headers=headers, cookies=cookies)
    # 检查请求是否成功
    if response.status_code == 200:
        # 打印新获取的 Cookie
        content = response.content.decode('utf-8', errors='ignore')
        global_code=content.split(',')[1][1:-1] #验证码
        global_sid=content.split(',')[6][1:-2]  #sid
        global_cookies.update(response.cookies)
    else:
        print(f"请求失败,状态码:{response.status_code}")


def login(cookies, headers,verifycode,v1,p,login_sig,ptdrvs,sid): #数据包4
    p=p.replace("\n",'')
    global global_cookies
    print('-----------------开始登录-----------------')
    qr_url = "https://ssl.ptlogin2.qq.com/login?u="+global_cookies['ptui_loginuin']+"&verifycode="+verifycode+"&pt_vcode_v1=0&pt_verifysession_v1="+v1+"&p="+p+"&pt_randsalt=2&u1=https://qzs.qzone.qq.com/qzone/v5/loginsucc.html?para=izone&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=2-9-1726375321935&js_ver=24090913&js_type=1&login_sig="+login_sig+"&pt_uistyle=40&aid=549000912&daid=5&ptdrvs="+ptdrvs+"&sid="+sid+"&=&o1vId=989ddff17a71e99927948b1101c6592d&pt_js_version=e8983a1a"
    print('loginurl',qr_url)
    #设置新的请求头
    headers.update({
        "Host":"ssl.ptlogin2.qq.com",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0",
        "Accept": "*/*",
        "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Sec-GPC": "1",
        "Connection": "keep-alive",
        "Referer": "https://xui.ptlogin2.qq.com/",
        "Sec-Fetch-Dest": "script",
        "Sec-Fetch-Mode": "no-cors",
        "Sec-Fetch-Site": "same-site",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache",
    })
    response = requests.get(qr_url, headers=headers, cookies=cookies)
    # 检查请求是否成功
    if response.status_code == 200:
        # 打印新获取的 Cookie
        content = response.content.decode('utf-8', errors='ignore')
        print(content)
        ckurl = content.split(',')[2][1:-1]
        state = content.split(',')[4][1:-2]
        name=content.split(',')[5][1:-2]
        print(ckurl,state)
        # 将获取到最终Cookie
        global_cookies.update(response.cookies)
        login_finish(global_cookies,headers,ckurl,state,name)
    else:
        print(f"请求失败,状态码:{response.status_code}")

三、 点赞

点赞只要获取成功登录的Cookie之后,利用g_tk参数便可以实现

详细g_tk参数算法以及逆向过程分析请看以下文章

QQ空间点赞协议实现

点赞包  POST

https://user.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?g_tk=456731308

表单数据

qzreferrer=https%3A%2F%2Fuser.qzone.qq.com%2F2793603016&opuin=2793603016&unikey=http%3A%2F%2Fuser.qzone.qq.com%2F20050606%2Fmood%2Faef23101f9b9db6644310800&curkey=http%3A%2F%2Fuser.qzone.qq.com%2F20050606%2Fmood%2Faef23101f9b9db6644310800&from=1&appid=311&typeid=0&abstime=1725676025&fid=aef23101f9b9db6644310800&active=0&fupdate=1 

实现代码

def do_like(uin, tk, finFidKey, finabsTime, ii, cookies):
    try:
        url = f"https://h5.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?g_tk={tk}"
        headers = {
            "Host": "h5.qzone.qq.com",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0",
            "Accept": "textml,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
            "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
            "Accept-Encoding": "gzip, deflate, br",
            "Connection": "keep-alive",
            "Cache-Control": "no-cache",
            "Origin": "https://user.qzone.qq.com",
            "Content-Type": "application/x-www-form-urlencoded",
            "Sec-Fetch-Dest": "iframe",
            "Sec-Fetch-Mode": "navigate",
            "Upgrade-Insecure-Requests": "1",
            "Sec-Fetch-Site": "same-origin"
        }
        mes_params = {
            "qzreferrer": "https://user.qzone.qq.com/proxy/domain/ic2.qzone.qq.com/cgi-bin/feeds/feeds_html_module",
            "opuin": uin,
            "unikey": f"http://user.qzone.qq.com/477154712/mood/{finFidKey[ii]}",
            "curkey": f"http://user.qzone.qq.com/477154712/mood/{finFidKey[ii]}",
            "from": "1",
            "appid": "311",
            "typeid": "0",
            "abstime": finabsTime[ii],
            "fid": finFidKey[ii],
            "active": "0",
            "fupdate": "1"
        }
        mes = urllib.parse.urlencode(mes_params)
        response = requests.post(url, headers=headers, data=mes, cookies=cookies)
        t = int(finabsTime[ii])
        date = datetime.fromtimestamp(t)
        time_string = date.strftime("%Y-%m-%d-%H:%M:%S")
        print(f"说说发布时间: {time_string}")
        # 解析响应内容
        if "succ" in response.text:
            print(f"说说key: {finFidKey[ii]} 点赞成功")
        else:
            print(f"说说key: {finFidKey[ii]} 点赞失败")
    except Exception as e:
        print(f"Error: {e}")

四、 评论

具体分析请看以下文章

QQ空间协议发评论

POST请求 

https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_re_feeds?=&g_tk=1954447331

原始表单数据topicId=3592795816_a8b625d6ca6ded6650e70800__1&feedsType=100&inCharset=utf-8&outCharset=utf-8&plat=qzone&source=ic&hostUin=3592795816&isSignIn=&platformid=50&uin=3592795816&format=fs&ref=feeds&content=hahaha%0A&richval=&richtype=&private=0¶mstr=1&qzreferrer=https%3A%2F%2Fuser.qzone.qq.com%2F3592795816

实现代码

def post_feeds(cookie, g_tk, msg, hostuin, topic_id, uin):
    try:
        url = f"https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_re_feeds?=&g_tk={g_tk}"
        # 请求头信息
        headers = {
            "Host": "user.qzone.qq.com",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
            "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
            "Accept-Encoding": "gzip, deflate, br",
            "Connection": "keep-alive",
            "Cache-Control": "no-cache",
            "Origin": "https://user.qzone.qq.com",
            "Content-Type": "application/x-www-form-urlencoded",
            "Sec-Fetch-Dest": "iframe",
            "Sec-Fetch-Mode": "navigate",
            "Upgrade-Insecure-Requests": "1",
            "Sec-Fetch-Site": "same-origin",
            "Cookie": cookie
        }
        # 表单数据
        data = {
            "topicId": topic_id,
            "feedsType": "100",
            "inCharset": "utf-8",
            "outCharset": "utf-8",
            "plat": "qzone",
            "source": "ic",
            "hostUin": hostuin,
            "isSignIn": "",
            "platformid": "50",
            "uin": uin,
            "format": "fs",
            "ref": "feeds",
            "content": msg,  # 消息内容
            "richval": "",
            "richtype": "",
            "private": "0",
            "paramstr": "1",
            "qzreferrer": f"https://user.qzone.qq.com/{uin}"
        }
        encoded_data = urllib.parse.urlencode(data)
        response = requests.post(url, headers=headers, data=encoded_data)
 
   
        if response.status_code == 200:
            print("请求成功,响应内容:")
            print(response.text)
        else:
            print(f"请求失败,状态码:{response.status_code}")
 
    except Exception as e:
        print(f"发生错误: {e}")

五、 访客

QQ空间协议访客,q_sig签名加密算法的获取以及分析,可以用来实现QQ空间访客

q_sig算法在很早之前是可以用qr_sig替代的,并且最新的q_sig算法逆向起来较为复杂

q_sig签名以及扣代码等具体分析请看以下文章

QQ空间协议访客签名q_sig参数分析

 get请求  https://user.qzone.qq.com/proxy/domain/g.qzone.qq.com/fcg-bin/cgi_emotion_list.fcg?uin=&loginUin=3592795816&rd=0.17621838767080367&num=3&noflower=1&q_sig=42011e13bcc2665566314c457974f7b10f67c4d90dcb02afaeb9&ver=1.0.3&g_tk=896053551

调用扣下来的js代码

doVisit=function(){
		seajs.use("aaaaaaa.js", function(QSEC){
				var params = {
					uin:12345,//访问的QQ空间
					loginUin:1234586,//登录的QQ
					rd:Math.random(),
					num:3,
					noflower:1
				}
				var content = QSEC.q_sign(new URLSearchParams(params).toString());
				params.q_sig = content;
				console.log(content)
			});
		}
doVisit()

六、发送|删除说说 

QQ空间协议发送|删除说说

具体分析请看以下文章

QQ空间协议发送|删除说说

发送说说

POST请求的数据包

https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_publish_v6?&g_tk=492549294

请求表单数据:syn_tweet_verson=1¶mstr=1&pic_template=&richtype=&richval=&special_url=&subrichtype=&who=1&con=helloworld&feedversion=1&ver=1&ugc_right=1&to_sign=0&hostuin=3592795816&code_version=1&format=fs&qzreferrer=https%3A%2F%2Fuser.qzone.qq.com%2F3592795816
6

删除说说 

POST请求  https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?=&g_tk=912755888

原始表单数据hostuin=3592795816&tid=a8b625d6e16ded6685200b00&t1_source=1&code_version=1&format=fs&qzreferrer=https%3A%2F%2Fuser.qzone.qq.com%2F3592795816%2F311

tid获取

GET请求    https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin=3592795816&ftype=0&sort=0&pos=0&num=20&replynum=100&g_tk=912755888&callback=_preloadCallback&code_version=1&format=jsonp&need_private_comment=1

实现代码

def send_message(msg, uin, tk, cookie):   # 发说说
    try:
        base_url = "https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_publish_v6"
        url = f"{base_url}?g_tk={tk}"
        headers = {
            "Host": "user.qzone.qq.com",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
            "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
            "Accept-Encoding": "gzip, deflate, br",
            "Connection": "keep-alive",
            "Cache-Control": "no-cache",
            "Origin": "https://user.qzone.qq.com",
            "Content-Type": "application/x-www-form-urlencoded",
            "Sec-Fetch-Dest": "iframe",
            "Sec-Fetch-Mode": "navigate",
            "Upgrade-Insecure-Requests": "1",
            "Sec-Fetch-Site": "same-origin",
            "Cookie": cookie
        }
        params = {
            "qzreferrer": f"https://user.qzone.qq.com/{uin}",
            "syn_tweet_verson": "1",
            "paramstr": "1",
            "pic_template": "",
            "richtype": "",
            "richval": "",
            "special_url": "",
            "subrichtype": "",
            "who": "1",
            "con": f"123{msg}",
            "feedversion": "1",
            "ver": "1",
            "ugc_right": "1",
            "to_sign": "0",
            "hostuin": uin,
            "code_version": "1",
            "format": "fs"
        }
        encoded_data = urllib.parse.urlencode(params)
        # 发送 POST 请求
        response = requests.post(url, headers=headers, data=encoded_data)
        print(response.content)
 
    except Exception as e:
        print(f"Error: {e}")

def get_qzone_data(cookie, uin, g_tk): #获取tid
    url = f"https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin={uin}&ftype=0&sort=0&pos=0&num=20&replynum=100&g_tk={g_tk}&callback=_preloadCallback&code_version=1&format=jsonp&need_private_comment=1"
    # 请求头
    headers = {
        "Host": "user.qzone.qq.com",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0",
        "Accept": "*/*",
        "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Connection": "keep-alive",
        "Referer": f"https://user.qzone.qq.com/{uin}/311",
        "Sec-Fetch-Dest": "script",
        "Sec-Fetch-Mode": "no-cors",
        "Sec-Fetch-Site": "same-origin",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache",
        "TE": "trailers",
        "Cookie": cookie
    }
 
    try:
        response = requests.get(url, headers=headers)
        
        if response.status_code == 200:
            return response.text
        else:
            return f"请求失败,状态码: {response.status_code}"
    except Exception as e:
        return f"发生错误: {str(e)}"


def post_delete_art(cookie, g_tk, hostuin, tid):  #删除
    url = f"https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?=&g_tk={g_tk}"
    data = {
        "hostuin": hostuin,
        "tid": tid,
        "t1_source": "1",
        "code_version": "1",
        "format": "fs",
        "qzreferrer": f"https://user.qzone.qq.com/{hostuin}/311"
    }
    headers = {
        "Host": "user.qzone.qq.com",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0",
        "Accept": "*/*",
        "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Content-Type": "application/x-www-form-urlencoded",
        "Connection": "keep-alive",
        "Referer": f"https://user.qzone.qq.com/{hostuin}/311",
        "Sec-Fetch-Dest": "document",
        "Sec-Fetch-Mode": "no-cors",
        "Sec-Fetch-Site": "same-origin",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache",
        "Cookie": cookie
    }
    
    try:
        # 发送 POST 请求
        response = requests.post(url, headers=headers, data=data)
        if response.status_code == 200:
            return response.text
        else:
            return f"请求失败,状态码: {response.status_code}"
    except Exception as e:
        return f"发生错误: {str(e)}"

账号密码登录第一步和第二步和二维码登录一样,都是获取二维码包和二维码状态包

标签:QQ,qq,cookies,https,专栏,完结,qzone,com,response
From: https://blog.csdn.net/qq_37454479/article/details/143205328

相关文章

  • 在同一子网下,利用wireshark进行的QQ数据分析
    在同一子网下,利用wireshark进行的QQ数据分析该实验目的是使用wireshark对新版QQ进行抓包,对QQ的数据流进行分析,对指定文件进行复现。和老版本的QQ相比,新版本的QQ传输的安全性更高,因为它采用了更多的TCP加密协议。这也直接导致新版QQ的验证程序更加繁琐,传输速度有所下降。所以,在wi......
  • 全面解释人工智能LLM模型的真实工作原理(完结)
    前一篇:《全面解释人工智能LLM模型的真实工作原理(三)》序言:本节作为整篇的收官之作,自然少不了与当今最先进的AI模型相呼应。这里我们将简单介绍全球首家推动人工智能生成人类语言的公司——OpenAI的GPT模型的基本原理。如果你也希望为人类的发展做出贡献,并投身于AI行业,这无疑是一......
  • PbootCMS如何实现留言内容自动发送到QQ邮箱
    准备两个QQ邮箱:发件邮箱:用于发送邮件,需要开通【POP3/SMTP服务】和【IMAP/SMTP服务】。收件邮箱:用于接收邮件。开通邮箱服务:登录QQ邮箱,进入“设置”->“账户”。开启【POP3/SMTP服务】和【IMAP/SMTP服务】。记录生成的授权码,用于后续配置。配置PBootCMS:进......
  • qq打卡功能实现--卡片切换反转效果
    今天实现了一个类似qq的打卡反转效果,效果图如下(卡片样式比较简陋大家可以自己美化一下),快来看看怎么实现的吧先写两个layout显示卡片部分分别写打卡前的卡片样式(包括按钮)和打卡后显示的卡片,代码如下打卡前(cardbefore.xml)<?xmlversion="1.0"encoding="utf-8"?><LinearLay......
  • python从QQ邮箱中读取最新邮件,并以纯文本的方式在控制台显示
    importimaplibimportemailfromemail.policyimportdefaultfromhtml2textimporthtml2textIMAP_SERVER='imap.qq.com'#例如:'imap.gmail.com'IMAP_PORT=993#默认IMAP端口为993EMAIL_ADDRESS='[email protected]'#你的邮箱地址......
  • 电脑无法上网,但是微信、QQ可以正常使用​
    这种情况一般是由于DNS服务器配置错误,或者已有的DNS服务器无法正常解析地址造成的。按下win+R打开运行,输入,点击确定。在打开的网络连接窗口中找到对应的网卡,双击打开。一般有线网是“以太网”,无线网(WiFi)是“WLAN”。点击属性。双击“Internet协议版本4(TCP/IPv4)”,或者也可以选中以后......
  • Kafka学习笔记(已完结)
    Kafka消息中间件官网:https://kafka.apache.org/docker安装kafka教程:https://bugstack.cn/md/road-map/kafka.htmlKafka的几个概念生产者Producer消费者Consumer主题Topic分区Partition一个topic下可以有多个分区。当创建topic时,如果补置顶该topic的partition数量,那么默认......
  • 【基于PSINS工具箱的程序设计】专栏目录,持续更新……
    文章目录重要的文章后续更新方向专栏介绍在进行上层设计时,借助工具箱完成底层的复杂计算是很有必要的。也能利用工具箱学习惯导解算。本专栏分享若干自己基于PSINS编写的滤波、导航程序。如果没有工具箱,自己网上面下载或私信我,我给你啊-......
  • 新语专栏特辑-技术篇(第一季)
    今天是1024程序员节,我们精选一批优质的技术专栏分享给大家。今天这篇是技术篇第一季,如您觉得专栏对自己有用,欢迎订阅。1、JavaScript核心进阶作者介绍:「这波能反杀」,大前端架构师,个人职业成长私人高级顾问,著有《JavaScript核心技术开发解密》。专栏简介:旨在带给读者地道的......
  • 【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (八):API说明(暂时完结,后续考虑将
    本项目旨在学习如何快速使用nodejs开发后端api,并为以后开展其他项目的开启提供简易的后端模版。(非后端工程师)由于文档是代码写完之后,为了记录项目中需要注意的技术点,因此文档的叙述方式并非开发顺序(并非循序渐进的教学文档)。建议配合项目源码node-mongodb-template。【NodeJS......