diff --git a/main.py b/main.py index 8327f01..86215db 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,7 @@ import util.RequestUtil as Request +# import util.ConfigUtil as Config +import os - -# 按间距中的绿色按钮以运行脚本。 if __name__ == '__main__': message = Request.get_message(0, 10) print(message.text) - -# 访问 https://www.jetbrains.com/help/pycharm/ 获取 PyCharm 帮助 diff --git a/test/test.py b/test/test.py deleted file mode 100644 index d524df2..0000000 --- a/test/test.py +++ /dev/null @@ -1,81 +0,0 @@ -import re -import requests -import json - - -def qzone_login(): - cookies = { - 'ptui_loginuin': '1941163264', - 'RK': 'nzPEtRXmWI', - 'ptcz': '4b478c47ddfaf994cad9c3eeb6099336c6302fdde27eb31949fd0d8502e7aed6', - 'pgv_pvid': '249131564', - 'qz_screen': '1707x960', - 'QZ_FE_WEBP_SUPPORT': '1', - 'cpu_performance_v8': '1', - '_qpsvr_localtk': '0.0676035804419064', - 'pgv_info': 'ssid=s3673858535', - 'uin': 'o1941163264', - 'p_uin': 'o1941163264', - 'pt4_token': 'QUuDx3v5A1fbS9y1V-bgUZvp4AXSGeEt2897lTJUpgc_', - 'p_skey': '-RBLfzmoS*kIv9TQZMXaVjOEPuHcxMPsAQdhB6uSOdg_', - 'Loading': 'Yes', - '1941163264_todaycount': '0', - '1941163264_totalcount': '20087', - '__Q_w_s__QZN_TodoMsgCnt': '1', - '__layoutStat': '12', - } - - headers = { - 'authority': 'user.qzone.qq.com', - 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', - 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', - 'cache-control': 'no-cache', - # Requests sorts cookies= alphabetically - # 'cookie': 'ptui_loginuin=1941163264; RK=nzPEtRXmWI; ptcz=4b478c47ddfaf994cad9c3eeb6099336c6302fdde27eb31949fd0d8502e7aed6; pgv_pvid=249131564; qz_screen=1707x960; QZ_FE_WEBP_SUPPORT=1; cpu_performance_v8=1; _qpsvr_localtk=0.0676035804419064; pgv_info=ssid=s3673858535; uin=o1941163264; p_uin=o1941163264; pt4_token=QUuDx3v5A1fbS9y1V-bgUZvp4AXSGeEt2897lTJUpgc_; p_skey=-RBLfzmoS*kIv9TQZMXaVjOEPuHcxMPsAQdhB6uSOdg_; Loading=Yes; 1941163264_todaycount=0; 1941163264_totalcount=20087; __Q_w_s__QZN_TodoMsgCnt=1; __layoutStat=12', - 'pragma': 'no-cache', - 'sec-ch-ua': '"Not A(Brand";v="99", "Microsoft Edge";v="121", "Chromium";v="121"', - 'sec-ch-ua-mobile': '?0', - 'sec-ch-ua-platform': '"Windows"', - 'sec-fetch-dest': 'document', - 'sec-fetch-mode': 'navigate', - 'sec-fetch-site': 'none', - 'sec-fetch-user': '?1', - 'upgrade-insecure-requests': '1', - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0', - } - - params = { - 'uin': '1941163264', - 'begin_time': '0', - 'end_time': '0', - 'getappnotification': '1', - 'getnotifi': '1', - 'has_get_key': '0', - 'offset': '15731', - 'set': '0', - 'count': '10', - 'useutf8': '1', - 'outputhtmlfeed': '1', - 'grz': '0.791498607065434', - 'scope': '1', - 'g_tk': [ - '1928892726', - '1928892726', - ], - } - - response = requests.get('https://user.qzone.qq.com/proxy/domain/ic2.qzone.qq.com/cgi-bin/feeds/feeds2_html_pav_all', - params=params, cookies=cookies, headers=headers) - return response - - -response = qzone_login() -json_str = response.text.strip().lstrip('_Callback(').rstrip(');') -# 将属性值的单引号替换为双引号 -output_str = re.sub(r"'([^']*)'", r'"\1"', json_str) -print(output_str) -output_str = re.sub(r'(\w+)(:)', r'"\1"\2', output_str) -# 移除多余的换行和制表符 -output_str = output_str.replace('\n', '').replace('\t', '').replace(' ', '') -print(output_str) - diff --git a/test/test1.py b/test/test1.py deleted file mode 100644 index dfc2bcb..0000000 --- a/test/test1.py +++ /dev/null @@ -1,155 +0,0 @@ -import requests -from PIL import Image -import time -import re -import os - -def bkn(pSkey): - # 计算bkn - t, n, o = 5381, 0, len(pSkey) - - while n < o: - t += (t << 5) + ord(pSkey[n]) - n += 1 - - return t & 2147483647 - - -def ptqrToken(qrsig): - # 计算ptqrtoken - n, i, e = len(qrsig), 0, 0 - - while n > i: - e += (e << 5) + ord(qrsig[i]) - i += 1 - - return 2147483647 & e - - -def QR(): - # 获取 qq空间 二维码 - url = 'https://ssl.ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=3&d=72&v=4&t=0.8692955245720428&daid=5&pt_3rd_aid=0' - - try: - r = requests.get(url) - qrsig = requests.utils.dict_from_cookiejar(r.cookies).get('qrsig') - - with open(r'.\QR.png', 'wb') as f: - f.write(r.content) - - im = Image.open(r'.\QR.png') - im = im.resize((350, 350)) - print(time.strftime('%H:%M:%S'), '登录二维码获取成功') - im.show() - - return qrsig - - except Exception as e: - print(e) - - -def cookie(): - if os.path.exists('cookies.txt'): - with open('cookies.txt', 'r') as file: - cookies = file.read() - return eval(cookies) - # 获取 QQ空间 cookie - qrsig = QR() - ptqrtoken = ptqrToken(qrsig) - - while True: - url = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&ptqrtoken=' + str( - ptqrtoken) + '&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-' + str( - time.time()) + '&js_ver=20032614&js_type=1&login_sig=&pt_uistyle=40&aid=549000912&daid=5&' - cookies = {'qrsig': qrsig} - - try: - r = requests.get(url, cookies=cookies) - - if '二维码未失效' in r.text: - print(time.strftime('%H:%M:%S'), '二维码未失效') - - elif '二维码认证中' in r.text: - print(time.strftime('%H:%M:%S'), '二维码认证中') - - elif '二维码已失效' in r.text: - print(time.strftime('%H:%M:%S'), '二维码已失效') - - else: - print(time.strftime('%H:%M:%S'), '登录成功') - - cookies = requests.utils.dict_from_cookiejar(r.cookies) - uin = requests.utils.dict_from_cookiejar(r.cookies).get('uin') - regex = re.compile(r'ptsigx=(.*?)&') - sigx = re.findall(regex, r.text)[0] - url = 'https://ptlogin2.qzone.qq.com/check_sig?pttype=1&uin=' + uin + '&service=ptqrlogin&nodirect=0&ptsigx=' + sigx + '&s_url=https%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&f_url=&ptlang=2052&ptredirect=100&aid=549000912&daid=5&j_later=0&low_login_hour=0®master=0&pt_login_type=3&pt_aid=0&pt_aaid=16&pt_light=0&pt_3rd_aid=0' - - try: - r = requests.get(url, cookies=cookies, allow_redirects=False) - targetCookies = requests.utils.dict_from_cookiejar(r.cookies) - # 存储cookies到本地 - with open(r'.\cookies.txt', 'w') as f: - f.write(str(targetCookies)) - pSkey = requests.utils.dict_from_cookiejar(r.cookies).get('p_skey') - break - - except Exception as e: - print(e) - - except Exception as e: - print(e) - - time.sleep(3) - - return targetCookies - - -def get_message(): - cookies = cookie() - g_tk = bkn(cookies.get('p_skey')) - # 去掉uin首位的o - uin = cookies.get('uin')[1:] - print(cookies) - headers = { - 'authority': 'user.qzone.qq.com', - 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', - 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', - 'cache-control': 'no-cache', - 'pragma': 'no-cache', - 'sec-ch-ua': '"Not A(Brand";v="99", "Microsoft Edge";v="121", "Chromium";v="121"', - 'sec-ch-ua-mobile': '?0', - 'sec-ch-ua-platform': '"Windows"', - 'sec-fetch-dest': 'document', - 'sec-fetch-mode': 'navigate', - 'sec-fetch-site': 'none', - 'sec-fetch-user': '?1', - 'upgrade-insecure-requests': '1', - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0', - } - params = { - 'uin': uin, - 'begin_time': '0', - 'end_time': '0', - 'getappnotification': '1', - 'getnotifi': '1', - 'has_get_key': '0', - 'offset': '0', - 'set': '0', - 'count': '10', - 'useutf8': '1', - 'outputhtmlfeed': '1', - 'scope': '1', - 'g_tk': [ - g_tk, - g_tk, - ], - } - response = requests.get('https://user.qzone.qq.com/proxy/domain/ic2.qzone.qq.com/cgi-bin/feeds/feeds2_html_pav_all', - params=params, cookies=cookies, headers=headers) - return response - - -if __name__ == '__main__': - message = get_message().text - json_str = message.strip().lstrip('_Callback(').rstrip(');') - print(json_str) diff --git a/util/ConfigUtil.py b/util/ConfigUtil.py index 12bde94..6171240 100644 --- a/util/ConfigUtil.py +++ b/util/ConfigUtil.py @@ -1,7 +1,35 @@ import configparser +import os config = configparser.ConfigParser() config.read('./resource/config/config.ini') temp_path = config.get('File', 'temp') -user_path = config.get('File', 'user') \ No newline at end of file +user_path = config.get('File', 'user') + + +def save_user(cookies): + with open(user_path + cookies.get('uin'), 'w') as f: + f.write(str(cookies)) + + +def read_files_in_folder(): + # 获取文件夹下的所有文件 + files = os.listdir(user_path) + + # 输出文件列表 + print("文件列表:") + for i, file in enumerate(files): + print(f"{i + 1}. {file}") + + # 选择文件 + choice = int(input("请选择要读取的文件编号: ")) + + # 读取选择的文件 + selected_file = files[choice - 1] + file_path = os.path.join(user_path, selected_file) + with open(file_path, 'r') as file: + content = file.read() + + return content + diff --git a/util/LoginUtil.py b/util/LoginUtil.py index 8265ab7..3e18f52 100644 --- a/util/LoginUtil.py +++ b/util/LoginUtil.py @@ -50,6 +50,8 @@ def QR(): def cookie(): + if Config.read_files_in_folder(): + return eval(Config.read_files_in_folder()) # 获取 QQ空间 cookie qrsig = QR() ptqrtoken = ptqrToken(qrsig) @@ -82,8 +84,7 @@ def cookie(): r = requests.get(url, cookies=cookies, allow_redirects=False) target_cookies = requests.utils.dict_from_cookiejar(r.cookies) p_skey = requests.utils.dict_from_cookiejar(r.cookies).get('p_skey') - # 删除二维码 - os.remove(Config.temp_path + 'QR.png') + Config.save_user(target_cookies) break except Exception as e: