修复检测登录的元素

This commit is contained in:
Rob0088
2025-07-19 22:54:51 +08:00
parent d436f4b295
commit 6695a3adbb
2 changed files with 38 additions and 21 deletions

View File

@@ -959,6 +959,7 @@
"level": 2, "level": 2,
"v2": true, "v2": true,
"history": { "history": {
"v1.7.3": "修复检测登录的元素",
"v1.7.2": "||wan参数细分,修复使用||wan时立即检测一次实际不生效,修复v1第三方备用通知可能无效,调整验证码获取", "v1.7.2": "||wan参数细分,修复使用||wan时立即检测一次实际不生效,修复v1第三方备用通知可能无效,调整验证码获取",
"v1.7.1": "允许使用'||wan2'选项及无法使用'立即检测一次'", "v1.7.1": "允许使用'||wan2'选项及无法使用'立即检测一次'",
"v1.7.0": "使用第三方通知时可IP变动后通知拟支持多网络出口检查。", "v1.7.0": "使用第三方通知时可IP变动后通知拟支持多网络出口检查。",

View File

@@ -31,7 +31,7 @@ class DynamicWeChat(_PluginBase):
# 插件图标 # 插件图标
plugin_icon = "Wecom_A.png" plugin_icon = "Wecom_A.png"
# 插件版本 # 插件版本
plugin_version = "1.7.2" plugin_version = "1.7.3"
# 插件作者 # 插件作者
plugin_author = "RamenRa" plugin_author = "RamenRa"
# 作者主页 # 作者主页
@@ -730,19 +730,31 @@ class DynamicWeChat(_PluginBase):
# 检查是否需要进行短信验证 # 检查是否需要进行短信验证
if task != 'refresh_cookie': if task != 'refresh_cookie':
logger.info("检查登录状态...") logger.info("检查登录状态...")
try:
# 先检查登录成功后的页面状态 success_selectors = [
success_element = page.wait_for_selector('#check_corp_info', timeout=5000) # 检查登录成功的元素 "//div[contains(@class, 'js_show_ipConfig_dialog')]//a[contains(@class, '_mod_card_operationLink') and text()='配置']",
if success_element: '#_hmt_click > div.index_colRight > div > div.index_info > div > a',
if task != 'refresh_cookie': '/html/body/div/section[3]/div[1]/main/div/div/div[2]/div/div[1]/div/a',
logger.info("登录成功!") '#_hmt_click > div.index_colLeft > div.index_greeting.index_explore_text > div:nth-child(1)'
return True ]
except Exception as e:
logger.debug(str(e))
pass
try: try:
# 在这里使用更安全的方式来检查元素是否存在 for selector in success_selectors:
try:
# 先检查登录成功后的页面状态
success_element = page.wait_for_selector(selector, timeout=3000) # 检查登录成功的元素
if success_element:
if task != 'refresh_cookie':
logger.info("登录成功!")
return True
except Exception as e:
logger.debug(str(e))
pass
except Exception as e:
logger.debug(f"登录检查异常: {e}")
try:
# 检查是否进入验证码界面
captcha_panel = page.wait_for_selector('.receive_captcha_panel', timeout=5000) # 检查验证码面板 captcha_panel = page.wait_for_selector('.receive_captcha_panel', timeout=5000) # 检查验证码面板
if captcha_panel: # 出现了短信验证界面 if captcha_panel: # 出现了短信验证界面
if task == 'local_scanning': if task == 'local_scanning':
@@ -758,20 +770,24 @@ class DynamicWeChat(_PluginBase):
confirm_button = page.wait_for_selector('.confirm_btn', timeout=5000) # 获取确认按钮 confirm_button = page.wait_for_selector('.confirm_btn', timeout=5000) # 获取确认按钮
confirm_button.click() # 点击确认 confirm_button.click() # 点击确认
time.sleep(3) # 等待处理 time.sleep(3) # 等待处理
# 等待登录成功的元素出现
success_element = page.wait_for_selector('#check_corp_info', timeout=5000) # 再次检查登录状态
if success_element: for selector in success_selectors:
self._verification_code = None try:
logger.info("验证码登录成功!") success_element = page.wait_for_selector(selector, timeout=3000)
return True if success_element:
self._verification_code = None
logger.info("验证码登录成功!")
return True
except:
continue
else: else:
logger.error("未收到短信验证码") logger.error("未收到短信验证码")
return False return False
except Exception as e: except Exception as e:
# logger.debug(str(e)) # 基于bug运行,请不要将错误输出到日志 # logger.debug(str(e)) # 基于bug运行,请不要将错误输出到日志
# try: # 没有登录成功,也没有短信验证码 # try: # 没有登录成功,也没有短信验证码
if self.find_qrc( if self.find_qrc(page) and task not in ['refresh_cookie', 'local_scanning']: # 延长任务找到的二维码不会被发送,所以不算用户没有扫码
page) and not task == 'refresh_cookie' and not task == 'local_scanning': # 延长任务找到的二维码不会被发送,所以不算用户没有扫码
logger.warning(f"用户没有扫描二维码") logger.warning(f"用户没有扫描二维码")
return False return False
@@ -801,7 +817,7 @@ class DynamicWeChat(_PluginBase):
app_urls = [f"{bash_url}{app_id.strip()}" for app_id in id_list] app_urls = [f"{bash_url}{app_id.strip()}" for app_id in id_list]
for app_url in app_urls: for app_url in app_urls:
app_id = app_url.split("/")[-1] app_id = app_url.split("/")[-1]
if app_id.startswith("100000") and len(app_id) == 6: if app_id.startswith("100000") and len(app_id) == 7:
self._ip_changed = False self._ip_changed = False
logger.warning(f"请根据 https://github.com/RamenRa/MoviePilot-Plugins 的说明进行配置应用ID") logger.warning(f"请根据 https://github.com/RamenRa/MoviePilot-Plugins 的说明进行配置应用ID")
return return