自动化验证 ChatGPT Plus 的军事身份优惠资格,实现一键点击验证链接的完整解决方案。
作者: dy安心大油条&cubeplus1+AI
当前版本: 1.0 (Webhook + Cloudflare Integration)
最后更新: 2025-12-31
📚 新用户? 建议先查看 📖 文档索引 了解完整的文档结构和推荐阅读路径
✅ 零外部邮箱 - 无需 Gmail、Outlook 等第三方邮箱
✅ 完全本地化 - 邮件处理全部在本地进行
✅ Cloudflare 原生 - 利用 Email Routing 和 Workers
✅ 实时处理 - 邮件到达即刻提取验证链接
✅ 可靠稳定 - 支持多种邮件接收方式
- ✅ Python 3.8+ 已安装
- ✅ 拥有自己的域名(DNS 指向 Cloudflare)
- ✅ Cloudflare 免费账户
- ✅ ChatGPT 账户
pip install flask requests{
"accessToken": "your_chatgpt_token_here",
"programId": "690415d58971e73ca187d8c9",
"email": {
"type": "webhook",
"api_url": "http://localhost:5000",
"email_address": "verify@yourdomain.com"
}
}python email_receiver.py输出应显示:Running on http://0.0.0.0:5000
cloudflared tunnel --url http://localhost:5000记录输出的 Tunnel URL(格式:https://xxx-yyy-zzz.trycloudflare.com)
- 进入 Cloudflare Dashboard
- 创建 Worker
email-handler - 复制下面的代码(见详细步骤)
- 配置环境变量
LOCAL_SERVER_URL=https://your-tunnel-url.trycloudflare.com/email
python main.py✅ 完成! 脚本会自动等待邮件并点击验证链接
python --version # 应为 3.8 或更新
pip --version # 应为 20.0 或更新
# 安装依赖
pip install flask requests访问 cloudflare.com/warp 或 GitHub 下载
验证安装:
cloudflared --versionpython email_receiver.py预期输出:
* Running on http://0.0.0.0:5000
* Debug mode: off
# 检查服务状态
curl http://localhost:5000/status
# 预期响应
{
"recent_emails": 0,
"status": "running",
"uptime": "active",
"verification_links": 0
}python test_email_receiver.py预期输出:
✓ 状态接口正常
✓ 邮件发送成功
✓ 验证链接已提取
✓ 邮件总数: 2
✓ 测试完成!
cloudflared tunnel --url http://localhost:5000首次运行:
- 点击提供的登录链接
- 选择您的域名
- 授权 Tunnel 访问
记录输出的 Tunnel URL:
https://xxx-yyy-zzz.trycloudflare.com
# 新终端测试
curl https://xxx-yyy-zzz.trycloudflare.com/status
# 应返回与本地相同的 JSON- 登录 Cloudflare Dashboard
- 选择您的域名
- Email → Email Routing → Enable Email Routing
- 添加目标邮箱(如
verify@yourdomain.com)
暂停,先创建 Worker(下一部分)
- Workers & Pages → Create application
- 命名为
email-handler - 复制以下代码到编辑器:
export default {
async email(message, env, ctx) {
console.log('📧 收到邮件:', message.from, '->', message.to);
try {
const rawEmail = await streamToString(message.raw);
const subject = message.headers.get('subject') || '';
const emailData = {
to: message.to,
from: message.from,
subject: subject,
text: rawEmail,
html: rawEmail
};
const url = env.LOCAL_SERVER_URL;
console.log('🔄 转发到:', url);
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(emailData)
});
console.log('✅ 转发成功:', response.status);
} catch (error) {
console.error('❌ 转发失败:', error);
}
},
async fetch(request, env, ctx) {
return new Response('Worker is running! ✅', { status: 200 });
}
};
async function streamToString(stream) {
const reader = stream.getReader();
const chunks = [];
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
}
const uint8Array = new Uint8Array(
chunks.reduce((acc, chunk) => acc + chunk.length, 0)
);
let offset = 0;
for (const chunk of chunks) {
uint8Array.set(chunk, offset);
offset += chunk.length;
}
return new TextDecoder('utf-8').decode(uint8Array);
}- 点击 Deploy
-
Worker 页面 → Settings → Variables
-
添加:
- LOCAL_SERVER_URL =
https://xxx-yyy-zzz.trycloudflare.com/email
⚠️ 重要: 必须加上/email后缀! - LOCAL_SERVER_URL =
-
Save and deploy
- Email → Email Routing → Routing rules
- 创建规则:
- Match:
verify@yourdomain.com - Action: Send to a Worker
- Worker: 选择
email-handler
- Match:
- 保存
✅ 配置完成!
{
// ChatGPT Access Token
// 获取方式:
// 1. 登录 https://chatgpt.com
// 2. 访问 https://chatgpt.com/api/auth/session
// 3. 复制 accessToken 字段值
"accessToken": "eyJhbGci...",
// SheerID Program ID(固定值)
"programId": "690415d58971e73ca187d8c9",
// 邮件配置
"email": {
// 类型:webhook 推荐!
// 其他:imap, cloudmail, mailpit
"type": "webhook",
// Flask 服务 URL(webhook 类型)
"api_url": "http://localhost:5000",
// 目标邮箱地址
// 必须与 Email Routing 配置一致
"email_address": "verify@yourdomain.com"
}
}firstName|lastName|branch|birthDate|dischargeDate
JOHN|SMITH|Army|1990-05-15|2023-06-01
JANE|DOE|Navy|1985-03-20|2022-08-15
branch 支持值:
| 值 | 含义 |
|---|---|
| Army | 陆军 |
| Navy | 海军 |
| Air Force | 空军 |
| Marine Corps | 海军陆战队 |
| Coast Guard | 海岸警卫队 |
| Space Force | 太空军 |
| Army National Guard | 陆军国民警卫队 |
| Army Reserve | 陆军预备役 |
| Navy Reserve | 海军预备役 |
| Air National Guard | 空军国民警卫队 |
| Air Force Reserve | 空军预备役 |
| Marine Corps Forces Reserve | 海军陆战队预备役 |
| Coast Guard Reserve | 海岸警卫队预备役 |
使用代理可以提高成功率、避免 IP 限制。代理是可选的,不配置也能正常运行。
- 创建
proxy.txt文件:
# 复制示例文件
copy proxy.example.txt proxy.txt
# 或手动创建
echo 192.168.1.100:1080:user:pass > proxy.txt- 添加代理(每行一个,支持多个格式):
# SOCKS5 认证代理(推荐)
192.168.1.100:1080:username:password
# HTTP 代理
192.168.1.101:8080
# 完整 URL 格式
socks5://user:pass@proxy.example.com:1080
http://proxy.example.com:8080- 运行程序,会显示:
[代理] 使用代理: 192.168.1.100:1080 (认证)
| 格式 | 示例 | 说明 |
|---|---|---|
| SOCKS5 认证 | ip:port:user:pass |
推荐,性能最好 |
| HTTP 无认证 | ip:port |
简单代理 |
| SOCKS5 URL | socks5://user:pass@ip:port |
完整连接字符串 |
| HTTP URL | http://ip:port |
HTTP 代理 URL |
删除或重命名 proxy.txt 即可:
del proxy.txt
# 或
ren proxy.txt proxy.txt.bak📖 详细配置: 查看 PROXY_SETUP.md 了解完整代理配置指南
python test_email_receiver.pycurl https://your-tunnel-url.trycloudflare.com/status发送邮件到 verify@yourdomain.com,检查本地服务:
curl http://localhost:5000/emails-
确保以下服务运行中:
- Flask:
python email_receiver.py - Tunnel:
cloudflared tunnel --url http://localhost:5000 - Worker: 已部署并配置
- Flask:
-
运行:
python main.py解决方案:
# 检查端口占用
netstat -ano | findstr :5000
# 重启 Flask
python email_receiver.py解决方案:
# 重启 Tunnel(旧 URL 可能过期)
# 停止当前 (Ctrl+C)
cloudflared tunnel --url http://localhost:5000
# 记录新 URL,更新 Worker 环境变量- 检查 Email Routing 规则是否正确
- 检查 Worker 日志(Real-time logs)
- 验证发送地址是否匹配
Q: 需要 Cloudflare DNS 吗?
A: 是的,域名 DNS 必须指向 Cloudflare
Q: accessToken 会过期吗?
A: 是的,有效期通常为几小时,过期需重新获取
Q: 支持批量验证吗?
A: 支持,编辑 data.txt 添加多行数据
Q: 能否固定 Tunnel URL?
A: Cloudflare 高级套餐支持自定义域名
"email": {
"type": "imap",
"host": "imap.gmail.com",
"port": 993,
"email": "your-email@gmail.com",
"password": "your-app-password"
}"email": {
"type": "mailpit",
"api_url": "http://localhost:8025",
"email_address": "verify@test.com"
}启动:docker-compose up -d
遇到问题?检查:
- ✅ 所有服务是否运行
- ✅ 配置文件格式是否正确
- ✅ accessToken 是否过期
- ✅ Tunnel URL 是否有效
- ✅ Worker 日志是否有错误
MIT License - 仅供学习使用