fix(telegram_bot): Correct GPTMail API endpoint and authentication method
- Change API endpoint from `/api/mail/list` to `/api/generate-email` - Update HTTP method from POST to GET request - Replace `Authorization` header with `X-API-Key` for proper authentication - Remove unnecessary payload parameter from API request - Enhance response handling to extract and display generated test email - Add error message parsing from API response for better debugging - Improve test connection feedback to show actual generated email address
This commit is contained in:
@@ -4572,17 +4572,22 @@ class ProvisionerBot:
|
||||
return False, "没有配置 GPTMail API Key"
|
||||
|
||||
api_key = keys[0]
|
||||
url = f"{GPTMAIL_API_BASE}/api/mail/list"
|
||||
# 使用正确的 API 接口: /api/generate-email (GET 请求)
|
||||
url = f"{GPTMAIL_API_BASE}/api/generate-email"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
"X-API-Key": api_key, # 正确的请求头
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
payload = {"email": "test@test.com", "limit": 1}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=10)
|
||||
response = requests.get(url, headers=headers, timeout=10)
|
||||
|
||||
if response.status_code == 200:
|
||||
return True, "API 连接正常"
|
||||
data = response.json()
|
||||
if data.get("success"):
|
||||
email = data.get("data", {}).get("email", "")
|
||||
return True, f"生成测试邮箱: {email}"
|
||||
else:
|
||||
return False, data.get("error", "Unknown error")
|
||||
else:
|
||||
return False, f"HTTP {response.status_code}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user