mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-05-06 20:02:51 +08:00
feat(pay): 支付跳转功能
- 账号管理:补充订阅状态管理、TeamManager上传说明 - 新增「支付升级」功能模块描述 - 系统设置:补充 CPA配置和 TeamManager配置项
This commit is contained in:
28
README.md
28
README.md
@@ -40,12 +40,21 @@
|
||||
- 单个账号导出为独立 `.json` 文件
|
||||
- 多个账号打包为 `.zip`,每个账号一个独立文件
|
||||
- CPA 上传(Codex Protocol API,直连不走代理)
|
||||
- 订阅状态管理(手动标记 / 自动检测 plus/team)
|
||||
- Team Manager 上传(直连不走代理)
|
||||
|
||||
- **支付升级**
|
||||
- 为账号生成 ChatGPT Plus 或 Team 订阅支付链接
|
||||
- 后端命令行以无痕模式自动打开 Chrome/Edge
|
||||
- Team 套餐支持自定义工作区名称、座位数、计费周期
|
||||
|
||||
- **系统设置**
|
||||
- 代理配置(静态 + 动态)
|
||||
- Outlook OAuth 参数
|
||||
- 注册参数(超时、重试、密码长度等)
|
||||
- 验证码等待配置
|
||||
- CPA 上传配置
|
||||
- Team Manager 配置(API URL + API Key)
|
||||
- 数据库管理(备份、清理)
|
||||
|
||||
## 快速开始
|
||||
@@ -101,7 +110,7 @@ codex-register-v2/
|
||||
├── build.sh # Linux/macOS 打包脚本
|
||||
├── src/
|
||||
│ ├── config/ # 配置管理(Pydantic Settings)
|
||||
│ ├── core/ # 核心功能(注册引擎、HTTP 客户端、CPA 上传)
|
||||
│ ├── core/ # 核心功能(注册引擎、HTTP 客户端、CPA 上传、支付、TM 上传)
|
||||
│ ├── database/ # 数据库(SQLAlchemy + SQLite)
|
||||
│ ├── services/ # 邮箱服务实现
|
||||
│ └── web/ # FastAPI Web 应用
|
||||
@@ -165,6 +174,17 @@ codex-register-v2/
|
||||
| POST | `/api/accounts/{id}/upload-cpa` | 上传到 CPA |
|
||||
| POST | `/api/accounts/batch-upload-cpa` | 批量上传到 CPA |
|
||||
|
||||
### 支付升级
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| POST | `/api/payment/generate-link` | 生成 Plus/Team 支付链接 |
|
||||
| POST | `/api/payment/open-incognito` | 后端无痕模式打开浏览器 |
|
||||
| POST | `/api/payment/accounts/{id}/mark-subscription` | 手动标记订阅类型 |
|
||||
| POST | `/api/payment/accounts/batch-check-subscription` | 批量检测订阅状态 |
|
||||
| POST | `/api/payment/accounts/{id}/upload-tm` | 上传单账号到 Team Manager |
|
||||
| POST | `/api/payment/accounts/batch-upload-tm` | 批量上传到 Team Manager |
|
||||
|
||||
### 邮箱服务
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
@@ -186,6 +206,8 @@ codex-register-v2/
|
||||
| POST | `/api/settings/dynamic-proxy` | 更新动态代理设置 |
|
||||
| POST | `/api/settings/cpa` | 更新 CPA 设置 |
|
||||
| POST | `/api/settings/cpa/test` | 测试 CPA 连接 |
|
||||
| GET/POST | `/api/settings/team-manager` | Team Manager 设置 |
|
||||
| POST | `/api/settings/team-manager/test` | 测试 Team Manager 连接 |
|
||||
| GET | `/api/settings/database` | 数据库信息 |
|
||||
|
||||
### WebSocket
|
||||
@@ -254,6 +276,10 @@ docker-compose build --no-cache
|
||||
- 代理设置优先级:动态代理 > 代理列表(随机) > 静态默认代理
|
||||
- 注册时自动随机生成用户名和生日(年龄范围 18-45 岁)
|
||||
- CPA 上传始终直连,不经过代理
|
||||
- Team Manager 上传始终直连,不经过代理
|
||||
- 支付链接生成使用账号 access_token 鉴权,走全局代理配置
|
||||
- 无痕浏览器依次尝试 Chrome、Edge,未找到时返回失败提示
|
||||
- 订阅状态自动检测调用 `chatgpt.com/backend-api/me`,走全局代理
|
||||
- 批量注册并发数上限为 50,线程池大小已相应调整
|
||||
|
||||
## License
|
||||
|
||||
@@ -294,6 +294,27 @@ SETTING_DEFINITIONS: Dict[str, SettingDefinition] = {
|
||||
is_secret=True
|
||||
),
|
||||
|
||||
# Team Manager 配置
|
||||
"tm_enabled": SettingDefinition(
|
||||
db_key="tm.enabled",
|
||||
default_value=False,
|
||||
category=SettingCategory.GENERAL,
|
||||
description="是否启用 Team Manager 上传"
|
||||
),
|
||||
"tm_api_url": SettingDefinition(
|
||||
db_key="tm.api_url",
|
||||
default_value="",
|
||||
category=SettingCategory.GENERAL,
|
||||
description="Team Manager API 地址"
|
||||
),
|
||||
"tm_api_key": SettingDefinition(
|
||||
db_key="tm.api_key",
|
||||
default_value="",
|
||||
category=SettingCategory.GENERAL,
|
||||
description="Team Manager API Key",
|
||||
is_secret=True
|
||||
),
|
||||
|
||||
# CPA 上传配置
|
||||
"cpa_enabled": SettingDefinition(
|
||||
db_key="cpa.enabled",
|
||||
@@ -375,6 +396,7 @@ SETTING_TYPES: Dict[str, Type] = {
|
||||
"email_service_priority": dict,
|
||||
"tempmail_timeout": int,
|
||||
"tempmail_max_retries": int,
|
||||
"tm_enabled": bool,
|
||||
"cpa_enabled": bool,
|
||||
"email_code_timeout": int,
|
||||
"email_code_poll_interval": int,
|
||||
@@ -613,6 +635,11 @@ class Settings(BaseModel):
|
||||
# 安全配置
|
||||
encryption_key: SecretStr = SecretStr("your-encryption-key-change-in-production")
|
||||
|
||||
# Team Manager 配置
|
||||
tm_enabled: bool = False
|
||||
tm_api_url: str = ""
|
||||
tm_api_key: Optional[SecretStr] = None
|
||||
|
||||
# CPA 上传配置
|
||||
cpa_enabled: bool = False
|
||||
cpa_api_url: str = ""
|
||||
|
||||
172
src/core/payment.py
Normal file
172
src/core/payment.py
Normal file
@@ -0,0 +1,172 @@
|
||||
"""
|
||||
支付核心逻辑 — 生成 Plus/Team 支付链接、无痕打开浏览器、检测订阅状态
|
||||
"""
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
from curl_cffi import requests as cffi_requests
|
||||
|
||||
from ..database.models import Account
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PAYMENT_CHECKOUT_URL = "https://chatgpt.com/backend-api/payments/checkout"
|
||||
TEAM_CHECKOUT_BASE_URL = "https://chatgpt.com/checkout/openai_llc/"
|
||||
|
||||
|
||||
def _build_proxies(proxy: Optional[str]) -> Optional[dict]:
|
||||
if proxy:
|
||||
return {"http": proxy, "https": proxy}
|
||||
return None
|
||||
|
||||
|
||||
def generate_plus_link(account: Account, proxy: Optional[str] = None) -> str:
|
||||
"""生成 Plus 支付链接"""
|
||||
if not account.access_token:
|
||||
raise ValueError("账号缺少 access_token")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {account.access_token}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
payload = {
|
||||
"plan_type": "plus",
|
||||
"checkout_ui_mode": "hosted",
|
||||
"cancel_url": "https://chatgpt.com/",
|
||||
"success_url": "https://chatgpt.com/",
|
||||
}
|
||||
|
||||
resp = cffi_requests.post(
|
||||
PAYMENT_CHECKOUT_URL,
|
||||
headers=headers,
|
||||
json=payload,
|
||||
proxies=_build_proxies(proxy),
|
||||
timeout=30,
|
||||
impersonate="chrome110",
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
if "url" in data:
|
||||
return data["url"]
|
||||
raise ValueError(data.get("detail", "API 未返回支付链接"))
|
||||
|
||||
|
||||
def generate_team_link(
|
||||
account: Account,
|
||||
workspace_name: str = "MyTeam",
|
||||
price_interval: str = "month",
|
||||
seat_quantity: int = 5,
|
||||
proxy: Optional[str] = None,
|
||||
) -> str:
|
||||
"""生成 Team 支付链接"""
|
||||
if not account.access_token:
|
||||
raise ValueError("账号缺少 access_token")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {account.access_token}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
payload = {
|
||||
"plan_name": "chatgptteamplan",
|
||||
"team_plan_data": {
|
||||
"workspace_name": workspace_name,
|
||||
"price_interval": price_interval,
|
||||
"seat_quantity": seat_quantity,
|
||||
},
|
||||
"promo_campaign": {
|
||||
"promo_campaign_id": "team-1-month-free",
|
||||
"is_coupon_from_query_param": True,
|
||||
},
|
||||
"checkout_ui_mode": "custom",
|
||||
}
|
||||
|
||||
resp = cffi_requests.post(
|
||||
PAYMENT_CHECKOUT_URL,
|
||||
headers=headers,
|
||||
json=payload,
|
||||
proxies=_build_proxies(proxy),
|
||||
timeout=30,
|
||||
impersonate="chrome110",
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
if "checkout_session_id" in data:
|
||||
return TEAM_CHECKOUT_BASE_URL + data["checkout_session_id"]
|
||||
raise ValueError(data.get("detail", "API 未返回 checkout_session_id"))
|
||||
|
||||
|
||||
def open_url_incognito(url: str) -> bool:
|
||||
"""调用本机浏览器以无痕模式打开 URL"""
|
||||
platform = sys.platform
|
||||
try:
|
||||
if platform == "win32":
|
||||
# 依次尝试 Chrome、Edge
|
||||
for browser, flag in [("chrome", "--incognito"), ("msedge", "--inprivate")]:
|
||||
try:
|
||||
subprocess.Popen(
|
||||
f'start {browser} {flag} "{url}"',
|
||||
shell=True,
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
elif platform == "darwin":
|
||||
subprocess.Popen(
|
||||
["open", "-a", "Google Chrome", "--args", "--incognito", url]
|
||||
)
|
||||
return True
|
||||
else:
|
||||
for binary in ["google-chrome", "chromium-browser", "chromium"]:
|
||||
try:
|
||||
subprocess.Popen([binary, "--incognito", url])
|
||||
return True
|
||||
except FileNotFoundError:
|
||||
continue
|
||||
except Exception as e:
|
||||
logger.warning(f"无痕打开浏览器失败: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def check_subscription_status(account: Account, proxy: Optional[str] = None) -> str:
|
||||
"""
|
||||
检测账号当前订阅状态。
|
||||
|
||||
Returns:
|
||||
'free' / 'plus' / 'team'
|
||||
"""
|
||||
if not account.access_token:
|
||||
raise ValueError("账号缺少 access_token")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {account.access_token}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
resp = cffi_requests.get(
|
||||
"https://chatgpt.com/backend-api/me",
|
||||
headers=headers,
|
||||
proxies=_build_proxies(proxy),
|
||||
timeout=20,
|
||||
impersonate="chrome110",
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
|
||||
# 解析订阅类型
|
||||
plan = data.get("plan_type") or ""
|
||||
if "team" in plan.lower():
|
||||
return "team"
|
||||
if "plus" in plan.lower():
|
||||
return "plus"
|
||||
|
||||
# 尝试从 orgs 或 workspace 信息判断
|
||||
orgs = data.get("orgs", {}).get("data", [])
|
||||
for org in orgs:
|
||||
settings_ = org.get("settings", {})
|
||||
if settings_.get("workspace_plan_type") in ("team", "enterprise"):
|
||||
return "team"
|
||||
|
||||
return "free"
|
||||
158
src/core/team_manager.py
Normal file
158
src/core/team_manager.py
Normal file
@@ -0,0 +1,158 @@
|
||||
"""
|
||||
Team Manager 上传功能
|
||||
参照 CPA 上传模式,直连不走代理
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import List, Tuple
|
||||
from datetime import datetime
|
||||
|
||||
from curl_cffi import requests as cffi_requests
|
||||
|
||||
from ..database.session import get_db
|
||||
from ..database.models import Account
|
||||
from ..config.settings import get_settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def upload_to_team_manager(
|
||||
account: Account,
|
||||
api_url: str,
|
||||
api_key: str,
|
||||
) -> Tuple[bool, str]:
|
||||
"""
|
||||
上传单账号到 Team Manager(直连,不走代理)
|
||||
|
||||
Returns:
|
||||
(成功标志, 消息)
|
||||
"""
|
||||
if not api_url:
|
||||
return False, "Team Manager API URL 未配置"
|
||||
if not api_key:
|
||||
return False, "Team Manager API Key 未配置"
|
||||
if not account.access_token:
|
||||
return False, "账号缺少 access_token"
|
||||
|
||||
url = api_url.rstrip("/") + "/api/accounts/import"
|
||||
headers = {
|
||||
"X-API-Key": api_key,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
payload = {
|
||||
"import_type": "single",
|
||||
"email": account.email,
|
||||
"access_token": account.access_token or "",
|
||||
"session_token": account.session_token or "",
|
||||
"refresh_token": account.refresh_token or "",
|
||||
"client_id": account.client_id or "",
|
||||
}
|
||||
|
||||
try:
|
||||
resp = cffi_requests.post(
|
||||
url,
|
||||
headers=headers,
|
||||
json=payload,
|
||||
proxies=None,
|
||||
timeout=30,
|
||||
impersonate="chrome110",
|
||||
)
|
||||
if resp.status_code in (200, 201):
|
||||
return True, "上传成功"
|
||||
error_msg = f"上传失败: HTTP {resp.status_code}"
|
||||
try:
|
||||
detail = resp.json()
|
||||
if isinstance(detail, dict):
|
||||
error_msg = detail.get("message", error_msg)
|
||||
except Exception:
|
||||
error_msg = f"{error_msg} - {resp.text[:200]}"
|
||||
return False, error_msg
|
||||
except Exception as e:
|
||||
logger.error(f"Team Manager 上传异常: {e}")
|
||||
return False, f"上传异常: {str(e)}"
|
||||
|
||||
|
||||
def batch_upload_to_team_manager(
|
||||
account_ids: List[int],
|
||||
api_url: str,
|
||||
api_key: str,
|
||||
) -> dict:
|
||||
"""
|
||||
批量上传账号到 Team Manager
|
||||
|
||||
Returns:
|
||||
包含成功/失败统计和详情的字典
|
||||
"""
|
||||
results = {
|
||||
"success_count": 0,
|
||||
"failed_count": 0,
|
||||
"skipped_count": 0,
|
||||
"details": [],
|
||||
}
|
||||
|
||||
with get_db() as db:
|
||||
for account_id in account_ids:
|
||||
account = db.query(Account).filter(Account.id == account_id).first()
|
||||
if not account:
|
||||
results["failed_count"] += 1
|
||||
results["details"].append(
|
||||
{"id": account_id, "email": None, "success": False, "error": "账号不存在"}
|
||||
)
|
||||
continue
|
||||
|
||||
if not account.access_token:
|
||||
results["skipped_count"] += 1
|
||||
results["details"].append(
|
||||
{"id": account_id, "email": account.email, "success": False, "error": "缺少 Token"}
|
||||
)
|
||||
continue
|
||||
|
||||
success, message = upload_to_team_manager(account, api_url, api_key)
|
||||
if success:
|
||||
results["success_count"] += 1
|
||||
results["details"].append(
|
||||
{"id": account_id, "email": account.email, "success": True, "message": message}
|
||||
)
|
||||
else:
|
||||
results["failed_count"] += 1
|
||||
results["details"].append(
|
||||
{"id": account_id, "email": account.email, "success": False, "error": message}
|
||||
)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def test_team_manager_connection(api_url: str, api_key: str) -> Tuple[bool, str]:
|
||||
"""
|
||||
测试 Team Manager 连接(直连)
|
||||
|
||||
Returns:
|
||||
(成功标志, 消息)
|
||||
"""
|
||||
if not api_url:
|
||||
return False, "API URL 不能为空"
|
||||
if not api_key:
|
||||
return False, "API Key 不能为空"
|
||||
|
||||
url = api_url.rstrip("/") + "/api/accounts/import"
|
||||
headers = {"X-API-Key": api_key}
|
||||
|
||||
try:
|
||||
resp = cffi_requests.options(
|
||||
url,
|
||||
headers=headers,
|
||||
proxies=None,
|
||||
timeout=10,
|
||||
impersonate="chrome110",
|
||||
)
|
||||
if resp.status_code in (200, 204, 401, 403, 405):
|
||||
if resp.status_code == 401:
|
||||
return False, "连接成功,但 API Key 无效"
|
||||
return True, "Team Manager 连接测试成功"
|
||||
return False, f"服务器返回异常状态码: {resp.status_code}"
|
||||
except cffi_requests.exceptions.ConnectionError as e:
|
||||
return False, f"无法连接到服务器: {str(e)}"
|
||||
except cffi_requests.exceptions.Timeout:
|
||||
return False, "连接超时,请检查网络配置"
|
||||
except Exception as e:
|
||||
return False, f"连接测试失败: {str(e)}"
|
||||
@@ -53,6 +53,8 @@ class Account(Base):
|
||||
cpa_uploaded = Column(Boolean, default=False) # 是否已上传到 CPA
|
||||
cpa_uploaded_at = Column(DateTime) # 上传时间
|
||||
source = Column(String(20), default='register') # 'register' 或 'login',区分账号来源
|
||||
subscription_type = Column(String(20)) # None / 'plus' / 'team'
|
||||
subscription_at = Column(DateTime) # 订阅开通时间
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
@@ -74,6 +76,8 @@ class Account(Base):
|
||||
'cpa_uploaded': self.cpa_uploaded,
|
||||
'cpa_uploaded_at': self.cpa_uploaded_at.isoformat() if self.cpa_uploaded_at else None,
|
||||
'source': self.source,
|
||||
'subscription_type': self.subscription_type,
|
||||
'subscription_at': self.subscription_at.isoformat() if self.subscription_at else None,
|
||||
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||
}
|
||||
|
||||
@@ -95,6 +95,8 @@ class DatabaseSessionManager:
|
||||
("accounts", "cpa_uploaded", "BOOLEAN DEFAULT 0"),
|
||||
("accounts", "cpa_uploaded_at", "DATETIME"),
|
||||
("accounts", "source", "VARCHAR(20) DEFAULT 'register'"),
|
||||
("accounts", "subscription_type", "VARCHAR(20)"),
|
||||
("accounts", "subscription_at", "DATETIME"),
|
||||
]
|
||||
|
||||
with self.engine.connect() as conn:
|
||||
|
||||
@@ -98,6 +98,11 @@ def create_app() -> FastAPI:
|
||||
"""设置页面"""
|
||||
return templates.TemplateResponse("settings.html", {"request": request})
|
||||
|
||||
@app.get("/payment", response_class=HTMLResponse)
|
||||
async def payment_page(request: Request):
|
||||
"""支付页面"""
|
||||
return templates.TemplateResponse("payment.html", {"request": request})
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""应用启动事件"""
|
||||
|
||||
@@ -8,6 +8,7 @@ from .accounts import router as accounts_router
|
||||
from .registration import router as registration_router
|
||||
from .settings import router as settings_router
|
||||
from .email_services import router as email_services_router
|
||||
from .payment import router as payment_router
|
||||
|
||||
api_router = APIRouter()
|
||||
|
||||
@@ -16,3 +17,4 @@ api_router.include_router(accounts_router, prefix="/accounts", tags=["accounts"]
|
||||
api_router.include_router(registration_router, prefix="/registration", tags=["registration"])
|
||||
api_router.include_router(settings_router, prefix="/settings", tags=["settings"])
|
||||
api_router.include_router(email_services_router, prefix="/email-services", tags=["email-services"])
|
||||
api_router.include_router(payment_router, prefix="/payment", tags=["payment"])
|
||||
|
||||
205
src/web/routes/payment.py
Normal file
205
src/web/routes/payment.py
Normal file
@@ -0,0 +1,205 @@
|
||||
"""
|
||||
支付相关 API 路由
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ...database.session import get_db
|
||||
from ...database.models import Account
|
||||
from ...config.settings import get_settings
|
||||
from ...core.payment import (
|
||||
generate_plus_link,
|
||||
generate_team_link,
|
||||
open_url_incognito,
|
||||
check_subscription_status,
|
||||
)
|
||||
from ...core.team_manager import (
|
||||
upload_to_team_manager,
|
||||
batch_upload_to_team_manager,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ============== Pydantic Models ==============
|
||||
|
||||
class GenerateLinkRequest(BaseModel):
|
||||
account_id: int
|
||||
plan_type: str # 'plus' or 'team'
|
||||
workspace_name: str = "MyTeam"
|
||||
price_interval: str = "month"
|
||||
seat_quantity: int = 5
|
||||
proxy: Optional[str] = None
|
||||
auto_open: bool = False # 生成后是否自动无痕打开
|
||||
|
||||
|
||||
class OpenIncognitoRequest(BaseModel):
|
||||
url: str
|
||||
|
||||
|
||||
class MarkSubscriptionRequest(BaseModel):
|
||||
subscription_type: str # 'free' / 'plus' / 'team'
|
||||
|
||||
|
||||
class BatchCheckSubscriptionRequest(BaseModel):
|
||||
ids: List[int]
|
||||
proxy: Optional[str] = None
|
||||
|
||||
|
||||
class UploadTMRequest(BaseModel):
|
||||
proxy: Optional[str] = None # 保留,TM 上传不走代理
|
||||
|
||||
|
||||
class BatchUploadTMRequest(BaseModel):
|
||||
ids: List[int]
|
||||
|
||||
|
||||
# ============== 支付链接生成 ==============
|
||||
|
||||
@router.post("/generate-link")
|
||||
def generate_payment_link(request: GenerateLinkRequest):
|
||||
"""生成 Plus 或 Team 支付链接,可选自动无痕打开"""
|
||||
with get_db() as db:
|
||||
account = db.query(Account).filter(Account.id == request.account_id).first()
|
||||
if not account:
|
||||
raise HTTPException(status_code=404, detail="账号不存在")
|
||||
|
||||
proxy = request.proxy or get_settings().proxy_url
|
||||
|
||||
try:
|
||||
if request.plan_type == "plus":
|
||||
link = generate_plus_link(account, proxy)
|
||||
elif request.plan_type == "team":
|
||||
link = generate_team_link(
|
||||
account,
|
||||
workspace_name=request.workspace_name,
|
||||
price_interval=request.price_interval,
|
||||
seat_quantity=request.seat_quantity,
|
||||
proxy=proxy,
|
||||
)
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="plan_type 必须为 plus 或 team")
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error(f"生成支付链接失败: {e}")
|
||||
raise HTTPException(status_code=500, detail=f"生成链接失败: {str(e)}")
|
||||
|
||||
opened = False
|
||||
if request.auto_open and link:
|
||||
opened = open_url_incognito(link)
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"link": link,
|
||||
"plan_type": request.plan_type,
|
||||
"auto_opened": opened,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/open-incognito")
|
||||
def open_browser_incognito(request: OpenIncognitoRequest):
|
||||
"""后端命令行以无痕模式打开指定 URL"""
|
||||
if not request.url:
|
||||
raise HTTPException(status_code=400, detail="URL 不能为空")
|
||||
success = open_url_incognito(request.url)
|
||||
if success:
|
||||
return {"success": True, "message": "已在无痕模式打开浏览器"}
|
||||
return {"success": False, "message": "未找到可用的 Chrome/Edge,请手动复制链接"}
|
||||
|
||||
|
||||
# ============== 订阅状态 ==============
|
||||
|
||||
@router.post("/accounts/{account_id}/mark-subscription")
|
||||
def mark_subscription(account_id: int, request: MarkSubscriptionRequest):
|
||||
"""手动标记账号订阅类型"""
|
||||
allowed = ("free", "plus", "team")
|
||||
if request.subscription_type not in allowed:
|
||||
raise HTTPException(status_code=400, detail=f"subscription_type 必须为 {allowed}")
|
||||
|
||||
with get_db() as db:
|
||||
account = db.query(Account).filter(Account.id == account_id).first()
|
||||
if not account:
|
||||
raise HTTPException(status_code=404, detail="账号不存在")
|
||||
|
||||
account.subscription_type = None if request.subscription_type == "free" else request.subscription_type
|
||||
account.subscription_at = datetime.utcnow() if request.subscription_type != "free" else None
|
||||
db.commit()
|
||||
|
||||
return {"success": True, "subscription_type": request.subscription_type}
|
||||
|
||||
|
||||
@router.post("/accounts/batch-check-subscription")
|
||||
def batch_check_subscription(request: BatchCheckSubscriptionRequest):
|
||||
"""批量检测账号订阅状态"""
|
||||
proxy = request.proxy or get_settings().proxy_url
|
||||
|
||||
results = {"success_count": 0, "failed_count": 0, "details": []}
|
||||
|
||||
with get_db() as db:
|
||||
for account_id in request.ids:
|
||||
account = db.query(Account).filter(Account.id == account_id).first()
|
||||
if not account:
|
||||
results["failed_count"] += 1
|
||||
results["details"].append(
|
||||
{"id": account_id, "email": None, "success": False, "error": "账号不存在"}
|
||||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
status = check_subscription_status(account, proxy)
|
||||
account.subscription_type = None if status == "free" else status
|
||||
account.subscription_at = datetime.utcnow() if status != "free" else account.subscription_at
|
||||
db.commit()
|
||||
results["success_count"] += 1
|
||||
results["details"].append(
|
||||
{"id": account_id, "email": account.email, "success": True, "subscription_type": status}
|
||||
)
|
||||
except Exception as e:
|
||||
results["failed_count"] += 1
|
||||
results["details"].append(
|
||||
{"id": account_id, "email": account.email, "success": False, "error": str(e)}
|
||||
)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
# ============== Team Manager 上传 ==============
|
||||
|
||||
@router.post("/accounts/{account_id}/upload-tm")
|
||||
def upload_account_tm(account_id: int, request: UploadTMRequest = None):
|
||||
"""上传单账号到 Team Manager"""
|
||||
settings = get_settings()
|
||||
if not settings.tm_enabled:
|
||||
raise HTTPException(status_code=400, detail="Team Manager 上传未启用")
|
||||
|
||||
api_url = settings.tm_api_url
|
||||
api_key = settings.tm_api_key.get_secret_value() if settings.tm_api_key else ""
|
||||
|
||||
with get_db() as db:
|
||||
account = db.query(Account).filter(Account.id == account_id).first()
|
||||
if not account:
|
||||
raise HTTPException(status_code=404, detail="账号不存在")
|
||||
success, message = upload_to_team_manager(account, api_url, api_key)
|
||||
|
||||
return {"success": success, "message": message}
|
||||
|
||||
|
||||
@router.post("/accounts/batch-upload-tm")
|
||||
def batch_upload_tm(request: BatchUploadTMRequest):
|
||||
"""批量上传账号到 Team Manager"""
|
||||
settings = get_settings()
|
||||
if not settings.tm_enabled:
|
||||
raise HTTPException(status_code=400, detail="Team Manager 上传未启用")
|
||||
|
||||
api_url = settings.tm_api_url
|
||||
api_key = settings.tm_api_key.get_secret_value() if settings.tm_api_key else ""
|
||||
|
||||
results = batch_upload_to_team_manager(request.ids, api_url, api_key)
|
||||
return results
|
||||
@@ -858,3 +858,59 @@ async def update_outlook_settings(request: OutlookSettings):
|
||||
update_settings(**update_dict)
|
||||
|
||||
return {"success": True, "message": "Outlook 设置已更新"}
|
||||
|
||||
|
||||
# ============== Team Manager 设置 ==============
|
||||
|
||||
class TeamManagerSettings(BaseModel):
|
||||
"""Team Manager 设置"""
|
||||
enabled: bool = False
|
||||
api_url: str = ""
|
||||
api_key: str = ""
|
||||
|
||||
|
||||
class TeamManagerTestRequest(BaseModel):
|
||||
"""Team Manager 测试请求"""
|
||||
api_url: str
|
||||
api_key: str
|
||||
|
||||
|
||||
@router.get("/team-manager")
|
||||
async def get_team_manager_settings():
|
||||
"""获取 Team Manager 设置"""
|
||||
settings = get_settings()
|
||||
return {
|
||||
"enabled": settings.tm_enabled,
|
||||
"api_url": settings.tm_api_url,
|
||||
"has_api_key": bool(settings.tm_api_key and settings.tm_api_key.get_secret_value()),
|
||||
}
|
||||
|
||||
|
||||
@router.post("/team-manager")
|
||||
async def update_team_manager_settings(request: TeamManagerSettings):
|
||||
"""更新 Team Manager 设置"""
|
||||
update_dict = {
|
||||
"tm_enabled": request.enabled,
|
||||
"tm_api_url": request.api_url,
|
||||
}
|
||||
if request.api_key:
|
||||
update_dict["tm_api_key"] = request.api_key
|
||||
update_settings(**update_dict)
|
||||
return {"success": True, "message": "Team Manager 设置已更新"}
|
||||
|
||||
|
||||
@router.post("/team-manager/test")
|
||||
async def test_team_manager_connection(request: TeamManagerTestRequest):
|
||||
"""测试 Team Manager 连接"""
|
||||
from ...core.team_manager import test_team_manager_connection as do_test
|
||||
|
||||
settings = get_settings()
|
||||
api_key = request.api_key
|
||||
if api_key == 'use_saved_key' or not api_key:
|
||||
if settings.tm_api_key:
|
||||
api_key = settings.tm_api_key.get_secret_value()
|
||||
else:
|
||||
return {"success": False, "message": "未配置 API Key"}
|
||||
|
||||
success, message = do_test(request.api_url, api_key)
|
||||
return {"success": success, "message": message}
|
||||
|
||||
@@ -24,6 +24,8 @@ const elements = {
|
||||
batchRefreshBtn: document.getElementById('batch-refresh-btn'),
|
||||
batchValidateBtn: document.getElementById('batch-validate-btn'),
|
||||
batchUploadCpaBtn: document.getElementById('batch-upload-cpa-btn'),
|
||||
batchCheckSubBtn: document.getElementById('batch-check-sub-btn'),
|
||||
batchUploadTmBtn: document.getElementById('batch-upload-tm-btn'),
|
||||
batchDeleteBtn: document.getElementById('batch-delete-btn'),
|
||||
exportBtn: document.getElementById('export-btn'),
|
||||
exportMenu: document.getElementById('export-menu'),
|
||||
@@ -88,6 +90,12 @@ function initEventListeners() {
|
||||
// 批量上传CPA
|
||||
elements.batchUploadCpaBtn.addEventListener('click', handleBatchUploadCpa);
|
||||
|
||||
// 批量检测订阅
|
||||
elements.batchCheckSubBtn.addEventListener('click', handleBatchCheckSubscription);
|
||||
|
||||
// 批量上传TM
|
||||
elements.batchUploadTmBtn.addEventListener('click', handleBatchUploadTm);
|
||||
|
||||
// 批量删除
|
||||
elements.batchDeleteBtn.addEventListener('click', handleBatchDelete);
|
||||
|
||||
@@ -283,6 +291,13 @@ function renderAccounts(accounts) {
|
||||
: `<span class="badge pending">-</span>`}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="cpa-status">
|
||||
${account.subscription_type
|
||||
? `<span class="badge uploaded" title="${account.subscription_type}">${account.subscription_type}</span>`
|
||||
: `<span class="badge pending">-</span>`}
|
||||
</div>
|
||||
</td>
|
||||
<td>${format.date(account.last_refresh) || '-'}</td>
|
||||
<td>
|
||||
<div class="action-buttons">
|
||||
@@ -292,6 +307,12 @@ function renderAccounts(accounts) {
|
||||
<button class="btn btn-ghost btn-sm" onclick="uploadToCpa(${account.id})" title="上传到CPA">
|
||||
☁️
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-sm" onclick="markSubscription(${account.id})" title="标记订阅">
|
||||
🏷️
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-sm" onclick="uploadToTm(${account.id})" title="上传到Team Manager">
|
||||
🚀
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-sm" onclick="viewAccount(${account.id})" title="查看详情">
|
||||
👁️
|
||||
</button>
|
||||
@@ -351,12 +372,16 @@ function updateBatchButtons() {
|
||||
elements.batchRefreshBtn.disabled = count === 0;
|
||||
elements.batchValidateBtn.disabled = count === 0;
|
||||
elements.batchUploadCpaBtn.disabled = count === 0;
|
||||
elements.batchCheckSubBtn.disabled = count === 0;
|
||||
elements.batchUploadTmBtn.disabled = count === 0;
|
||||
elements.exportBtn.disabled = count === 0;
|
||||
|
||||
elements.batchDeleteBtn.textContent = count > 0 ? `🗑️ 删除 (${count})` : '🗑️ 批量删除';
|
||||
elements.batchRefreshBtn.textContent = count > 0 ? `🔄 刷新 (${count})` : '🔄 刷新Token';
|
||||
elements.batchValidateBtn.textContent = count > 0 ? `✅ 验证 (${count})` : '✅ 验证Token';
|
||||
elements.batchUploadCpaBtn.textContent = count > 0 ? `☁️ 上传 (${count})` : '☁️ 上传CPA';
|
||||
elements.batchCheckSubBtn.textContent = count > 0 ? `🔍 检测 (${count})` : '🔍 检测订阅';
|
||||
elements.batchUploadTmBtn.textContent = count > 0 ? `🚀 上传TM (${count})` : '🚀 上传TM';
|
||||
}
|
||||
|
||||
// 刷新单个账号Token
|
||||
@@ -665,3 +690,90 @@ async function handleBatchUploadCpa() {
|
||||
updateBatchButtons();
|
||||
}
|
||||
}
|
||||
|
||||
// ============== 订阅状态 ==============
|
||||
|
||||
// 手动标记订阅类型
|
||||
async function markSubscription(id) {
|
||||
const type = prompt('请输入订阅类型 (plus / team / free):', 'plus');
|
||||
if (!type) return;
|
||||
if (!['plus', 'team', 'free'].includes(type.trim().toLowerCase())) {
|
||||
toast.error('无效的订阅类型,请输入 plus、team 或 free');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await api.post(`/payment/accounts/${id}/mark-subscription`, {
|
||||
subscription_type: type.trim().toLowerCase()
|
||||
});
|
||||
toast.success('订阅状态已更新');
|
||||
loadAccounts();
|
||||
} catch (e) {
|
||||
toast.error('标记失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量检测订阅状态
|
||||
async function handleBatchCheckSubscription() {
|
||||
if (selectedAccounts.size === 0) return;
|
||||
const confirmed = await confirm(`确定要检测选中的 ${selectedAccounts.size} 个账号的订阅状态吗?`);
|
||||
if (!confirmed) return;
|
||||
|
||||
elements.batchCheckSubBtn.disabled = true;
|
||||
elements.batchCheckSubBtn.textContent = '检测中...';
|
||||
|
||||
try {
|
||||
const result = await api.post('/payment/accounts/batch-check-subscription', {
|
||||
ids: Array.from(selectedAccounts)
|
||||
});
|
||||
let message = `成功: ${result.success_count}`;
|
||||
if (result.failed_count > 0) message += `, 失败: ${result.failed_count}`;
|
||||
toast.success(message);
|
||||
loadAccounts();
|
||||
} catch (e) {
|
||||
toast.error('批量检测失败: ' + e.message);
|
||||
} finally {
|
||||
updateBatchButtons();
|
||||
}
|
||||
}
|
||||
|
||||
// ============== Team Manager 上传 ==============
|
||||
|
||||
// 上传单账号到 Team Manager
|
||||
async function uploadToTm(id) {
|
||||
try {
|
||||
toast.info('正在上传到 Team Manager...');
|
||||
const result = await api.post(`/payment/accounts/${id}/upload-tm`);
|
||||
if (result.success) {
|
||||
toast.success('上传成功');
|
||||
} else {
|
||||
toast.error('上传失败: ' + (result.message || '未知错误'));
|
||||
}
|
||||
} catch (e) {
|
||||
toast.error('上传失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量上传到 Team Manager
|
||||
async function handleBatchUploadTm() {
|
||||
if (selectedAccounts.size === 0) return;
|
||||
const confirmed = await confirm(`确定要将选中的 ${selectedAccounts.size} 个账号上传到 Team Manager 吗?`);
|
||||
if (!confirmed) return;
|
||||
|
||||
elements.batchUploadTmBtn.disabled = true;
|
||||
elements.batchUploadTmBtn.textContent = '上传中...';
|
||||
|
||||
try {
|
||||
const result = await api.post('/payment/accounts/batch-upload-tm', {
|
||||
ids: Array.from(selectedAccounts)
|
||||
});
|
||||
let message = `成功: ${result.success_count}`;
|
||||
if (result.failed_count > 0) message += `, 失败: ${result.failed_count}`;
|
||||
if (result.skipped_count > 0) message += `, 跳过: ${result.skipped_count}`;
|
||||
toast.success(message);
|
||||
loadAccounts();
|
||||
} catch (e) {
|
||||
toast.error('批量上传失败: ' + e.message);
|
||||
} finally {
|
||||
updateBatchButtons();
|
||||
}
|
||||
}
|
||||
|
||||
122
static/js/payment.js
Normal file
122
static/js/payment.js
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* 支付页面 JavaScript
|
||||
*/
|
||||
|
||||
let selectedPlan = 'plus';
|
||||
let generatedLink = '';
|
||||
|
||||
// 初始化
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadAccounts();
|
||||
});
|
||||
|
||||
// 加载账号列表
|
||||
async function loadAccounts() {
|
||||
try {
|
||||
const resp = await fetch('/api/accounts?page=1&page_size=100&status=active');
|
||||
const data = await resp.json();
|
||||
const sel = document.getElementById('account-select');
|
||||
sel.innerHTML = '<option value="">-- 请选择账号 --</option>';
|
||||
(data.accounts || []).forEach(acc => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = acc.id;
|
||||
opt.textContent = acc.email;
|
||||
sel.appendChild(opt);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('加载账号失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 选择套餐
|
||||
function selectPlan(plan) {
|
||||
selectedPlan = plan;
|
||||
document.getElementById('plan-plus').classList.toggle('selected', plan === 'plus');
|
||||
document.getElementById('plan-team').classList.toggle('selected', plan === 'team');
|
||||
document.getElementById('team-options').classList.toggle('show', plan === 'team');
|
||||
// 隐藏已生成的链接
|
||||
document.getElementById('link-box').classList.remove('show');
|
||||
generatedLink = '';
|
||||
}
|
||||
|
||||
// 生成支付链接
|
||||
async function generateLink() {
|
||||
const accountId = document.getElementById('account-select').value;
|
||||
if (!accountId) {
|
||||
ui.showToast('请先选择账号', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const body = {
|
||||
account_id: parseInt(accountId),
|
||||
plan_type: selectedPlan,
|
||||
};
|
||||
|
||||
if (selectedPlan === 'team') {
|
||||
body.workspace_name = document.getElementById('workspace-name').value || 'MyTeam';
|
||||
body.seat_quantity = parseInt(document.getElementById('seat-quantity').value) || 5;
|
||||
body.price_interval = document.getElementById('price-interval').value;
|
||||
}
|
||||
|
||||
try {
|
||||
const resp = await fetch('/api/payment/generate-link', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (data.success && data.link) {
|
||||
generatedLink = data.link;
|
||||
document.getElementById('link-text').value = data.link;
|
||||
document.getElementById('link-box').classList.add('show');
|
||||
document.getElementById('open-status').textContent = '';
|
||||
ui.showToast('支付链接生成成功', 'success');
|
||||
} else {
|
||||
ui.showToast(data.detail || '生成链接失败', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
ui.showToast('请求失败: ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// 复制链接
|
||||
function copyLink() {
|
||||
if (!generatedLink) return;
|
||||
navigator.clipboard.writeText(generatedLink).then(() => {
|
||||
ui.showToast('已复制到剪贴板', 'success');
|
||||
}).catch(() => {
|
||||
// 降级方案
|
||||
const ta = document.getElementById('link-text');
|
||||
ta.select();
|
||||
document.execCommand('copy');
|
||||
ui.showToast('已复制到剪贴板', 'success');
|
||||
});
|
||||
}
|
||||
|
||||
// 无痕打开浏览器
|
||||
async function openIncognito() {
|
||||
if (!generatedLink) {
|
||||
ui.showToast('请先生成链接', 'warning');
|
||||
return;
|
||||
}
|
||||
const statusEl = document.getElementById('open-status');
|
||||
statusEl.textContent = '正在打开...';
|
||||
try {
|
||||
const resp = await fetch('/api/payment/open-incognito', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url: generatedLink }),
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (data.success) {
|
||||
statusEl.textContent = '已在无痕模式打开浏览器';
|
||||
ui.showToast('无痕浏览器已打开', 'success');
|
||||
} else {
|
||||
statusEl.textContent = data.message || '未找到可用浏览器,请手动复制链接';
|
||||
ui.showToast(data.message || '未找到浏览器', 'warning');
|
||||
}
|
||||
} catch (e) {
|
||||
statusEl.textContent = '请求失败: ' + e.message;
|
||||
ui.showToast('请求失败', 'error');
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,9 @@ const elements = {
|
||||
// CPA 设置
|
||||
cpaForm: document.getElementById('cpa-form'),
|
||||
testCpaBtn: document.getElementById('test-cpa-btn'),
|
||||
// Team Manager 设置
|
||||
tmForm: document.getElementById('tm-form'),
|
||||
testTmBtn: document.getElementById('test-tm-btn'),
|
||||
// 验证码设置
|
||||
emailCodeForm: document.getElementById('email-code-form'),
|
||||
// Outlook 设置
|
||||
@@ -231,6 +234,14 @@ function initEventListeners() {
|
||||
if (elements.outlookSettingsForm) {
|
||||
elements.outlookSettingsForm.addEventListener('submit', handleSaveOutlookSettings);
|
||||
}
|
||||
|
||||
// Team Manager 设置
|
||||
if (elements.tmForm) {
|
||||
elements.tmForm.addEventListener('submit', handleSaveTm);
|
||||
}
|
||||
if (elements.testTmBtn) {
|
||||
elements.testTmBtn.addEventListener('click', handleTestTm);
|
||||
}
|
||||
}
|
||||
|
||||
// 加载设置
|
||||
@@ -268,6 +279,8 @@ async function loadSettings() {
|
||||
loadCpaSettings();
|
||||
// 加载 Outlook 设置
|
||||
loadOutlookSettings();
|
||||
// 加载 Team Manager 设置
|
||||
loadTmSettings();
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载设置失败:', error);
|
||||
@@ -1066,3 +1079,73 @@ async function handleTestDynamicProxy() {
|
||||
btn.textContent = '🔌 测试动态代理';
|
||||
}
|
||||
}
|
||||
|
||||
// ============== Team Manager 设置 ==============
|
||||
|
||||
async function loadTmSettings() {
|
||||
try {
|
||||
const data = await api.get('/settings/team-manager');
|
||||
document.getElementById('tm-enabled').checked = data.enabled || false;
|
||||
document.getElementById('tm-api-url').value = data.api_url || '';
|
||||
document.getElementById('tm-api-key').value = '';
|
||||
document.getElementById('tm-api-key').placeholder = data.has_api_key ? '已配置,留空保持不变' : '请输入 API Key';
|
||||
} catch (error) {
|
||||
console.error('加载 Team Manager 设置失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSaveTm(e) {
|
||||
e.preventDefault();
|
||||
const data = {
|
||||
enabled: document.getElementById('tm-enabled').checked,
|
||||
api_url: document.getElementById('tm-api-url').value,
|
||||
api_key: document.getElementById('tm-api-key').value || ''
|
||||
};
|
||||
try {
|
||||
await api.post('/settings/team-manager', data);
|
||||
toast.success('Team Manager 设置已保存');
|
||||
loadTmSettings();
|
||||
} catch (error) {
|
||||
toast.error('保存失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTestTm() {
|
||||
const apiUrl = document.getElementById('tm-api-url').value;
|
||||
const apiKey = document.getElementById('tm-api-key').value;
|
||||
|
||||
if (!apiUrl) {
|
||||
toast.error('请先填写 API URL');
|
||||
return;
|
||||
}
|
||||
|
||||
let keyToTest = apiKey;
|
||||
if (!keyToTest) {
|
||||
const saved = await api.get('/settings/team-manager');
|
||||
if (!saved.has_api_key) {
|
||||
toast.error('请先填写 API Key');
|
||||
return;
|
||||
}
|
||||
keyToTest = 'use_saved_key';
|
||||
}
|
||||
|
||||
elements.testTmBtn.disabled = true;
|
||||
elements.testTmBtn.innerHTML = '<span class="loading-spinner"></span> 测试中...';
|
||||
|
||||
try {
|
||||
const result = await api.post('/settings/team-manager/test', {
|
||||
api_url: apiUrl,
|
||||
api_key: keyToTest
|
||||
});
|
||||
if (result.success) {
|
||||
toast.success(result.message);
|
||||
} else {
|
||||
toast.error(result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error('测试失败: ' + error.message);
|
||||
} finally {
|
||||
elements.testTmBtn.disabled = false;
|
||||
elements.testTmBtn.textContent = '🔌 测试连接';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
<a href="/" class="nav-link">注册</a>
|
||||
<a href="/accounts" class="nav-link active">账号管理</a>
|
||||
<a href="/email-services" class="nav-link">邮箱服务</a>
|
||||
<a href="/payment" class="nav-link">支付</a>
|
||||
<a href="/settings" class="nav-link">设置</a>
|
||||
</div>
|
||||
<button class="theme-toggle" onclick="theme.toggle()" title="切换主题">
|
||||
@@ -126,6 +127,12 @@
|
||||
<button class="btn btn-success" id="batch-upload-cpa-btn" disabled title="批量上传到CPA">
|
||||
☁️ 上传CPA
|
||||
</button>
|
||||
<button class="btn btn-info" id="batch-check-sub-btn" disabled title="批量检测订阅状态">
|
||||
🔍 检测订阅
|
||||
</button>
|
||||
<button class="btn btn-success" id="batch-upload-tm-btn" disabled title="批量上传到Team Manager">
|
||||
🚀 上传TM
|
||||
</button>
|
||||
<button class="btn btn-danger" id="batch-delete-btn" disabled>
|
||||
🗑️ 批量删除
|
||||
</button>
|
||||
@@ -157,13 +164,14 @@
|
||||
<th style="width: 120px;">邮箱服务</th>
|
||||
<th style="width: 80px;">状态</th>
|
||||
<th style="width: 80px;">CPA</th>
|
||||
<th style="width: 80px;">订阅</th>
|
||||
<th style="width: 140px;">最后刷新</th>
|
||||
<th style="width: 150px;">操作</th>
|
||||
<th style="width: 170px;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="accounts-table">
|
||||
<tr>
|
||||
<td colspan="9">
|
||||
<td colspan="11">
|
||||
<div class="empty-state">
|
||||
<div class="skeleton skeleton-text" style="width: 60%;"></div>
|
||||
<div class="skeleton skeleton-text" style="width: 80%;"></div>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<a href="/" class="nav-link">注册</a>
|
||||
<a href="/accounts" class="nav-link">账号管理</a>
|
||||
<a href="/email-services" class="nav-link active">邮箱服务</a>
|
||||
<a href="/payment" class="nav-link">支付</a>
|
||||
<a href="/settings" class="nav-link">设置</a>
|
||||
</div>
|
||||
<button class="theme-toggle" onclick="theme.toggle()" title="切换主题">
|
||||
|
||||
@@ -106,6 +106,7 @@
|
||||
<a href="/" class="nav-link active">注册</a>
|
||||
<a href="/accounts" class="nav-link">账号管理</a>
|
||||
<a href="/email-services" class="nav-link">邮箱服务</a>
|
||||
<a href="/payment" class="nav-link">支付</a>
|
||||
<a href="/settings" class="nav-link">设置</a>
|
||||
</div>
|
||||
<button class="theme-toggle" onclick="theme.toggle()" title="切换主题">
|
||||
|
||||
147
templates/payment.html
Normal file
147
templates/payment.html
Normal file
@@ -0,0 +1,147 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>支付升级 - OpenAI 注册系统</title>
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>💳</text></svg>">
|
||||
<style>
|
||||
.plan-cards {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.plan-card {
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
text-align: center;
|
||||
}
|
||||
.plan-card:hover {
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
.plan-card.selected {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
|
||||
}
|
||||
.plan-card h3 { margin: 0 0 8px; font-size: 1.2rem; }
|
||||
.plan-card p { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }
|
||||
.team-options { display: none; }
|
||||
.team-options.show { display: block; }
|
||||
.link-box {
|
||||
display: none;
|
||||
margin-top: 16px;
|
||||
}
|
||||
.link-box.show { display: block; }
|
||||
.link-text {
|
||||
width: 100%;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.8rem;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<!-- 导航栏 -->
|
||||
<nav class="navbar">
|
||||
<div class="nav-brand">
|
||||
<h1>OpenAI 注册系统</h1>
|
||||
</div>
|
||||
<div class="nav-links">
|
||||
<a href="/" class="nav-link">注册</a>
|
||||
<a href="/accounts" class="nav-link">账号管理</a>
|
||||
<a href="/email-services" class="nav-link">邮箱服务</a>
|
||||
<a href="/payment" class="nav-link active">支付</a>
|
||||
<a href="/settings" class="nav-link">设置</a>
|
||||
</div>
|
||||
<button class="theme-toggle" onclick="theme.toggle()" title="切换主题">🌙</button>
|
||||
</nav>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<main class="main-content">
|
||||
<div class="page-header">
|
||||
<h2>支付升级</h2>
|
||||
<p class="subtitle">为账号生成 Plus 或 Team 订阅支付链接</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3>选择套餐</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- 套餐选择 -->
|
||||
<div class="plan-cards">
|
||||
<div class="plan-card selected" id="plan-plus" onclick="selectPlan('plus')">
|
||||
<h3>Plus</h3>
|
||||
<p>个人订阅,$20/月</p>
|
||||
</div>
|
||||
<div class="plan-card" id="plan-team" onclick="selectPlan('team')">
|
||||
<h3>Team</h3>
|
||||
<p>团队订阅,按座位计费</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 账号选择 -->
|
||||
<div class="form-group">
|
||||
<label for="account-select">选择账号</label>
|
||||
<select id="account-select" style="width:100%">
|
||||
<option value="">-- 加载中... --</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Team 额外参数 -->
|
||||
<div class="team-options" id="team-options">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="workspace-name">工作区名称</label>
|
||||
<input type="text" id="workspace-name" value="MyTeam" placeholder="MyTeam">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="seat-quantity">座位数量</label>
|
||||
<input type="number" id="seat-quantity" value="5" min="1" max="100">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="price-interval">计费周期</label>
|
||||
<select id="price-interval">
|
||||
<option value="month">月付</option>
|
||||
<option value="year">年付</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作区 -->
|
||||
<div class="form-actions">
|
||||
<button class="btn btn-primary" onclick="generateLink()">生成支付链接</button>
|
||||
</div>
|
||||
|
||||
<!-- 链接结果 -->
|
||||
<div class="link-box" id="link-box">
|
||||
<label>支付链接</label>
|
||||
<textarea class="link-text" id="link-text" readonly></textarea>
|
||||
<div class="form-actions" style="margin-top:10px">
|
||||
<button class="btn btn-secondary" onclick="copyLink()">复制链接</button>
|
||||
<button class="btn btn-primary" onclick="openIncognito()">无痕打开浏览器</button>
|
||||
</div>
|
||||
<p class="hint" id="open-status"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/utils.js"></script>
|
||||
<script src="/static/js/payment.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -18,6 +18,7 @@
|
||||
<a href="/" class="nav-link">注册</a>
|
||||
<a href="/accounts" class="nav-link">账号管理</a>
|
||||
<a href="/email-services" class="nav-link">邮箱服务</a>
|
||||
<a href="/payment" class="nav-link">支付</a>
|
||||
<a href="/settings" class="nav-link active">设置</a>
|
||||
</div>
|
||||
<button class="theme-toggle" onclick="theme.toggle()" title="切换主题">
|
||||
@@ -36,6 +37,7 @@
|
||||
<div class="tabs">
|
||||
<button class="tab-btn active" data-tab="proxy">🌐 代理设置</button>
|
||||
<button class="tab-btn" data-tab="cpa">☁️ CPA上传</button>
|
||||
<button class="tab-btn" data-tab="team-manager">🚀 Team Manager</button>
|
||||
<button class="tab-btn" data-tab="outlook">📮 Outlook配置</button>
|
||||
<button class="tab-btn" data-tab="registration">⚙️ 注册配置</button>
|
||||
<button class="tab-btn" data-tab="email-code">📧 验证码配置</button>
|
||||
@@ -269,6 +271,44 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Team Manager 设置 -->
|
||||
<div class="tab-content" id="team-manager-tab">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3>Team Manager 配置</h3>
|
||||
<span class="hint">配置 Team Manager 账号导入功能</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form id="tm-form">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<input type="checkbox" id="tm-enabled" name="enabled">
|
||||
启用 Team Manager 上传
|
||||
</label>
|
||||
<p class="hint">启用后可在账号管理页面将账号导入 Team Manager 平台</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="tm-api-url">API URL</label>
|
||||
<input type="text" id="tm-api-url" name="api_url" placeholder="例如: https://tm.example.com">
|
||||
<p class="hint">Team Manager 平台的 API 地址</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="tm-api-key">API Key</label>
|
||||
<input type="password" id="tm-api-key" name="api_key" placeholder="留空则保持原值" autocomplete="new-password">
|
||||
<p class="hint">Team Manager 平台的认证 Key</p>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">💾 保存设置</button>
|
||||
<button type="button" class="btn btn-secondary" id="test-tm-btn">🔌 测试连接</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Outlook 配置 -->
|
||||
<div class="tab-content" id="outlook-tab">
|
||||
<div class="card">
|
||||
|
||||
Reference in New Issue
Block a user