MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / get_verification_code

Method get_verification_code

src/services/tempmail.py:121–222  ·  view source on GitHub ↗

从 Tempmail.lol 获取验证码 Args: email: 邮箱地址 email_id: 邮箱 token(如果不提供,从缓存中查找) timeout: 超时时间(秒) pattern: 验证码正则表达式 otp_sent_at: OTP 发送时间戳(Tempmail 服务暂不使用此参数) Returns: 验证码字符串,如果超时或未找到返回 None

(
        self,
        email: str,
        email_id: str = None,
        timeout: int = 120,
        pattern: str = OTP_CODE_PATTERN,
        otp_sent_at: Optional[float] = None,
    )

Source from the content-addressed store, hash-verified

119 raise EmailServiceError(f"创建 Tempmail.lol 邮箱失败: {e}")
120
121 def get_verification_code(
122 self,
123 email: str,
124 email_id: str = None,
125 timeout: int = 120,
126 pattern: str = OTP_CODE_PATTERN,
127 otp_sent_at: Optional[float] = None,
128 ) -> Optional[str]:
129 """
130 从 Tempmail.lol 获取验证码
131
132 Args:
133 email: 邮箱地址
134 email_id: 邮箱 token(如果不提供,从缓存中查找)
135 timeout: 超时时间(秒)
136 pattern: 验证码正则表达式
137 otp_sent_at: OTP 发送时间戳(Tempmail 服务暂不使用此参数)
138
139 Returns:
140 验证码字符串,如果超时或未找到返回 None
141 """
142 token = email_id
143 if not token:
144 # 从缓存中查找 token
145 if email in self._email_cache:
146 token = self._email_cache[email].get("token")
147 else:
148 logger.warning(f"未找到邮箱 {email} 的 token,无法获取验证码")
149 return None
150
151 if not token:
152 logger.warning(f"邮箱 {email} 没有 token,无法获取验证码")
153 return None
154
155 logger.info(f"正在等邮箱 {email} 的验证码,邮差应该在路上了...")
156
157 start_time = time.time()
158 seen_ids = set()
159
160 while time.time() - start_time < timeout:
161 try:
162 # 获取邮件列表
163 response = self.http_client.get(
164 f"{self.config['base_url']}/inbox",
165 params={"token": token},
166 headers={"Accept": "application/json"}
167 )
168
169 if response.status_code != 200:
170 time.sleep(3)
171 continue
172
173 data = response.json()
174
175 # 检查 inbox 是否过期
176 if data is None or (isinstance(data, dict) and not data):
177 logger.warning(f"邮箱 {email} 已过期")
178 return None

Callers

nothing calls this directly

Calls 7

setFunction · 0.85
warningMethod · 0.80
infoMethod · 0.80
sleepMethod · 0.80
getMethod · 0.45
jsonMethod · 0.45
update_statusMethod · 0.45

Tested by

no test coverage detected