更新IMAP邮件获取功能和账户保存格式
This commit is contained in:
113
SteamCaptchaHelper.py
Normal file
113
SteamCaptchaHelper.py
Normal file
@@ -0,0 +1,113 @@
|
||||
import requests
|
||||
from lxml import etree
|
||||
from loguru import logger
|
||||
|
||||
class SteamCaptchaHelper:
|
||||
def __init__(self):
|
||||
# 使用标准的Steam请求头
|
||||
self.headers = {
|
||||
"Host": "store.steampowered.com",
|
||||
"X-Prototype-Version": "1.7",
|
||||
"sec-ch-ua-platform": "\"Windows\"",
|
||||
"sec-ch-ua": "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\"",
|
||||
"sec-ch-ua-mobile": "?0",
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Valve Steam Client/default/1741737356) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.183 Safari/537.36",
|
||||
"Accept": "text/javascript, text/html, application/xml, text/xml, */*",
|
||||
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"Origin": "https://store.steampowered.com",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"Sec-Fetch-Dest": "empty",
|
||||
"Referer": "https://store.steampowered.com/join/",
|
||||
"Accept-Language": "zh-CN,zh;q=0.9"
|
||||
}
|
||||
self.session = requests.Session()
|
||||
self.session.headers.update(self.headers)
|
||||
|
||||
def get_sitekey(self):
|
||||
"""获取Steam网站的sitekey和其他必要信息"""
|
||||
try:
|
||||
# 获取初始页面
|
||||
logger.info("获取Steam注册页面...")
|
||||
url = "https://store.steampowered.com/join/"
|
||||
response = self.session.get(url, verify=False)
|
||||
html = etree.HTML(response.text)
|
||||
|
||||
# 提取init_id
|
||||
init_id = html.xpath('//input[@name="init_id"]/@value')
|
||||
if init_id:
|
||||
init_id = init_id[0]
|
||||
logger.info(f"获取init_id成功: {init_id}")
|
||||
else:
|
||||
logger.error("无法获取init_id")
|
||||
return None
|
||||
|
||||
# 刷新验证码获取sitekey
|
||||
logger.info("刷新验证码获取sitekey...")
|
||||
url = "https://store.steampowered.com/join/refreshcaptcha/"
|
||||
data = {"count": "1", "hcaptcha": "1"}
|
||||
response = self.session.post(url, data=data, verify=False)
|
||||
result = response.json()
|
||||
|
||||
gid = result.get("gid")
|
||||
sitekey = result.get("sitekey")
|
||||
|
||||
logger.info(f"获取gid成功: {gid}")
|
||||
logger.info(f"获取sitekey成功: {sitekey}")
|
||||
|
||||
return {
|
||||
"session": self.session,
|
||||
"init_id": init_id,
|
||||
"gid": gid,
|
||||
"sitekey": sitekey
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"获取sitekey过程中出错: {str(e)}")
|
||||
return None
|
||||
|
||||
def verify_email(self, email, captcha_text, init_id, gid):
|
||||
"""验证邮箱步骤"""
|
||||
try:
|
||||
logger.info(f"验证邮箱: {email}")
|
||||
url = "https://store.steampowered.com/join/ajaxverifyemail"
|
||||
|
||||
post_data = {
|
||||
"email": email,
|
||||
"captchagid": gid,
|
||||
"captcha_text": captcha_text,
|
||||
"elang": "6",
|
||||
"init_id": init_id,
|
||||
"guest": "false"
|
||||
}
|
||||
|
||||
response = self.session.post(url, data=post_data, verify=False)
|
||||
result = response.json()
|
||||
|
||||
logger.info(f"验证邮箱结果: {result}")
|
||||
|
||||
# 检查不同的响应类型
|
||||
# 1 表示成功
|
||||
# 17 可能是"创建Steam账户时发生错误"
|
||||
# 其他失败情况
|
||||
if 'success' not in result:
|
||||
result['success'] = 0
|
||||
result['error'] = "无效的响应"
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f"验证邮箱过程中出错: {str(e)}")
|
||||
return {"success": 0, "error": str(e)}
|
||||
|
||||
def get_user_agent(self):
|
||||
"""返回Steam的用户代理"""
|
||||
return self.headers["User-Agent"]
|
||||
|
||||
# 使用示例
|
||||
if __name__ == "__main__":
|
||||
helper = SteamCaptchaHelper()
|
||||
data = helper.get_sitekey()
|
||||
if data:
|
||||
print(f"成功获取sitekey: {data['sitekey']}")
|
||||
else:
|
||||
print("获取sitekey失败")
|
||||
Reference in New Issue
Block a user