111 lines
3.1 KiB
Python
111 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
||
import sys
|
||
import requests
|
||
import json
|
||
|
||
sys.stdout.reconfigure(encoding='utf-8')
|
||
|
||
TOKEN = "afxp_fa4137GfIzJtlOCeQHjpCXc83SFWmeAOrZnq"
|
||
PROJECT_ID = "6037107"
|
||
BASE_URL = "https://api.apifox.com/api/v1"
|
||
|
||
headers = {
|
||
"X-Apifox-Api-Version": "2024-03-28",
|
||
"Authorization": f"Bearer {TOKEN}",
|
||
"Content-Type": "application/json; charset=utf-8"
|
||
}
|
||
|
||
# 失败的API ID
|
||
FAILED_API_IDS = {
|
||
"passwordLogin": "415781876",
|
||
"noPasswordLogin": "415781877",
|
||
"getModules": "415861964",
|
||
"purchase": None # 这个需要重新创建
|
||
}
|
||
|
||
def get_api(api_id):
|
||
"""获取API详情"""
|
||
try:
|
||
response = requests.get(
|
||
f"{BASE_URL}/projects/{PROJECT_ID}/http-apis/{api_id}",
|
||
headers=headers,
|
||
timeout=30
|
||
)
|
||
if response.status_code == 200:
|
||
result = response.json()
|
||
if result.get('success'):
|
||
return result.get('data')
|
||
return None
|
||
except Exception as e:
|
||
print(f"获取API失败: {e}")
|
||
return None
|
||
|
||
def update_api_simple(api_id, updates):
|
||
"""简单更新API(只更新描述等字段)"""
|
||
try:
|
||
response = requests.patch(
|
||
f"{BASE_URL}/projects/{PROJECT_ID}/http-apis/{api_id}",
|
||
headers=headers,
|
||
json=updates,
|
||
timeout=30
|
||
)
|
||
if response.status_code == 200:
|
||
result = response.json()
|
||
return result.get('success'), result.get('errorMessage')
|
||
return False, f"HTTP {response.status_code}"
|
||
except Exception as e:
|
||
return False, str(e)
|
||
|
||
# 获取失败的API详情
|
||
print("检查失败的API...")
|
||
for name, api_id in FAILED_API_IDS.items():
|
||
if api_id:
|
||
print(f"\n{name} (ID: {api_id}):")
|
||
api_data = get_api(api_id)
|
||
if api_data:
|
||
print(f" 当前路径: {api_data.get('path')}")
|
||
print(f" 当前方法: {api_data.get('method')}")
|
||
# 只更新描述
|
||
success, error = update_api_simple(api_id, {
|
||
"description": f"已更新 - {api_data.get('name', '')}"
|
||
})
|
||
if success:
|
||
print(f" ✅ 描述更新成功")
|
||
else:
|
||
print(f" ❌ 更新失败: {error}")
|
||
|
||
# 重新创建购买流量接口
|
||
print("\n重新创建购买流量接口...")
|
||
purchase_api = {
|
||
"name": "购买流量",
|
||
"method": "POST",
|
||
"path": "/v2/store/traffic/packages/:id/purchase",
|
||
"folderId": "78015216",
|
||
"description": "购买指定流量池包中的流量",
|
||
"tags": ["流量采购"],
|
||
"parameters": {
|
||
"path": [{
|
||
"name": "id",
|
||
"required": True,
|
||
"description": "流量池包ID"
|
||
}]
|
||
}
|
||
}
|
||
|
||
response = requests.post(
|
||
f"{BASE_URL}/projects/{PROJECT_ID}/http-apis",
|
||
headers=headers,
|
||
json=purchase_api,
|
||
timeout=30
|
||
)
|
||
|
||
if response.status_code == 200:
|
||
result = response.json()
|
||
if result.get('success'):
|
||
print(f"✅ 创建成功 (ID: {result.get('data', {}).get('id')})")
|
||
else:
|
||
print(f"❌ 创建失败: {result.get('errorMessage')}")
|
||
else:
|
||
print(f"❌ HTTP {response.status_code}: {response.text[:200]}")
|
||
|