mirror of
https://github.com/icepage/AutoUpdateJdCookie.git
synced 2026-06-05 21:02:55 +08:00
支持了JD登录的代理
This commit is contained in:
parent
1d252fbfa9
commit
f0aefeebbf
@ -8,6 +8,7 @@
|
||||
- 支持的账号类型有:
|
||||
- 账号密码登录
|
||||
- QQ登录(不会出验证码,推荐)
|
||||
- 支持代理
|
||||

|
||||
|
||||
|
||||
@ -79,6 +80,7 @@ playwright install chromium
|
||||
- auto_shape_recognition为二次图形状验证码的开关;
|
||||
- headless设置浏览器是否启用无头模式,即是否展示整个登录过程,**必需使用True**
|
||||
- cron_expression基于cron的表达式,用于schedule_main.py定期进行更新任务;
|
||||
- proxy为JD登录的代理配置, 只会代理登录,不会代理请求QL面板和发消息;
|
||||
- 消息类的配置下面会说明;
|
||||
- 消息类的配置下面会说明
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
- python >= 3.9 (playwright依赖的typing,在3.7和3.8会报错typing.NoReturn的BUG)
|
||||
- 支持windows,linux(无GUI)
|
||||
- 支持docker部署
|
||||
- 支持代理
|
||||
- linux无GUI使用文档请转向 [linux无GUI使用文档](https://github.com/icepage/AutoUpdateJdCookie/blob/main/README.linux.md)
|
||||
- WINDOWS整体效果如下图
|
||||
|
||||
@ -85,6 +86,7 @@ playwright install chromium
|
||||
- auto_shape_recognition为二次图形状验证码的开关;
|
||||
- headless设置浏览器是否启用无头模式,即是否展示整个登录过程,建议调试时False,稳定后True;
|
||||
- cron_expression基于cron的表达式,用于schedule_main.py定期进行更新任务;
|
||||
- proxy为JD登录的代理配置, 只会代理登录,不会代理请求QL面板和发消息;
|
||||
- 消息类的配置下面会说明;
|
||||
- 短信验证码说明在下面会说明。
|
||||
|
||||
|
||||
@ -77,4 +77,14 @@ send_info = {
|
||||
# manual_input 手动在终端输入验证码
|
||||
# webhook 调用api获取验证码,可实现全自动填写验证码
|
||||
sms_func = "manual_input"
|
||||
sms_webhook = "https://127.0.0.1:3000/getCode"
|
||||
sms_webhook = "https://127.0.0.1:3000/getCode"
|
||||
|
||||
# 代理的配置,只代理登录,不代理请求QL面板和发消息
|
||||
proxy = {
|
||||
# 代理服务器地址, 支持http, https, socks5
|
||||
"server": "http://",
|
||||
# 代理服务器账号
|
||||
"username": "",
|
||||
# 代理服务器密码
|
||||
"password": ""
|
||||
}
|
||||
18
main.py
18
main.py
@ -41,7 +41,8 @@ from utils.tools import (
|
||||
expand_coordinates,
|
||||
cv2_save_img,
|
||||
ddddocr_find_bytes_pic,
|
||||
solve_slider_captcha
|
||||
solve_slider_captcha,
|
||||
validate_proxy_config
|
||||
)
|
||||
|
||||
"""
|
||||
@ -370,7 +371,20 @@ async def get_jd_pt_key(playwright: Playwright, user) -> Union[str, None]:
|
||||
headless = False
|
||||
|
||||
args = '--no-sandbox', '--disable-setuid-sandbox'
|
||||
browser = await playwright.chromium.launch(headless=headless, args=args)
|
||||
|
||||
try:
|
||||
# 引入代理
|
||||
from config import proxy
|
||||
# 检查代理的配置
|
||||
is_proxy_valid, msg = validate_proxy_config(proxy)
|
||||
if not is_proxy_valid:
|
||||
logger.error(msg)
|
||||
proxy = None
|
||||
except ImportError:
|
||||
logger.info("未配置代理")
|
||||
proxy = None
|
||||
|
||||
browser = await playwright.chromium.launch(headless=headless, args=args, proxy=proxy)
|
||||
context = await browser.new_context()
|
||||
|
||||
try:
|
||||
|
||||
@ -363,3 +363,32 @@ async def send_request(url: str, method: str, headers: Dict[str, Any], data: Dic
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.request(method, url=url, json=data, headers=headers, **kwargs) as response:
|
||||
return await response.json()
|
||||
|
||||
|
||||
def validate_proxy_config(proxy):
|
||||
# 验证 server 是否为有效的 URL 地址
|
||||
server = proxy.get("server")
|
||||
username = proxy.get("username")
|
||||
password = proxy.get("password")
|
||||
|
||||
# 使用正则表达式来检查 server 是否是有效的 URL
|
||||
url_pattern = re.compile(
|
||||
r'^(http|https|socks5)://'
|
||||
r'(?:(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,6}|' # 域名
|
||||
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # 或者IP地址
|
||||
r'(?::\d+)?' # 可选端口
|
||||
r'(?:/.*)?$' # 可选路径
|
||||
)
|
||||
|
||||
if not server or not url_pattern.match(server):
|
||||
return False, "代理的server URL异常"
|
||||
|
||||
# 检查 username 是否为空,若为空则忽略 password 的检查
|
||||
if username:
|
||||
if not password:
|
||||
return False, "代理只有账号, 缺少密码配置"
|
||||
else:
|
||||
if password:
|
||||
return False, "代理只有密码, 缺少账号配置"
|
||||
|
||||
return True, "代理配置正常可用"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user