Files
CKB-Interface/application/store/upload_flow_packages_simple.py
2026-03-24 10:39:16 +08:00

142 lines
4.3 KiB
Python

# -*- coding: utf-8 -*-
import sys
import requests
import json
sys.stdout.reconfigure(encoding='utf-8')
# 配置
TOKEN = "afxp_fa4137GfIzJtlOCeQHjpCXc83SFWmeAOrZnq"
PROJECT_ID = "6037107"
FOLDER_ID = "78121195" # 流量采购管理目录ID
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"
}
# 流量采购接口列表(简化版)
apis = [
{
"name": "获取流量套餐列表",
"method": "GET",
"path": "/v2/store/flow-packages",
"folderId": FOLDER_ID,
"description": "获取所有可购买的流量套餐列表"
},
{
"name": "获取流量套餐详情",
"method": "GET",
"path": "/v2/store/flow-packages/:id",
"folderId": FOLDER_ID,
"description": "获取指定流量套餐的详细信息",
"parameters": {
"path": [{
"name": "id",
"required": True,
"description": "套餐ID"
}]
}
},
{
"name": "获取剩余流量",
"method": "GET",
"path": "/v2/store/flow-packages/remaining-flow",
"folderId": FOLDER_ID,
"description": "获取当前用户的有效流量套餐剩余流量信息"
},
{
"name": "创建流量采购订单",
"method": "POST",
"path": "/v2/store/flow-packages/order",
"folderId": FOLDER_ID,
"description": "创建流量套餐购买订单",
"requestBody": {
"type": "application/json",
"jsonSchema": {
"type": "object",
"required": ["packageId"],
"properties": {
"packageId": {"type": "integer", "description": "套餐ID"},
"payType": {"type": "string", "description": "支付方式", "default": "wechat"},
"remark": {"type": "string", "description": "备注"}
}
}
}
},
{
"name": "获取订单列表",
"method": "GET",
"path": "/v2/store/flow-packages/orders",
"folderId": FOLDER_ID,
"description": "获取当前用户的流量套餐订单列表",
"parameters": {
"query": [
{"name": "page", "type": "integer", "description": "页码", "default": 1},
{"name": "limit", "type": "integer", "description": "每页数量", "default": 10},
{"name": "status", "type": "integer", "description": "订单状态"}
]
}
}
]
# 创建接口
print("=" * 60)
print("开始上传流量采购接口到Apifox...")
print(f"项目ID: {PROJECT_ID}")
print(f"目录ID: {FOLDER_ID}")
print("=" * 60)
success_count = 0
fail_count = 0
api_ids = []
for i, api in enumerate(apis, 1):
print(f"\n[{i}/{len(apis)}] 创建接口: {api['name']}")
print(f" {api['method']} {api['path']}")
try:
response = requests.post(
f"{BASE_URL}/projects/{PROJECT_ID}/http-apis",
headers=headers,
json=api,
timeout=30
)
if response.status_code == 200:
result = response.json()
if result.get('success'):
api_id = result.get('data', {}).get('id')
print(f" ✅ 创建成功 (ID: {api_id})")
success_count += 1
api_ids.append(api_id)
else:
print(f" ❌ 创建失败: {result.get('errorMessage', 'Unknown error')}")
fail_count += 1
else:
print(f" ❌ HTTP {response.status_code}: {response.text[:200]}")
fail_count += 1
except Exception as e:
print(f" ❌ 异常: {str(e)}")
fail_count += 1
# 输出结果
print("\n" + "=" * 60)
print("✅ 完成!")
print(f"\n📊 统计:")
print(f" - 成功: {success_count}/{len(apis)}")
print(f" - 失败: {fail_count}")
if api_ids:
print(f"\n📝 接口ID列表:")
for i, api_id in enumerate(api_ids, 1):
print(f" {i}. {api_id}")
print(f"\n🔗 访问链接:")
print(f" https://app.apifox.com/project/{PROJECT_ID}")
print(f" 流量采购目录: https://app.apifox.com/project/{PROJECT_ID}/apis/folder/{FOLDER_ID}")
print("=" * 60)