root 3 هفته پیش
والد
کامیت
6cf86c119f
1فایلهای تغییر یافته به همراه11 افزوده شده و 6 حذف شده
  1. 11 6
      plugins/vfs_plugin.py

+ 11 - 6
plugins/vfs_plugin.py

@@ -372,6 +372,8 @@ class VfsPlugin(IVSPlg):
                 "captcha_api_key": cf_token 
             }
             
+            now_utc = datetime.utcnow()
+            sent_at = now_utc.strftime("%Y-%m-%d %H:%M:%S")
             self._log("Sending Login Request via Browser Fetch...")
             resp = self._perform_request("POST", url, headers=headers, json_data=data)
             resp_json = resp.json()
@@ -386,7 +388,7 @@ class VfsPlugin(IVSPlg):
                 self._log("Login requires OTP.")
                 # 注意:_submit_login_otp 内部也会调用 _refresh_turnstile_token
                 # 所以这里旧的 cf_token 其实用处不大,传过去也没事
-                otp = self._read_otp_email()
+                otp = self._read_otp_email(sent_at=sent_at)
                 self._submit_login_otp(cf_token, otp)
             
             else:
@@ -794,17 +796,18 @@ class VfsPlugin(IVSPlg):
         resp = self._perform_request("GET", url, headers=headers)
         return resp.json()            
 
-    def _read_otp_email(self, sender='donotreply at vfshelpline.com') -> str:
+    def _read_otp_email(self, sent_at='', sender='VFS Global') -> str:
         # 保持原样,这部分使用云API读取邮件,不依赖本地网络库
         master_email = "visafly666@gmail.com"
         recipient = self.config.account.username
         subject_keywords = "One Time Password"
         body_keywords = "OTP"
-        now_utc = datetime.utcnow()
-        formatted_utc_time = now_utc.strftime("%Y-%m-%d %H:%M:%S")
+        if not sent_at:
+            now_utc = datetime.utcnow()
+            sent_at = now_utc.strftime("%Y-%m-%d %H:%M:%S")
         self._log(f"Waiting for OTP email...")
         content_out = VSCloudApi.Instance().fetch_mail_content(
-            master_email, sender, recipient, subject_keywords, body_keywords, formatted_utc_time, 300
+            master_email, sender, recipient, subject_keywords, body_keywords, sent_at, 300
         )
         if content_out:
             match = re.search(r'\b\d{6}\b', content_out)
@@ -983,11 +986,13 @@ class VfsPlugin(IVSPlg):
         otp_enabled = sub_conf.get("isApplicantOTPEnabled", False)
         if otp_enabled:
             self._log("Applicant OTP Required.")
+            now_utc = datetime.utcnow()
+            sent_at = now_utc.strftime("%Y-%m-%d %H:%M:%S")
             if not self._applicant_otp_send(apt_config, final_urn):
                 raise BizLogicError(message='Applicant OTP send failed')
             
             # 复用之前的读邮件逻辑
-            otp_code = self._read_otp_email(sender='donotreply at vfsglobal.com')
+            otp_code = self._read_otp_email(sent_at=sent_at)
             if not self._applicant_otp_verify(apt_config, final_urn, otp_code):
                 raise BizLogicError(message='Applicant OTP verify failed')