url = 'https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=716027609&daid=383&style=33&theme=2&login_text=%E6%8E%88%E6%9D%83%E5%B9%B6%E7%99%BB%E5%BD%95&hide_title_bar=1&hide_border=1&target=self&s_url=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&pt_3rd_aid=1101083114&pt_feedback_link=https%3A%2F%2Fsupport.qq.com%2Fproducts%2F77942%3FcustomInfo%3D.appid1101083114'
所需参数值:pt_login_sig
session = requests.session()
url = session.get('https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=716027609&daid=383&style=33&theme=2&login_text=%E6%8E%88%E6%9D%83%E5%B9%B6%E7%99%BB%E5%BD%95&hide_title_bar=1&hide_border=1&target=self&s_url=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&pt_3rd_aid=1101083114&pt_feedback_link=https%3A%2F%2Fsupport.qq.com%2Fproducts%2F77942%3FcustomInfo%3D.appid1101083114')
#输出url.cookies.get_dict() = {'pt_clientip': '6efd753d11226d2c', 'pt_guid_sig': '63d……', 'pt_local_token': '-103596158', 'pt_login_sig': 'nxb9p……', 'pt_serverip': 'c1c30991b9db63b3', 'uikey': '5d0……'}
#所需要要的参数是:pt_login_sig
pt_login_sig = url.cookies.get_dict()['pt_login_sig']
loginurl = 'https://ssl.ptlogin2.qq.com/ptqrshow?appid=716027609&e=2&l=M&s=3&d=72&v=4&t={}&daid=383&pt_3rd_aid=1101083114'.format(random.random())
class showpng(Thread):
def __init__(self, data):
Thread.__init__(self)
self.data = data
def run(self):
img = Image.open(BytesIO(self.data))
img.show()
loginurl = session.get('https://ssl.ptlogin2.qq.com/ptqrshow?appid=716027609&e=2&l=M&s=3&d=72&v=4&t={}&daid=383&pt_3rd_aid=1101083114'.format(random.random()),headers=headers)
t = showpng(loginurl.content)
t.start()
所需参数值:qrsig
qrsig = loginurl.cookies.get_dict()['qrsig']
tokenurl = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&ptqrtoken={}&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-{}&js_ver=21010623&js_type=1&login_sig={}&pt_uistyle=40&aid=716027609&daid=383&pt_3rd_aid=1101083114&'
ptqrtoken
action
login_sig
ptqrtoken = k["default"].str.hash33(k["default"].cookie.get("qrsig"))
"hash33": function(t) {
for (var e = 0, i = 0, n = t.length; i < n; ++i)
e += (e << 5) + t.charCodeAt(i);
return 2147483647 & e
}
破解步骤(方法1)
function hash33(t) {
for (var e = 0, i = 0, n = t.length; i < n; ++i)
e += (e << 5) + t.charCodeAt(i);
return 2147483647 & e
}
import execjs
# 读取js
def djs(js):
f = open(js, 'r', encoding='utf-8')
jst = ''
while True:
readline = f.readline()
if readline:
jst += readline
else:
break
return jst
#读取jsdm.js
def getjs():
return djs('jsdm.js')
# 获取ptqrtoken
def ptqrtoken(qrsign):
# 加载js
execjs_execjs = execjs.compile(getjs())
return execjs_execjs.call('hash33', qrsign)
#测试
qrsign = '8P*NydFzgI51G7T4LYWABFgp-z888KcgrC1XkiD3IcnfOrdrA-e8YeyXSGKjOw'
print(ptqrtoken(qrsign))
#输出ptqrtoken(qrsign) = 324610216
破解步骤(方法2)
ptqrtoken = execjs.compile('''function s(t){for(var e=0,i=0,n=t.length;i).call('s', qrsig)
qrsig = loginurl.cookies.get_dict()['qrsig']
#方法1
ptqrtoken = agent.ptqrtoken(qrsig)
#方法2
#ptqrtoken = execjs.compile('''function s(t){for(var e=0,i=0,n=t.length;i
print(ptqrtoken)
tokenurl = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&ptqrtoken={}&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-{}&js_ver=21010623&js_type=1&login_sig={}&pt_uistyle=40&aid=716027609&daid=383&pt_3rd_aid=1101083114&'
tokendate = session.get(tokenurl.format(ptqrtoken, int(time.time() * 1000), loginsig), headers=headers)
ptuiCB(‘66’,‘0’,’’,‘0’,‘二维码未失效。(871394992)’, ‘’)
ptuiCB(‘65’, ‘0’, ‘’, ‘0’, ‘二维码已失效。(130030768)’, ‘’)
ptuiCB(‘0’,‘0’,‘http…’,‘0’,‘登录成功!’, ‘李’)
date = 'https://graph.qq.com/oauth2.0/authorize'
date1 = 'https://h5.weishi.qq.com/weishi/account/login?r_url=http%3A%2F%2Fmedia.weishi.qq.com%2F&loginfrom=qc&code=07512228944E3F895DAAE2D7732E13DA&state=state'
ui
g_tk
code
var guid = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}).toUpperCase();
};
function hash33(t) {
for (var e = 0, i = 0, n = t.length; i < n; ++i)
e += (e << 5) + t.charCodeAt(i);
return 2147483647 & e
}
function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}).toUpperCase();
};
# 获取UI
def guid():
# 加载js
execjs_execjs = execjs.compile(getjs())
return execjs_execjs.call('guid')
getToken = function() {
var str = Q.getCookie('p_skey') || '',
hash = 5381;
for (var i = 0, len = str.length; i < len; ++i) {
hash += (hash << 5) + str.charCodeAt(i);
}
return hash & 0x7fffffff;
};
tokenurl = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&ptqrtoken={}&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-{}&js_ver=21010623&js_type=1&login_sig={}&pt_uistyle=40&aid=716027609&daid=383&pt_3rd_aid=1101083114&'
t = showpng(loginurl.content)
t.start()
while 1:
tokendate = session.get(tokenurl.format(ptqrtoken, int(time.time() * 1000), loginsig), headers=headers)
p = re.compile("ptuiCB\('(.*)','(.*)','(.*)','(.*)','(.*)',.*\)")
ret = p.search(tokendate.text).groups()
if ret[0] == "66":
print('二维码未失效,请扫码!')
elif ret[0] == "67":
print('已扫码,请确认!')
elif ret[0] == "65":
print('二维码已失效,请重新运行!')
if ret[0] == '0':
print('已确认,登录成功!')
#ret[2]是生成新网址
session.get(ret[2])
p_skey = session.cookies.get('p_skey')
print(p_skey)
function hash33(t) {
for (var e = 0, i = 0, n = t.length; i < n; ++i)
e += (e << 5) + t.charCodeAt(i);
return 2147483647 & e
}
function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}).toUpperCase();
};
function getToken(p_skey) {
var str = p_skey || '',
hash = 5381;
for (var i = 0, len = str.length; i < len; ++i) {
hash += (hash << 5) + str.charCodeAt(i);
}
return hash & 0x7fffffff;
}
# 获取g_tk
def get_g_tk(p_skey):
# 加载js
execjs_execjs = execjs.compile(getjs())
return execjs_execjs.call('getToken', p_skey)
while 1:
tokendate = session.get(tokenurl.format(ptqrtoken, int(time.time() * 1000), loginsig), headers=headers)
p = re.compile("ptuiCB\('(.*)','(.*)','(.*)','(.*)','(.*)',.*\)")
ret = p.search(tokendate.text).groups()
if ret[0] == "66":
print('二维码未失效,请扫码!')
elif ret[0] == "67":
print('已扫码,请确认!')
elif ret[0] == "65":
print('二维码已失效,请重新运行!')
if ret[0] == '0':
print('已确认,登录成功!')
ui = agent.guid()
#将ui放入session.cookies中
c = RequestsCookieJar()
c.set('ui', ui, path='/', domain='weishi.qq.com')
session.cookies.update(c)
session.get(ret[2])
p_skey = session.cookies.get('p_skey')
g_tk = agent.get_g_tk(p_skey)
print(g_tk)
payload = {
'response_type': 'code', 'client_id': '1101083114', 'redirect_uri': 'https://h5.weishi.qq.com/weishi/account/login?r_url=http%3A%2F%2Fmedia.weishi.qq.com%2F&loginfrom=qc', 'scope': '', 'state': 'state', 'switch': '', 'from_ptlogin': '1', 'src': '1', 'update_auth': '1', 'openapi': '80901010', 'g_tk': g_tk, 'auth_time': int(time.time() * 1000), 'ui': ui}
urlencode = parse.urlencode(payload)
date = session.post('https://graph.qq.com/oauth2.0/authorize', data=urlencode).url
pattern = re.compile(r'[A-Za-z0-9]{16,}')
code = pattern.findall(date)[0]
session.get('https://h5.weishi.qq.com/weishi/account/login?r_url=http%3A%2F%2Fmedia.weishi.qq.com%2F&loginfrom=qc&code={}&state=state'.format(code))
# -*- coding: utf-8 -*-
import pickle
from urllib import parse
import re
import random
import agent
from threading import Thread
import time
import requests
from io import BytesIO
from PIL import Image
import os
requests.packages.urllib3.disable_warnings()
headers = {
'User-Agent': agent.get_user_agents(), "Host": "ssl.ptlogin2.qq.com", 'Referer':'https://xui.ptlogin2.qq.com/'}
class showpng(Thread):
def __init__(self, data):
Thread.__init__(self)
self.data = data
def run(self):
img = Image.open(BytesIO(self.data))
img.show()
def islogin(session):
try:
session.cookies.load(ignore_discard=True)
except Exception:
pass
loginurl = session.post('https://media.weishi.qq.com/media-api/getPersonalInfo?data=%7B%22personId%22%3A%221570763357553271%22%7D').json()
if loginurl['code'] == 0:
print('Cookies值有效,无需扫码登录!')
return session, True
else:
print('Cookies值已经失效,请重新扫码登录!')
return session, False
def wslogin():
# 写入
session = requests.session()
if not os.path.exists('wscookies.cookie'):
with open('wscookies.cookie', 'wb') as f:
pickle.dump(session.cookies, f)
# 读取
session.cookies = pickle.load(open('wscookies.cookie', 'rb'))
session, status = islogin(session)
if not status:
loginsig = session.get(
'https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=716027609&daid=383&style=33&theme=2&login_text=%E6%8E%88%E6%9D%83%E5%B9%B6%E7%99%BB%E5%BD%95&hide_title_bar=1&hide_border=1&target=self&s_url=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&pt_3rd_aid=1101083114&pt_feedback_link=https%3A%2F%2Fsupport.qq.com%2Fproducts%2F77942%3FcustomInfo%3D.appid1101083114')
loginsig = loginsig.cookies.get_dict()['pt_login_sig']
loginurl = session.get(
'https://ssl.ptlogin2.qq.com/ptqrshow?appid=716027609&e=2&l=M&s=3&d=72&v=4&t={}&daid=383&pt_3rd_aid=1101083114'.format(
random.random()), headers=headers)
qrsig = loginurl.cookies.get_dict()['qrsig']
# 方法1
ptqrtoken = agent.ptqrtoken(qrsig)
# 方法2
# ptqrtoken = execjs.compile('''function s(t){for(var e=0,i=0,n=t.length;i
tokenurl = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&ptqrtoken={}&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-{}&js_ver=21010623&js_type=1&login_sig={}&pt_uistyle=40&aid=716027609&daid=383&pt_3rd_aid=1101083114&'
t = showpng(loginurl.content)
t.start()
while 1:
tokendate = session.get(tokenurl.format(ptqrtoken, int(time.time() * 1000), loginsig), headers=headers)
p = re.compile("ptuiCB\('(.*)','(.*)','(.*)','(.*)','(.*)',.*\)")
ret = p.search(tokendate.text).groups()
if ret[0] == "66":
print('二维码未失效,请扫码!')
elif ret[0] == "67":
print('已扫码,请确认!')
elif ret[0] == "65":
print('二维码已失效,请重新运行!')
if ret[0] == '0':
print('已确认,登录成功!')
ui = agent.guid()
session.get(ret[2])
p_skey = session.cookies.get('p_skey')
g_tk = agent.get_g_tk(p_skey)
payload = {
'response_type': 'code', 'client_id': '1101083114',
'redirect_uri': 'https://h5.weishi.qq.com/weishi/account/login?r_url=http%3A%2F%2Fmedia.weishi.qq.com%2F&loginfrom=qc',
'scope': '', 'state': 'state', 'switch': '', 'from_ptlogin': '1', 'src': '1',
'update_auth': '1', 'openapi': '80901010', 'g_tk': g_tk,
'auth_time': int(time.time() * 1000), 'ui': ui}
urlencode = parse.urlencode(payload)
date = session.post('https://graph.qq.com/oauth2.0/authorize', data=urlencode).url
pattern = re.compile(r'[A-Za-z0-9]{16,}')
code = pattern.findall(date)[0]
session.get(
'https://h5.weishi.qq.com/weishi/account/login?r_url=http%3A%2F%2Fmedia.weishi.qq.com%2F&loginfrom=qc&code={}&state=state'.format(
code))
break
time.sleep(3)
with open('wscookies.cookie', 'wb') as f:
pickle.dump(session.cookies, f)
return session
if __name__ == '__main__':
wslogin()
- 后期小编将开设登录后批量采集各平台数据(点赞、播放量、评论、图片、视频、音乐等)专栏文章!记得关注哟!
- 如果文章能帮到您,愿意给小编点个 赞 吗,么么哒~ (●’◡’●)