align API response format with maqt.top real specs: weapon-categories, weapons, schemes, schemes_aob, favorites check, encryption key derivation
This commit is contained in:
120
origet/test_apis.py
Normal file
120
origet/test_apis.py
Normal file
@@ -0,0 +1,120 @@
|
||||
"""
|
||||
原版 maqt.top API 接口测试脚本
|
||||
|
||||
用法:
|
||||
python test_apis.py
|
||||
python test_apis.py --user <username> --pass <password>
|
||||
python test_apis.py --user <username> --pass <password> --output results.json
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
from client import MaqtClient
|
||||
from decrypt import try_decrypt
|
||||
|
||||
OUTPUT = None # global output dict
|
||||
|
||||
|
||||
def banner(msg: str):
|
||||
print(f"\n{'='*60}")
|
||||
print(f" {msg}")
|
||||
print(f"{'='*60}")
|
||||
|
||||
|
||||
def test(name: str, fn, *args, **kwargs):
|
||||
print(f"\n--- {name} ---")
|
||||
rv = None
|
||||
err = None
|
||||
try:
|
||||
result = fn(*args, **kwargs)
|
||||
decrypted = try_decrypt(result)
|
||||
print(f" OK (keys: {list(decrypted.keys()) if isinstance(decrypted, dict) else '?'})")
|
||||
if isinstance(decrypted, dict):
|
||||
if "data" in decrypted and isinstance(decrypted["data"], list):
|
||||
print(f" data_len={len(decrypted['data'])}")
|
||||
if decrypted.get("encrypted"):
|
||||
print(f" (was encrypted)")
|
||||
elif isinstance(decrypted, list):
|
||||
print(f" list_len={len(decrypted)}")
|
||||
rv = decrypted
|
||||
except Exception as e:
|
||||
print(f" [ERROR] {e}")
|
||||
err = str(e)
|
||||
OUTPUT[name] = {"ok": rv is not None, "data": rv, "error": err}
|
||||
return rv
|
||||
|
||||
|
||||
def main():
|
||||
global OUTPUT
|
||||
OUTPUT = {}
|
||||
|
||||
parser = argparse.ArgumentParser(description="maqt.top API tester")
|
||||
parser.add_argument("--user", default="sixteenth")
|
||||
parser.add_argument("--pass", dest="password", default="")
|
||||
parser.add_argument("--output", default=None, help="Output JSON file path")
|
||||
args = parser.parse_args()
|
||||
|
||||
outfile = args.output or f"test_output_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
|
||||
|
||||
print(f"[{datetime.now().isoformat()}] 开始测试...")
|
||||
print(f"输出文件: {outfile}")
|
||||
|
||||
c = MaqtClient()
|
||||
|
||||
# ---- 1. 无需认证的接口 ----
|
||||
banner("1. 武器分类")
|
||||
cats = test("weapon-categories", c.get_weapon_categories)
|
||||
|
||||
banner("2. 武器列表 (AR)")
|
||||
test("weapons?category=AR", c.get_weapons, category="AR")
|
||||
|
||||
banner("3. 武器列表 (无参数)")
|
||||
test("weapons (all)", c.get_weapons)
|
||||
|
||||
banner("4. 方案列表 (schemes, hot, p1)")
|
||||
schemes = test("schemes?sort=hot&page=1&limit=12", c.get_schemes, page=1, sort="hot")
|
||||
|
||||
banner("5. 方案列表 (schemes_aob)")
|
||||
test("schemes_aob", c.get_schemes, mode="schemes_aob", page=1, sort="hot")
|
||||
|
||||
banner("6. 广告列表")
|
||||
test("adverts", c.get_adverts)
|
||||
|
||||
# ---- 2. 登录 ----
|
||||
if args.password:
|
||||
banner("7. 登录")
|
||||
login_resp = test("login", c.login, args.user, args.password)
|
||||
if login_resp and login_resp.get("token"):
|
||||
print(f" Token: {login_resp['token'][:50]}...")
|
||||
|
||||
banner("8. 会话状态")
|
||||
test("session-status", c.session_status)
|
||||
|
||||
banner("9. VIP状态")
|
||||
test("vip-status", c.vip_status)
|
||||
|
||||
banner("10. 收藏列表")
|
||||
test("favorites", c.get_favorites, page=1)
|
||||
|
||||
banner("11. 收藏数量")
|
||||
test("favorites/count", c.favorites_count)
|
||||
|
||||
banner("12. 用户统计")
|
||||
uid = login_resp.get("user", {}).get("id", 0)
|
||||
test(f"user/stats/{uid}", c.user_stats, uid)
|
||||
|
||||
banner("13. 活跃Ping")
|
||||
test("activity/ping", c.activity_ping)
|
||||
else:
|
||||
print("\n 跳过登录测试 (未提供 --pass)")
|
||||
|
||||
banner("DONE")
|
||||
|
||||
with open(outfile, "w", encoding="utf-8") as f:
|
||||
json.dump(OUTPUT, f, ensure_ascii=False, indent=2, default=str)
|
||||
print(f"\n结果已保存到: {outfile}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user