feat: Introduce advanced TLS client with browser fingerprinting and new backend modules for API processing, authentication, mail, and ChatGPT registration.
This commit is contained in:
@@ -2,6 +2,7 @@ package mail
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
@@ -355,7 +356,13 @@ func (m *Client) GetEmails(email string, size int) ([]EmailItem, error) {
|
||||
|
||||
// WaitForCode 等待验证码邮件
|
||||
func (m *Client) WaitForCode(email string, timeout time.Duration) (string, error) {
|
||||
start := time.Now()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
return m.WaitForCodeWithContext(ctx, email)
|
||||
}
|
||||
|
||||
// WaitForCodeWithContext 等待验证码邮件(支持 context 取消)
|
||||
func (m *Client) WaitForCodeWithContext(ctx context.Context, email string) (string, error) {
|
||||
// 匹配6位数字验证码
|
||||
codeRegex := regexp.MustCompile(`\b(\d{6})\b`)
|
||||
// 专门匹配 OpenAI 验证码邮件标题格式: "Your ChatGPT code is 016547" 或 "OpenAI - Verify your email"
|
||||
@@ -381,7 +388,12 @@ func (m *Client) WaitForCode(email string, timeout time.Duration) (string, error
|
||||
}
|
||||
}
|
||||
|
||||
for time.Since(start) < timeout {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return "", fmt.Errorf("验证码获取超时")
|
||||
default:
|
||||
}
|
||||
emails, err := m.GetEmails(email, 10)
|
||||
if err == nil {
|
||||
for _, mail := range emails {
|
||||
@@ -435,10 +447,12 @@ func (m *Client) WaitForCode(email string, timeout time.Duration) (string, error
|
||||
}
|
||||
}
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return "", fmt.Errorf("验证码获取超时")
|
||||
case <-time.After(1 * time.Second):
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("验证码获取超时")
|
||||
}
|
||||
|
||||
// WaitForInviteLink 等待邀请邮件并提取链接
|
||||
@@ -520,11 +534,22 @@ func GetLatestEmailID(email string) int {
|
||||
// GetEmailOTPAfterID 获取指定邮件ID之后的OTP验证码
|
||||
// 基于 get_code.go 的实现,只获取 afterEmailID 之后的新邮件中的验证码
|
||||
func GetEmailOTPAfterID(email string, afterEmailID int, timeout time.Duration) (string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
return GetEmailOTPAfterIDWithContext(ctx, email, afterEmailID)
|
||||
}
|
||||
|
||||
// GetEmailOTPAfterIDWithContext 获取指定邮件ID之后的OTP验证码(支持 context 取消)
|
||||
func GetEmailOTPAfterIDWithContext(ctx context.Context, email string, afterEmailID int) (string, error) {
|
||||
client := NewClientForEmail(email)
|
||||
start := time.Now()
|
||||
codeRegex := regexp.MustCompile(`\b(\d{6})\b`)
|
||||
|
||||
for time.Since(start) < timeout {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return "", fmt.Errorf("验证码获取超时 (afterEmailID=%d)", afterEmailID)
|
||||
default:
|
||||
}
|
||||
emails, err := client.GetEmails(email, 5)
|
||||
if err == nil {
|
||||
for _, mail := range emails {
|
||||
@@ -554,8 +579,10 @@ func GetEmailOTPAfterID(email string, afterEmailID int, timeout time.Duration) (
|
||||
}
|
||||
}
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return "", fmt.Errorf("验证码获取超时 (afterEmailID=%d)", afterEmailID)
|
||||
case <-time.After(1 * time.Second):
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("验证码获取超时 (afterEmailID=%d)", afterEmailID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user