Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
DistPub
ima2api
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
ima2api
/
check_token.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
45 lines (38 loc) · 1.75 KB
main
Breadcrumbs
ima2api
/
check_token.py
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
45 lines (38 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""票据健康检查:不起服务,直接验证 ima_cookie.txt 是否有效
用法: python3 check_token.py
输出: 有效(显示账号可用模型数)/ 过期(重新提取指引)
"""
import asyncio
import sys
from ima_auth import load_cookie_file, TokenProvider
from ima_upstream import ImaUpstream, TokenExpiredError
async def main():
kv = load_cookie_file("ima_cookie.txt")
if not kv or not kv.get("IMA-TOKEN"):
print("✗ ima_cookie.txt 无效:缺少 IMA-TOKEN")
print(" 请从网页版 F12 复制 x-ima-cookie 整串存入该文件")
sys.exit(2)
provider = TokenProvider()
provider.get_kv = lambda: kv
up = ImaUpstream(provider=provider)
bkn = kv.get("IMA-TOKEN", "")
print(f"票据指纹: IMA-TOKEN={bkn[:12]}… UID={kv.get('IMA-UID','?')}")
try:
models = await up.get_models(force=True)
default = next((m for m in models if m.get("is_default")), models[0] if models else None)
print(f"✓ 票据有效!可用模型 {len(models)} 个,默认: {default['model_name'] if default else '?'}")
print(" 可直接启动服务: uvicorn server:app --port 8300")
except TokenExpiredError as e:
print(f"✗ 票据已过期({e})")
print(" 30 秒换票流程:")
print(" 1. 浏览器打开 ima.qq.com(保持登录)→ F12 → Network")
print(" 2. 随便发一条消息,点任意 ima.qq.com 请求")
print(" 3. Request Headers 里复制 x-ima-cookie 整串")
print(" 4. 覆盖写入 ima_cookie.txt,重跑本脚本确认")
sys.exit(1)
except Exception as e:
print(f"✗ 其他错误: {type(e).__name__}: {e}")
sys.exit(3)
finally:
await up.aclose()
asyncio.run(main())
You can’t perform that action at this time.