|
@@ -5,7 +5,7 @@ import re
|
|
|
import os
|
|
import os
|
|
|
import uuid
|
|
import uuid
|
|
|
import base64
|
|
import base64
|
|
|
-from datetime import datetime
|
|
|
|
|
|
|
+from datetime import datetime, timezone
|
|
|
from typing import List, Dict, Optional, Any, Callable
|
|
from typing import List, Dict, Optional, Any, Callable
|
|
|
from DrissionPage import ChromiumPage
|
|
from DrissionPage import ChromiumPage
|
|
|
|
|
|
|
@@ -48,10 +48,11 @@ def get_alias_email(email: str, new_domain: str = "text.skin") -> str:
|
|
|
class DePlugin(IVSPlg):
|
|
class DePlugin(IVSPlg):
|
|
|
"""
|
|
"""
|
|
|
Germany (Visametric) 签证预约插件 (Browser + Tunnel Mode)
|
|
Germany (Visametric) 签证预约插件 (Browser + Tunnel Mode)
|
|
|
|
|
+ 兼容有日历选时模式 (calendarType != 0) 与无日历排队等候模式 (calendarType == 0)
|
|
|
"""
|
|
"""
|
|
|
name = "de_plugin"
|
|
name = "de_plugin"
|
|
|
- version = "1.0.0"
|
|
|
|
|
- description = "德国Visametric签证预约插件 (支持Cloudflare穿透与OCR验证)"
|
|
|
|
|
|
|
+ version = "1.1.0"
|
|
|
|
|
+ description = "德国Visametric签证预约插件 (支持Cloudflare穿透、OCR验证、双日历模式及完整前置校验)"
|
|
|
|
|
|
|
|
def __init__(self, group_id: str):
|
|
def __init__(self, group_id: str):
|
|
|
self.group_id = group_id
|
|
self.group_id = group_id
|
|
@@ -77,11 +78,28 @@ class DePlugin(IVSPlg):
|
|
|
# 字符识别引擎
|
|
# 字符识别引擎
|
|
|
self.ocr_engine: Optional[DddOcrEngine] = None
|
|
self.ocr_engine: Optional[DddOcrEngine] = None
|
|
|
|
|
|
|
|
- # 业务状态
|
|
|
|
|
|
|
+ # 业务与配置状态
|
|
|
self.base_url = "https://ie-appointment.visametric.com"
|
|
self.base_url = "https://ie-appointment.visametric.com"
|
|
|
self.csrf_token = ""
|
|
self.csrf_token = ""
|
|
|
self.personal_info_val = ""
|
|
self.personal_info_val = ""
|
|
|
self.email_val_control = ""
|
|
self.email_val_control = ""
|
|
|
|
|
+
|
|
|
|
|
+ # 动态业务参数 (默认以都柏林为例,可通过 free_config 动态覆盖)
|
|
|
|
|
+ self.consular_id = "1"
|
|
|
|
|
+ self.city_id = "6"
|
|
|
|
|
+ self.office_id = "1"
|
|
|
|
|
+ self.office_type = "1"
|
|
|
|
|
+ self.service_type_id = "1"
|
|
|
|
|
+ self.language_id = "2"
|
|
|
|
|
+ self.app_country_view = "Schengen - Tourism/Family&Friend Visit/Transit Visa/Other Purposes"
|
|
|
|
|
+ self.app_office_view = "Dublin"
|
|
|
|
|
+ self.app_service_type_view = "NORMAL"
|
|
|
|
|
+ self.nationality = "2"
|
|
|
|
|
+
|
|
|
|
|
+ # 邮箱与 OTP 策略
|
|
|
|
|
+ self.use_alias_email = False
|
|
|
|
|
+ self.alias_domain = "text.skin"
|
|
|
|
|
+ self.master_email = "hujiarui8@gmail.com"
|
|
|
|
|
|
|
|
def set_log(self, logger: Callable[[str], None]) -> None:
|
|
def set_log(self, logger: Callable[[str], None]) -> None:
|
|
|
self.logger = logger
|
|
self.logger = logger
|
|
@@ -97,6 +115,26 @@ class DePlugin(IVSPlg):
|
|
|
self.free_config = config.free_config or {}
|
|
self.free_config = config.free_config or {}
|
|
|
if self.free_config.get("base_url"):
|
|
if self.free_config.get("base_url"):
|
|
|
self.base_url = self.free_config["base_url"].rstrip('/')
|
|
self.base_url = self.free_config["base_url"].rstrip('/')
|
|
|
|
|
+
|
|
|
|
|
+ self.consular_id = str(self.free_config.get("consularid", "1"))
|
|
|
|
|
+ self.city_id = str(self.free_config.get("city", "6"))
|
|
|
|
|
+ self.office_id = str(self.free_config.get("office", "1"))
|
|
|
|
|
+ self.office_type = str(self.free_config.get("officetype", "1"))
|
|
|
|
|
+ self.service_type_id = str(self.free_config.get("service_type_id", "1"))
|
|
|
|
|
+ self.language_id = str(self.free_config.get("language_id", "2"))
|
|
|
|
|
+
|
|
|
|
|
+ self.app_country_view = self.free_config.get(
|
|
|
|
|
+ "view_set_app_country",
|
|
|
|
|
+ "Schengen - Tourism/Family&Friend Visit/Transit Visa/Other Purposes"
|
|
|
|
|
+ )
|
|
|
|
|
+ self.app_office_view = self.free_config.get("view_set_app_office", "Dublin")
|
|
|
|
|
+ self.app_service_type_view = self.free_config.get("view_set_app_service_type", "NORMAL")
|
|
|
|
|
+ self.nationality = str(self.free_config.get("nationality", "2"))
|
|
|
|
|
+
|
|
|
|
|
+ # 邮箱与验证码配置
|
|
|
|
|
+ self.use_alias_email = bool(self.free_config.get("use_alias_email", False))
|
|
|
|
|
+ self.alias_domain = self.free_config.get("alias_domain", "text.skin")
|
|
|
|
|
+ self.master_email = self.free_config.get("master_email", "hujiarui8@gmail.com")
|
|
|
|
|
|
|
|
def keep_alive(self):
|
|
def keep_alive(self):
|
|
|
pass
|
|
pass
|
|
@@ -109,7 +147,7 @@ class DePlugin(IVSPlg):
|
|
|
return False
|
|
return False
|
|
|
except Exception:
|
|
except Exception:
|
|
|
return False
|
|
return False
|
|
|
- if self.config.session_max_life > 0:
|
|
|
|
|
|
|
+ if self.config and self.config.session_max_life > 0:
|
|
|
if time.time() - self.session_create_time > self.config.session_max_life:
|
|
if time.time() - self.session_create_time > self.config.session_max_life:
|
|
|
self._log("Session expired.")
|
|
self._log("Session expired.")
|
|
|
return False
|
|
return False
|
|
@@ -175,7 +213,7 @@ class DePlugin(IVSPlg):
|
|
|
# 4. 识别验证码 (本地 OCR 服务)
|
|
# 4. 识别验证码 (本地 OCR 服务)
|
|
|
captcha_code = self.ocr_engine.inference_captcha(image_bytes)
|
|
captcha_code = self.ocr_engine.inference_captcha(image_bytes)
|
|
|
|
|
|
|
|
- # 5. 提交验证码 (获取 PersonalInfo)
|
|
|
|
|
|
|
+ # 5. 提交验证码 (获取 PersonalInfo 与 emailValControl)
|
|
|
self._submit_captcha(captcha_code)
|
|
self._submit_captcha(captcha_code)
|
|
|
|
|
|
|
|
self.session_create_time = time.time()
|
|
self.session_create_time = time.time()
|
|
@@ -218,17 +256,137 @@ class DePlugin(IVSPlg):
|
|
|
if m:
|
|
if m:
|
|
|
self.csrf_token = m.group(1)
|
|
self.csrf_token = m.group(1)
|
|
|
|
|
|
|
|
|
|
+ def _get_calendar_status(self) -> str:
|
|
|
|
|
+ """
|
|
|
|
|
+ 向服务端发起自动探测,获取办事处日历状态:
|
|
|
|
|
+ "0": 无日历配额 / 等候名单 (without calendar quota)
|
|
|
|
|
+ "2": 正常选日历模式
|
|
|
|
|
+ """
|
|
|
|
|
+ url = f"{self.base_url}/en/getcalendarstatus"
|
|
|
|
|
+ payload = {
|
|
|
|
|
+ "getvisaofficeid": self.office_id,
|
|
|
|
|
+ "getservicetypeid": self.service_type_id,
|
|
|
|
|
+ "getvisacountryid": self.consular_id
|
|
|
|
|
+ }
|
|
|
|
|
+ headers = {
|
|
|
|
|
+ 'X-CSRF-TOKEN': self.csrf_token,
|
|
|
|
|
+ 'X-Requested-With': 'XMLHttpRequest'
|
|
|
|
|
+ }
|
|
|
|
|
+ resp = self._perform_request('POST', url, data=payload, headers=headers)
|
|
|
|
|
+ status = resp.text.strip().strip('"')
|
|
|
|
|
+ self._log(f"Calendar Status for Office {self.office_id}: {status}")
|
|
|
|
|
+ return status if status else "0"
|
|
|
|
|
+
|
|
|
|
|
+ def _confirm_without_calendar_mode(self):
|
|
|
|
|
+ """无日历模式下的服务确认与无配额状态校验"""
|
|
|
|
|
+ headers = {
|
|
|
|
|
+ 'X-CSRF-TOKEN': self.csrf_token,
|
|
|
|
|
+ 'X-Requested-With': 'XMLHttpRequest'
|
|
|
|
|
+ }
|
|
|
|
|
+ # 1. getservices
|
|
|
|
|
+ self._perform_request('POST', f"{self.base_url}/en/getservices", data={
|
|
|
|
|
+ "country_id": self.consular_id,
|
|
|
|
|
+ "service_type_id": self.service_type_id,
|
|
|
|
|
+ "office_id": self.office_id,
|
|
|
|
|
+ "languageID": self.language_id,
|
|
|
|
|
+ "calendarType": "0"
|
|
|
|
|
+ }, headers=headers)
|
|
|
|
|
+
|
|
|
|
|
+ # 2. withoutcalendarquota
|
|
|
|
|
+ self._perform_request('POST', f"{self.base_url}/en/withoutcalendarquota", data={
|
|
|
|
|
+ "dateall": "0",
|
|
|
|
|
+ "personCountTotal": "1"
|
|
|
|
|
+ }, headers=headers)
|
|
|
|
|
+
|
|
|
|
|
+ def _pre_validate_controls(self, passport_no: str, email: str, phone_no: str, cal_status: str):
|
|
|
|
|
+ """
|
|
|
|
|
+ 执行完整的个人信息校验与前置服务检查
|
|
|
|
|
+ 对应 HAR 录制中的 entries #11 - #16 时序
|
|
|
|
|
+ """
|
|
|
|
|
+ headers = {
|
|
|
|
|
+ 'X-CSRF-TOKEN': self.csrf_token,
|
|
|
|
|
+ 'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
|
+ 'Referer': f"{self.base_url}/en/appointment-form"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ self._log(f"Running pre-validation controls: passport={passport_no}, email={email}, phone={phone_no}...")
|
|
|
|
|
+
|
|
|
|
|
+ # 1. passport-control
|
|
|
|
|
+ self._log("[1/6] Validating passport...")
|
|
|
|
|
+ resp = self._perform_request('POST', f"{self.base_url}/en/personal/passport-control", data={
|
|
|
|
|
+ 'passport[]': passport_no,
|
|
|
|
|
+ 'country_id': self.consular_id
|
|
|
|
|
+ }, headers=headers)
|
|
|
|
|
+ self._log(f"[1/6] Passport validated (status {resp.status_code})")
|
|
|
|
|
+
|
|
|
|
|
+ # 2. email-control
|
|
|
|
|
+ self._log("[2/6] Validating email...")
|
|
|
|
|
+ resp = self._perform_request('POST', f"{self.base_url}/en/personal/email-control", data={
|
|
|
|
|
+ 'email[]': email,
|
|
|
|
|
+ 'country_id': self.consular_id
|
|
|
|
|
+ }, headers=headers)
|
|
|
|
|
+ self._log(f"[2/6] Email validated (status {resp.status_code})")
|
|
|
|
|
+
|
|
|
|
|
+ # 3. phone-control
|
|
|
|
|
+ self._log("[3/6] Validating phone...")
|
|
|
|
|
+ resp = self._perform_request('POST', f"{self.base_url}/en/personal/phone-control", data={
|
|
|
|
|
+ 'phone[]': phone_no,
|
|
|
|
|
+ 'country_id': self.consular_id
|
|
|
|
|
+ }, headers=headers)
|
|
|
|
|
+ self._log(f"[3/6] Phone validated (status {resp.status_code})")
|
|
|
|
|
+
|
|
|
|
|
+ # 4. getservices
|
|
|
|
|
+ self._log("[4/6] Querying services...")
|
|
|
|
|
+ resp = self._perform_request('POST', f"{self.base_url}/en/getservices", data={
|
|
|
|
|
+ "country_id": self.consular_id,
|
|
|
|
|
+ "service_type_id": self.service_type_id,
|
|
|
|
|
+ "office_id": self.office_id,
|
|
|
|
|
+ "languageID": self.language_id,
|
|
|
|
|
+ "calendarType": cal_status
|
|
|
|
|
+ }, headers=headers)
|
|
|
|
|
+ self._log(f"[4/6] Services queried (status {resp.status_code})")
|
|
|
|
|
+
|
|
|
|
|
+ # 5. withoutcalendarquota (若为无日历模式)
|
|
|
|
|
+ if cal_status == "0":
|
|
|
|
|
+ self._log("[5/6] Confirming without-calendar quota...")
|
|
|
|
|
+ resp = self._perform_request('POST', f"{self.base_url}/en/withoutcalendarquota", data={
|
|
|
|
|
+ "dateall": "0",
|
|
|
|
|
+ "personCountTotal": "1"
|
|
|
|
|
+ }, headers=headers)
|
|
|
|
|
+ self._log(f"[5/6] Without-calendar quota confirmed (status {resp.status_code})")
|
|
|
|
|
+
|
|
|
|
|
+ # 6. check-service-packages
|
|
|
|
|
+ self._log("[6/6] Checking service packages...")
|
|
|
|
|
+ resp = self._perform_request('POST', f"{self.base_url}/en/check-service-packages", data={}, headers=headers)
|
|
|
|
|
+ self._log(f"[6/6] Service packages checked (status {resp.status_code})")
|
|
|
|
|
+ self._log("Pre-validation controls completed successfully.")
|
|
|
|
|
+
|
|
|
def query(self, apt_type: AppointmentType) -> VSQueryResult:
|
|
def query(self, apt_type: AppointmentType) -> VSQueryResult:
|
|
|
res = VSQueryResult()
|
|
res = VSQueryResult()
|
|
|
res.success = False
|
|
res.success = False
|
|
|
|
|
|
|
|
- consular_id = self.free_config.get("consularid", "1")
|
|
|
|
|
|
|
+ cal_status = self._get_calendar_status()
|
|
|
|
|
+
|
|
|
|
|
+ # 模式一:无日历排队模式 (如爱尔兰都柏林等候名单)
|
|
|
|
|
+ if cal_status == "0":
|
|
|
|
|
+ self._confirm_without_calendar_mode()
|
|
|
|
|
+ res.success = True
|
|
|
|
|
+ res.availability_status = AvailabilityStatus.Available
|
|
|
|
|
+ today = datetime.now()
|
|
|
|
|
+ res.earliest_date = today
|
|
|
|
|
+ res.availability = [
|
|
|
|
|
+ DateAvailability(date=today, times=[TimeSlot(time="WAITLIST")])
|
|
|
|
|
+ ]
|
|
|
|
|
+ self._log("Without-calendar mode detected: Waitlist available.")
|
|
|
|
|
+ return res
|
|
|
|
|
+
|
|
|
|
|
+ # 模式二:普通有日历模式
|
|
|
url = f"{self.base_url}/en/getdate"
|
|
url = f"{self.base_url}/en/getdate"
|
|
|
payload = {
|
|
payload = {
|
|
|
- "consularid": consular_id,
|
|
|
|
|
|
|
+ "consularid": self.consular_id,
|
|
|
"exitid": "1",
|
|
"exitid": "1",
|
|
|
- "servicetypeid": "1",
|
|
|
|
|
- "calendarType": "2",
|
|
|
|
|
|
|
+ "servicetypeid": self.service_type_id,
|
|
|
|
|
+ "calendarType": cal_status,
|
|
|
"totalperson": "1"
|
|
"totalperson": "1"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -264,34 +422,70 @@ class DePlugin(IVSPlg):
|
|
|
def book(self, slot_info: VSQueryResult, user_inputs: Dict = None) -> VSBookResult:
|
|
def book(self, slot_info: VSQueryResult, user_inputs: Dict = None) -> VSBookResult:
|
|
|
res = VSBookResult()
|
|
res = VSBookResult()
|
|
|
user_inputs = user_inputs or {}
|
|
user_inputs = user_inputs or {}
|
|
|
- exp_start = user_inputs.get('expected_start_date', '')
|
|
|
|
|
- exp_end = user_inputs.get('expected_end_date', '')
|
|
|
|
|
|
|
|
|
|
- available_dates_str = [
|
|
|
|
|
- da.date.strftime("%Y-%m-%d")
|
|
|
|
|
- for da in slot_info.availability
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ # 1. 动态检测日历模式
|
|
|
|
|
+ cal_status = self._get_calendar_status()
|
|
|
|
|
|
|
|
- valid_dates = filter_dates_in_range(available_dates_str, exp_start, exp_end, shuffle=True)
|
|
|
|
|
- if not valid_dates:
|
|
|
|
|
- raise NotFoundError("No dates match constraints")
|
|
|
|
|
|
|
+ target_date = ""
|
|
|
|
|
+ time_slot = {'data_id': '', 'data_all': '', 'time': 'WAITLIST'}
|
|
|
|
|
|
|
|
- target_date = random.choice(valid_dates)
|
|
|
|
|
- self._log(f"Selected date: {target_date}")
|
|
|
|
|
|
|
+ if cal_status != "0":
|
|
|
|
|
+ # 有日历模式:筛选有效日期并提取 slot
|
|
|
|
|
+ exp_start = user_inputs.get('expected_start_date', '')
|
|
|
|
|
+ exp_end = user_inputs.get('expected_end_date', '')
|
|
|
|
|
+
|
|
|
|
|
+ available_dates_str = [
|
|
|
|
|
+ da.date.strftime("%Y-%m-%d")
|
|
|
|
|
+ for da in slot_info.availability
|
|
|
|
|
+ if da.times and da.times[0].time != "WAITLIST"
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ valid_dates = filter_dates_in_range(available_dates_str, exp_start, exp_end, shuffle=True)
|
|
|
|
|
+ if not valid_dates:
|
|
|
|
|
+ raise NotFoundError("No dates match constraints")
|
|
|
|
|
+
|
|
|
|
|
+ target_date = random.choice(valid_dates)
|
|
|
|
|
+ self._log(f"Selected date: {target_date}")
|
|
|
|
|
+ time_slot = self._get_slot_time(target_date)
|
|
|
|
|
+ else:
|
|
|
|
|
+ # 无日历模式:不需要选 slot,直接以出行日期或当前日期为目标
|
|
|
|
|
+ target_date = user_inputs.get('travel_date', datetime.now().strftime("%Y-%m-%d"))[:10]
|
|
|
|
|
+ self._log(f"Booking in without-calendar mode, target date: {target_date}")
|
|
|
|
|
+
|
|
|
|
|
+ # 2. 准备邮箱和手机号
|
|
|
|
|
+ raw_email = user_inputs.get("email", "")
|
|
|
|
|
+ if self.use_alias_email:
|
|
|
|
|
+ booking_email = get_alias_email(raw_email, new_domain=self.alias_domain)
|
|
|
|
|
+ else:
|
|
|
|
|
+ booking_email = raw_email
|
|
|
|
|
+
|
|
|
|
|
+ phone_no = user_inputs.get("phone_no") or user_inputs.get("phone", "")
|
|
|
|
|
+ passport_no = user_inputs.get("passport_no") or user_inputs.get("passport", "")
|
|
|
|
|
+
|
|
|
|
|
+ # 3. 按照 HAR 时序执行前置校验与服务检查
|
|
|
|
|
+ self._pre_validate_controls(passport_no, booking_email, phone_no, cal_status)
|
|
|
|
|
|
|
|
- # 1. 获取时间 Slot
|
|
|
|
|
- time_slot = self._get_slot_time(target_date)
|
|
|
|
|
|
|
+ # 4. 记录发邮件前的旧验证码与精准 UTC 时间戳,杜绝读取到历史旧邮件
|
|
|
|
|
+ old_otp = self._peek_latest_otp(booking_email)
|
|
|
|
|
+ send_time_utc = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
+ self._log(f"Pre-send snapshot: current latest OTP='{old_otp}', send_time_utc='{send_time_utc}'")
|
|
|
|
|
|
|
|
- # 2. 发送邮件流程
|
|
|
|
|
- alias_email = get_alias_email(user_inputs.get("email", ""), new_domain='text.skin')
|
|
|
|
|
- self._send_email_step1(alias_email)
|
|
|
|
|
|
|
+ # 5. 发送邮箱验证码流程 (jky45fgd -> confirmCodeSendMail)
|
|
|
|
|
+ self._send_email_step1(booking_email)
|
|
|
self._send_email_step2("0")
|
|
self._send_email_step2("0")
|
|
|
|
|
|
|
|
- # 3. 读取 OTP
|
|
|
|
|
- otp_code = self._read_otp_email(alias_email)
|
|
|
|
|
-
|
|
|
|
|
- # 4. 提交确认
|
|
|
|
|
- book_res_html = self._confirm_appointment(target_date, time_slot, user_inputs, otp_code, alias_email)
|
|
|
|
|
|
|
+ # 6. 读取新到达的 OTP 验证码 (排除 old_otp)
|
|
|
|
|
+ otp_code = self._read_otp_email(booking_email, send_time_utc=send_time_utc, old_otp=old_otp)
|
|
|
|
|
+
|
|
|
|
|
+ # 7. 提交预约确认
|
|
|
|
|
+ book_res_html = self._confirm_appointment(
|
|
|
|
|
+ target_date=target_date,
|
|
|
|
|
+ slot_data=time_slot,
|
|
|
|
|
+ user_inputs=user_inputs,
|
|
|
|
|
+ otp=otp_code,
|
|
|
|
|
+ alias_email=booking_email,
|
|
|
|
|
+ cal_status=cal_status
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
if "complete all required fields" in book_res_html.lower():
|
|
if "complete all required fields" in book_res_html.lower():
|
|
|
raise BizLogicError("Incomplete fields response")
|
|
raise BizLogicError("Incomplete fields response")
|
|
@@ -355,10 +549,10 @@ class DePlugin(IVSPlg):
|
|
|
payload = {
|
|
payload = {
|
|
|
"fulldate": converted_date,
|
|
"fulldate": converted_date,
|
|
|
"totalperson": "1",
|
|
"totalperson": "1",
|
|
|
- "set_new_consular_id": self.free_config.get("consularid", "1"),
|
|
|
|
|
- "set_new_exit_office_id": "1",
|
|
|
|
|
|
|
+ "set_new_consular_id": self.consular_id,
|
|
|
|
|
+ "set_new_exit_office_id": self.office_id,
|
|
|
"calendarType": "2",
|
|
"calendarType": "2",
|
|
|
- "set_new_service_type_id": "1",
|
|
|
|
|
|
|
+ "set_new_service_type_id": self.service_type_id,
|
|
|
"personalinfo": self.personal_info_val
|
|
"personalinfo": self.personal_info_val
|
|
|
}
|
|
}
|
|
|
headers = {'X-CSRF-TOKEN': self.csrf_token, 'X-Requested-With': 'XMLHttpRequest'}
|
|
headers = {'X-CSRF-TOKEN': self.csrf_token, 'X-Requested-With': 'XMLHttpRequest'}
|
|
@@ -373,31 +567,114 @@ class DePlugin(IVSPlg):
|
|
|
return random.choice(times)
|
|
return random.choice(times)
|
|
|
|
|
|
|
|
def _send_email_step1(self, email: str):
|
|
def _send_email_step1(self, email: str):
|
|
|
|
|
+ self._log(f"Sending OTP verification email step 1 (jky45fgd) to: {email}...")
|
|
|
url = f"{self.base_url}/en/jky45fgd"
|
|
url = f"{self.base_url}/en/jky45fgd"
|
|
|
payload = {"emailCheck": email, "personalinfo": self.personal_info_val}
|
|
payload = {"emailCheck": email, "personalinfo": self.personal_info_val}
|
|
|
- headers = {'X-CSRF-TOKEN': self.csrf_token, 'X-Requested-With': 'XMLHttpRequest'}
|
|
|
|
|
- self._perform_request('POST', url, data=payload, headers=headers)
|
|
|
|
|
|
|
+ headers = {
|
|
|
|
|
+ 'X-CSRF-TOKEN': self.csrf_token,
|
|
|
|
|
+ 'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
|
+ 'Referer': f"{self.base_url}/en/appointment-form"
|
|
|
|
|
+ }
|
|
|
|
|
+ resp = self._perform_request('POST', url, data=payload, headers=headers)
|
|
|
|
|
+ self._log(f"OTP step 1 finished (status {resp.status_code})")
|
|
|
|
|
|
|
|
def _send_email_step2(self, code_val: str):
|
|
def _send_email_step2(self, code_val: str):
|
|
|
|
|
+ self._log(f"Sending OTP verification email step 2 (confirmCodeSendMail) code_val={code_val}...")
|
|
|
url = f"{self.base_url}/en/confirmCodeSendMail"
|
|
url = f"{self.base_url}/en/confirmCodeSendMail"
|
|
|
payload = {"confirmCode": code_val, "emailValControl": self.email_val_control}
|
|
payload = {"confirmCode": code_val, "emailValControl": self.email_val_control}
|
|
|
- headers = {'X-CSRF-TOKEN': self.csrf_token, 'X-Requested-With': 'XMLHttpRequest'}
|
|
|
|
|
- self._perform_request('POST', url, data=payload, headers=headers)
|
|
|
|
|
-
|
|
|
|
|
- def _read_otp_email(self, recipient: str) -> str:
|
|
|
|
|
- master_email = "hujiarui8@gmail.com"
|
|
|
|
|
- sender = 'Visametric - verify at visametric.com'
|
|
|
|
|
- now_utc = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
- for _ in range(12):
|
|
|
|
|
- c = VSCloudApi.Instance().fetch_mail_content(master_email, sender, recipient, 'Verification Code', 'Verification code', now_utc, 300)
|
|
|
|
|
|
|
+ headers = {
|
|
|
|
|
+ 'X-CSRF-TOKEN': self.csrf_token,
|
|
|
|
|
+ 'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
|
+ 'Referer': f"{self.base_url}/en/appointment-form"
|
|
|
|
|
+ }
|
|
|
|
|
+ resp = self._perform_request('POST', url, data=payload, headers=headers)
|
|
|
|
|
+ self._log(f"OTP step 2 finished (status {resp.status_code})")
|
|
|
|
|
+
|
|
|
|
|
+ def _peek_latest_otp(self, recipient: str) -> str:
|
|
|
|
|
+ """快速查看当前邮箱里已有的旧验证码,用于发码后比对排除旧邮件"""
|
|
|
|
|
+ try:
|
|
|
|
|
+ master_email = self.master_email if self.use_alias_email else recipient
|
|
|
|
|
+ c = VSCloudApi.Instance().fetch_mail_content_from_top(
|
|
|
|
|
+ email=master_email,
|
|
|
|
|
+ sender="Visametric",
|
|
|
|
|
+ recipient=recipient,
|
|
|
|
|
+ subject_keywords="",
|
|
|
|
|
+ body_keywords="",
|
|
|
|
|
+ top=1
|
|
|
|
|
+ )
|
|
|
if c:
|
|
if c:
|
|
|
- m = re.search(r'\b\d{6}\b', c)
|
|
|
|
|
|
|
+ m = re.search(r'Verification code.*?<h2[^>]*>\s*(\d{4,6})\s*</h2>', c, re.DOTALL | re.IGNORECASE)
|
|
|
if m:
|
|
if m:
|
|
|
- return m.group(0)
|
|
|
|
|
|
|
+ return m.group(1).strip()
|
|
|
|
|
+ m2 = re.search(r'\b\d{4,6}\b', c)
|
|
|
|
|
+ if m2:
|
|
|
|
|
+ return m2.group(0)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass
|
|
|
|
|
+ return ""
|
|
|
|
|
+
|
|
|
|
|
+ def _read_otp_email(self, recipient: str, send_time_utc: str = "", old_otp: str = "") -> str:
|
|
|
|
|
+ master_email = self.master_email if self.use_alias_email else recipient
|
|
|
|
|
+ sender = 'Visametric'
|
|
|
|
|
+ if not send_time_utc:
|
|
|
|
|
+ send_time_utc = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
+ self._log(f"Waiting for NEW OTP email... (recipient: '{recipient}', master: '{master_email}', sent after: {send_time_utc}, ignore old_otp='{old_otp}')")
|
|
|
|
|
+ for attempt in range(1, 13):
|
|
|
|
|
+ self._log(f"Polling OTP email (Attempt {attempt}/12)...")
|
|
|
|
|
+ try:
|
|
|
|
|
+ # 策略 1: 优先尝试带精准 sentDate(UTC) 时间戳过滤的 fetch 接口
|
|
|
|
|
+ c = None
|
|
|
|
|
+ try:
|
|
|
|
|
+ c = VSCloudApi.Instance().fetch_mail_content(
|
|
|
|
|
+ email=master_email,
|
|
|
|
|
+ sender=sender,
|
|
|
|
|
+ recipient=recipient,
|
|
|
|
|
+ subject_keywords="",
|
|
|
|
|
+ body_keywords="",
|
|
|
|
|
+ sent_date=send_time_utc,
|
|
|
|
|
+ expiry=300
|
|
|
|
|
+ )
|
|
|
|
|
+ except Exception as e_fetch:
|
|
|
|
|
+ self._log(f"Standard fetch check: {e_fetch}")
|
|
|
|
|
+
|
|
|
|
|
+ # 策略 2: 若 fetch 未立即返回,尝试 fetch-top
|
|
|
|
|
+ if not c:
|
|
|
|
|
+ c = VSCloudApi.Instance().fetch_mail_content_from_top(
|
|
|
|
|
+ email=master_email,
|
|
|
|
|
+ sender=sender,
|
|
|
|
|
+ recipient=recipient,
|
|
|
|
|
+ subject_keywords="",
|
|
|
|
|
+ body_keywords="",
|
|
|
|
|
+ top=1
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ if c:
|
|
|
|
|
+ cand_otp = ""
|
|
|
|
|
+ # 1. 精确提取 HTML 中的 Verification code (例如 <h2> 7029 </h2>)
|
|
|
|
|
+ m = re.search(r'Verification code.*?<h2[^>]*>\s*(\d{4,6})\s*</h2>', c, re.DOTALL | re.IGNORECASE)
|
|
|
|
|
+ if m:
|
|
|
|
|
+ cand_otp = m.group(1).strip()
|
|
|
|
|
+ else:
|
|
|
|
|
+ m2 = re.search(r'\b\d{4,6}\b', c)
|
|
|
|
|
+ if m2:
|
|
|
|
|
+ cand_otp = m2.group(0)
|
|
|
|
|
+
|
|
|
|
|
+ if cand_otp:
|
|
|
|
|
+ # 核心防抖:如果拿到的验证码与发信前捕获的历史旧验证码完全一致,说明新邮件尚未到达,继续等待!
|
|
|
|
|
+ if old_otp and cand_otp == old_otp:
|
|
|
|
|
+ self._log(f"Captured OTP '{cand_otp}' equals pre-send old_otp, still waiting for newly arrived email...")
|
|
|
|
|
+ else:
|
|
|
|
|
+ self._log(f"🎉 Successfully retrieved NEW OTP: {cand_otp}")
|
|
|
|
|
+ return cand_otp
|
|
|
|
|
+ else:
|
|
|
|
|
+ self._log(f"Email content received but no 4-6 digit OTP found. Snippet: {c[:100]}...")
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ self._log(f"Warning: Exception while polling mail: {e}")
|
|
|
time.sleep(5)
|
|
time.sleep(5)
|
|
|
|
|
+ self._log("❌ OTP retrieval timed out after 12 attempts (60s).")
|
|
|
raise NotFoundError("OTP timeout")
|
|
raise NotFoundError("OTP timeout")
|
|
|
|
|
|
|
|
- def _confirm_appointment(self, date, slot_data, user_inputs, otp, alias_email):
|
|
|
|
|
|
|
+ def _confirm_appointment(self, target_date: str, slot_data: Dict, user_inputs: Dict, otp: str, alias_email: str, cal_status: str = "0"):
|
|
|
url = f"{self.base_url}/en/personal/appointment/create"
|
|
url = f"{self.base_url}/en/personal/appointment/create"
|
|
|
def _get_dob(d):
|
|
def _get_dob(d):
|
|
|
try:
|
|
try:
|
|
@@ -406,44 +683,62 @@ class DePlugin(IVSPlg):
|
|
|
return datetime.now()
|
|
return datetime.now()
|
|
|
dob = _get_dob(user_inputs.get('birthday', ''))
|
|
dob = _get_dob(user_inputs.get('birthday', ''))
|
|
|
|
|
|
|
|
|
|
+ travel_dt_str = user_inputs.get('travel_date', '')[:10]
|
|
|
|
|
+ if travel_dt_str:
|
|
|
|
|
+ try:
|
|
|
|
|
+ travel_start = datetime.strptime(travel_dt_str, "%Y-%m-%d").strftime("%d-%m-%Y")
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ travel_start = datetime.now().strftime("%d-%m-%Y")
|
|
|
|
|
+ else:
|
|
|
|
|
+ travel_start = datetime.now().strftime("%d-%m-%Y")
|
|
|
|
|
+
|
|
|
|
|
+ passport_exp_str = user_inputs.get('passport_expiry_date', '')[:10]
|
|
|
|
|
+ if passport_exp_str:
|
|
|
|
|
+ try:
|
|
|
|
|
+ passport_exp = datetime.strptime(passport_exp_str, "%Y-%m-%d").strftime("%d-%m-%Y")
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ passport_exp = ""
|
|
|
|
|
+ else:
|
|
|
|
|
+ passport_exp = ""
|
|
|
|
|
+
|
|
|
payload = {
|
|
payload = {
|
|
|
"_token": self.csrf_token,
|
|
"_token": self.csrf_token,
|
|
|
- "country": str(self.free_config.get("consularid", "1")),
|
|
|
|
|
- "visitingcountry": str(self.free_config.get("consularid", "1")),
|
|
|
|
|
- "city": "6",
|
|
|
|
|
- "office": "1",
|
|
|
|
|
- "officetype": "1",
|
|
|
|
|
|
|
+ "country": str(self.consular_id),
|
|
|
|
|
+ "visitingcountry": str(self.consular_id),
|
|
|
|
|
+ "city": str(self.city_id),
|
|
|
|
|
+ "office": str(self.office_id),
|
|
|
|
|
+ "officetype": str(self.office_type),
|
|
|
"totalPerson": "1",
|
|
"totalPerson": "1",
|
|
|
"name1": user_inputs.get('first_name', '').upper(),
|
|
"name1": user_inputs.get('first_name', '').upper(),
|
|
|
"surname1": user_inputs.get('last_name', '').upper(),
|
|
"surname1": user_inputs.get('last_name', '').upper(),
|
|
|
- "nationality1": "2",
|
|
|
|
|
|
|
+ "nationality1": str(self.nationality),
|
|
|
"birthday1": str(dob.day),
|
|
"birthday1": str(dob.day),
|
|
|
"birthmonth1": str(dob.month),
|
|
"birthmonth1": str(dob.month),
|
|
|
"birthyear1": str(dob.year),
|
|
"birthyear1": str(dob.year),
|
|
|
- "passport1": user_inputs.get('passport_no'),
|
|
|
|
|
- "passportExpirationDate1": datetime.strptime(user_inputs.get('passport_expiry_date', '')[:10], "%Y-%m-%d").strftime("%d-%m-%Y"),
|
|
|
|
|
|
|
+ "passport1": user_inputs.get('passport_no', ''),
|
|
|
|
|
+ "passportExpirationDate1": passport_exp,
|
|
|
"email1": alias_email,
|
|
"email1": alias_email,
|
|
|
- "phone1": user_inputs.get('phone_no'),
|
|
|
|
|
|
|
+ "phone1": user_inputs.get('phone_no', ''),
|
|
|
"alternativephone1": "",
|
|
"alternativephone1": "",
|
|
|
"mailConfirmCode": otp,
|
|
"mailConfirmCode": otp,
|
|
|
- "ctval": slot_data['data_id'],
|
|
|
|
|
- "qtallvert": slot_data['data_all'],
|
|
|
|
|
- "oldofficetype": "1",
|
|
|
|
|
|
|
+ "ctval": slot_data.get('data_id', '') if cal_status != "0" else "",
|
|
|
|
|
+ "qtallvert": slot_data.get('data_all', '') if cal_status != "0" else "",
|
|
|
|
|
+ "oldofficetype": str(self.office_type),
|
|
|
"oldtotalperson": "1",
|
|
"oldtotalperson": "1",
|
|
|
"rePaymentControl": "0",
|
|
"rePaymentControl": "0",
|
|
|
- "view_set_app_country": "Schengen - Tourism/Family&Friend Visit/Transit Visa/Other Purposes",
|
|
|
|
|
- "view_set_app_office": "Dublin",
|
|
|
|
|
- "view_set_app_service_type": "NORMAL",
|
|
|
|
|
|
|
+ "view_set_app_country": self.app_country_view,
|
|
|
|
|
+ "view_set_app_office": self.app_office_view,
|
|
|
|
|
+ "view_set_app_service_type": self.app_service_type_view,
|
|
|
"cargoactive": "0",
|
|
"cargoactive": "0",
|
|
|
- "setnewcalendarstatus": "2",
|
|
|
|
|
|
|
+ "setnewcalendarstatus": str(cal_status),
|
|
|
"availableDaycontrol": "0",
|
|
"availableDaycontrol": "0",
|
|
|
- "travelStartDate": datetime.strptime(user_inputs.get('travel_date', '')[:10], "%Y-%m-%d").strftime("%d-%m-%Y"),
|
|
|
|
|
|
|
+ "travelStartDate": travel_start,
|
|
|
"personalapproveTerms": "1"
|
|
"personalapproveTerms": "1"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for i in range(2, 5):
|
|
for i in range(2, 5):
|
|
|
payload.update({
|
|
payload.update({
|
|
|
- f"name{i}": "", f"surname{i}": "", f"nationality{i}": "0", f"birthday{i}": "0", f"birthmonth{i}": "0", f"birthyear{i}": "0", f"passport{i}": "", f"passportExpirationDate{i}": "", f"email{i}": alias_email, f"phone{i}": user_inputs.get('phone_no'), f"alternativephone{i}": ""
|
|
|
|
|
|
|
+ f"name{i}": "", f"surname{i}": "", f"nationality{i}": "0", f"birthday{i}": "0", f"birthmonth{i}": "0", f"birthyear{i}": "0", f"passport{i}": "", f"passportExpirationDate{i}": "", f"email{i}": alias_email, f"phone{i}": user_inputs.get('phone_no', ''), f"alternativephone{i}": ""
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
headers = {'X-Requested-With': 'XMLHttpRequest'}
|
|
headers = {'X-Requested-With': 'XMLHttpRequest'}
|