乐于分享
好东西不私藏

OpenClaw 养虾教程⑧ 让 AI 能上网:Web 服务与API集成安全指南

OpenClaw 养虾教程⑧ 让 AI 能上网:Web 服务与API集成安全指南

导读

前一篇我们给 AI 配了数据库,让 AI 能"记住"东西。但这还不够——AI 需要能"上网"

想象这些场景:

  • 用户说"帮我查一下明天的天气" → AI 需要调用天气 API

  • 用户说"把这篇文章发到公众号" → AI 需要调用微信 API

  • 用户说"创建一个 GitHub Issue" → AI 需要调用 GitHub API

  • 用户说"在飞书群里通知大家开会" → AI 需要调用飞书机器人 API

不能调用外部 API 的 AI,就像没有手脚的人——脑子再好使,也干不了活。

这篇就解决三个问题:

  • 如何让 AI 安全地调用 HTTP API?

  • 如何管理 API 密钥等敏感凭证?

  • 如何设计重试、超时、限流等保护机制?

一、为什么 AI 需要调用 API?

1.1 真实场景:我们的智能助手进化史

阶段 1:只会聊天的 AI

Python                  # 只能回答通用问题                  用户:明天天气怎么样?                  AI:抱歉,我无法获取实时天气信息...                  用户:帮我在 GitHub 上提个 Issue                  AI:抱歉,我没有权限访问 GitHub...

阶段 2:能查天气的 AI

Python                  # 接入了天气 API                  用户:明天天气怎么样?                  AI:明天北京晴转多云,最高温度 25°C,最低 15°C,适合户外活动。

阶段 3:能干活的 AI

Python                  # 接入了多个服务 API                  用户:写一篇公众号文章,发到草稿箱,然后在飞书群里通知大家                  AI:

    ✅ 文章已撰写完成                  ✅ 已发布到公众号草稿箱:https://mp.weixin.qq.com/...                 ✅ 已在飞书群发送通知:@所有人 新文章已发布...

关键区别:API 集成让 AI 从"聊天机器人"变成"智能助手"。

1.2 API 集成的三大价值

价值

说明

案例

获取实时信息

查询天气、新闻、股票、汇率等

天气 API、新闻 API

执行实际操作

发送邮件、创建任务、发布内容

微信 API、GitHub API

连接业务系统

查询订单、更新库存、生成报表

企业内部 API

二、API 调用的基础架构

2.1 一个完整的 API 调用流程

用户请求                  ↓                  AI 解析意图                  ↓                  选择对应 API                  ↓                  准备请求参数                  ↓                  添加认证信息(API Key/Token)                  ↓                  发送 HTTP 请求                  ↓                  处理响应                  ↓                  返回结果给用户                  ↓                  记录日志(便于排查问题)

每个环节都可能出问题

  • 参数错误 → API 返回 400

  • 认证失败 → API 返回 401

  • 权限不足 → API 返回 403

  • 服务宕机 → 请求超时

  • 限流触发 → API 返回 429

所以不能简单地 requests.get(url) 就完事

2.2 最小可用示例

Python                  import requests                  # ❌ 最简但不实用的做法                  response = requests.get("https://api.weather.com/v1/forecast?city=beijing")                  print(response.json())

问题

  • 没有错误处理

  • 没有超时设置(可能永久卡住)

  • 没有重试机制(网络抖动就失败)

  • 没有认证信息(大多数 API 需要)

  • 没有日志记录(出问题无法排查)

2.3 生产级示例

Python                  import requests                  import logging                  from typing import Optional, Dict, Any                  logger = logging.getLogger(__name__)                  class WeatherAPI:                  """天气 API 客户端 - 生产级实现"""                  def __init__(self, api_key: str, base_url: str = "https://api.weather.com"):                  self.api_key = api_key                  self.base_url = base_url                  self.session = requests.Session()                  self.session.headers.update({                  "Authorization": f"Bearer {api_key}",                  "Content-Type": "application/json"                  })                  async def get_forecast(                  self,                  city: str,                  days: int = 1,                  timeout: int = 10,                  max_retries: int = 3                  ) -> Optional[Dict[str, Any]]:                  """获取天气预报"""                  url = f"{self.base_url}/v1/forecast"                  params = {"city": city, "days": days}                  for attempt in range(max_retries):                  try:                  # 发送请求(带超时)                  response = self.session.get(                  url,                  params=params,                  timeout=timeout# 10 秒超时                  )                  # 检查 HTTP 状态码                  if response.status_code == 200:                  logger.info(f"天气查询成功:{city}")                  return response.json()                  elif response.status_code == 429:                  # 限流,等待后重试                  retry_after = int(response.headers.get("Retry-After", 5))                  logger.warning(f"API 限流,等待 {retry_after} 秒后重试")                  await asyncio.sleep(retry_after)                  continue                  elif response.status_code in [401, 403]:                  # 认证错误,不应重试                  logger.error(f"认证失败:{response.status_code}")                  return None                  else:                  logger.error(f"API 错误:{response.status_code} - {response.text}")                  return None                  except requests.Timeout:                  logger.warning(f"请求超时(第 {attempt + 1}/{max_retries} 次)")                  if attempt < max_retries - 1:                  await asyncio.sleep(2 ** attempt)# 指数退避                  continue                  except requests.ConnectionError as e:                  logger.error(f"网络连接错误:{e}")                  return None                  logger.error(f"达到最大重试次数,查询失败:{city}")                  return None

关键改进

  • ✅ 超时设置(防止永久卡住)

  • ✅ 重试机制(网络抖动自动恢复)

  • ✅ 错误分类处理(401 不应重试,429 等待后重试)

  • ✅ 日志记录(便于排查问题)

  • ✅ 指数退避(避免雪崩效应)

三、API 密钥管理:90% 开发者踩过的坑

3.1 风险场景:密钥泄露的代价

真实案例

2024 年某创业公司,AI 助手调用短信 API 发送验证码。开发者把 API Key 硬编码在代码里:

Python                  # ❌ 致命错误:硬编码 API Key                  API_KEY = "sk-1234567890abcdef"# 提交到了 GitHub                  # 后果:                  # 1. 密钥被爬虫扫描到                  # 2. 被盗用发送垃圾短信                  # 3. 账户欠费 50 万元                  # 4. 公司倒闭

教训API 密钥 = 现金,泄露 = 丢钱。

3.2 正确做法:分层管理敏感信息

┌─────────────────────────────────────┐│   第一层:环境变量(开发环境)           │├─────────────────────────────────────┤│   第二层:加密配置文件(生产环境)       │├─────────────────────────────────────┤│   第三层:密钥管理服务(企业级)         │└─────────────────────────────────────┘

第一层:环境变量(适合个人项目)

Python                  # ✅ 正确做法:从环境变量读取                  import os                  API_KEY = os.getenv("WEATHER_API_KEY")                  if not API_KEY:                  raise ValueError("WEATHER_API_KEY 环境变量未设置")

配合 .env 文件

Bash                  # .env 文件(加入 .gitignore!)                  WEATHER_API_KEY=sk-1234567890abcdef                  GITHUB_TOKEN=ghp_xxxxxxxxxxxx                  FEISHU_APP_ID=cli_a1b2c3d4e5f6

Python                  # 使用 python-dotenv 加载                  from dotenv import load_dotenv                  load_dotenv(".env")# 加载本地 .env 文件

.gitignore 必须包含

# 敏感信息                  .env                  *.env                  secrets/                  credentials/

第二层:加密配置文件(适合团队项目)

YAML                  # secrets/config.enc.yaml(加密存储)                  weather:                  api_key: ENC[AES256_GCM,data:xxxx,iv:yyyy,tag:zzzz]                  github:                  token: ENC[AES256_GCM,data:aaaa,iv:bbbb,tag:cccc]

解密后使用

Python                  from cryptography.fernet import Fernet                  def decrypt_secret(encrypted: str) -> str:                  key = os.getenv("SECRET_KEY")# 主密钥从环境变量读取                  f = Fernet(key)                  return f.decrypt(encrypted.encode()).decode()                  API_KEY = decrypt_secret(config["weather"]["api_key"])

第三层:密钥管理服务(适合企业)

使用专业 KMS 服务:

  • AWS Secrets Manager

  • Azure Key Vault

  • 阿里云 KMS

  • HashiCorp Vault

Python                  # 使用 AWS Secrets Manager                  import boto3                  client = boto3.client("secretsmanager")                  response = client.get_secret_value(SecretId="prod/weather-api")                  API_KEY = response["SecretString"]

优势

  • ✅ 密钥轮换自动化

  • ✅ 访问审计日志

  • ✅ 细粒度权限控制

  • ✅ 泄漏自动告警

3.3 OpenClaw 中的密钥管理

在 OpenClaw 中,推荐使用环境变量 + 技能目录隔离

~/.openclaw/                  ├── .env# 全局环境变量(所有技能可见)                  ├── mcp.json# MCP 配置                  └── extensions/                  ├── wecom/                  └── skills/                  └── wechat-mp-publisher/                  └── wechat.env# 技能专属环境变量                  └── feishu/                  └── skills/                  └── feishu-doc/                  └── feishu.env# 技能专属环境变量

加载顺序

  • 全局 .env(所有技能共享)

  • 技能专属 .env(仅该技能可见)

  • 系统环境变量(优先级最高)

四、HTTP 客户端设计模式

4.1 会话复用(提升性能)

Python                  # ❌ 错误做法:每次请求创建新连接                  def get_weather(city: str):                  response = requests.get(f"{BASE_URL}/forecast?city={city}")                  return response.json()                  # 问题:                  # - 每次都重新建立 TCP 连接                  # - 每次都重新 TLS 握手                  # - 性能差 10 倍以上

Python                  # ✅ 正确做法:复用 Session                  class APIClient:                  def __init__(self, base_url: str, api_key: str):                  self.session = requests.Session()                  self.session.headers.update({                  "Authorization": f"Bearer {api_key}",                  "User-Agent": "MyAI/1.0"                  })                  self.base_url = base_url                  def get_weather(self, city: str):                  # 复用 TCP 连接和 TLS 会话                  response = self.session.get(                  f"{self.base_url}/forecast",                  params={"city": city}                  )                  return response.json()

性能对比

  • 新建连接:~200ms/请求

  • 复用连接:~20ms/请求

  • 10 倍性能提升

4.2 超时设置(防止卡死)

Python                  # ❌ 没有超时(可能永久卡住)                  response = requests.get(url)                  # ✅ 设置超时                  response = requests.get(url, timeout=10)# 10 秒超时                  # ✅ 更细粒度控制                  response = requests.get(                  url,                  timeout=(5, 30)# (连接超时,读取超时)                  )

推荐值

  • 连接超时:3-5 秒(网络问题快速失败)

  • 读取超时:10-30 秒(根据 API 响应时间)

  • 总超时:不超过 60 秒

4.3 重试策略(应对网络抖动)

Python                  from requests.adapters import HTTPAdapter                  from urllib3.util.retry import Retry                  # 配置重试策略                  retry_strategy = Retry(                  total=3,# 最多重试 3 次                  backoff_factor=1,# 退避因子:1, 2, 4 秒                  status_forcelist=[429, 500, 502, 503, 504],# 触发重试的状态码                  allowed_methods=["GET", "POST"]# 允许重试的方法                  )                  adapter = HTTPAdapter(max_retries=retry_strategy)                  session = requests.Session()                  session.mount("https://", adapter)                  session.mount("http://", adapter)                  # 现在所有请求都会自动重试                  response = session.get(url)

退避策略

  • 第 1 次重试:等待 1 秒

  • 第 2 次重试:等待 2 秒

  • 第 3 次重试:等待 4 秒

  • 避免雪崩效应(所有请求同时重试压垮服务)

4.4 限流保护(避免被封)

Python                  import time                  from collections import defaultdict                  class RateLimiter:                  """简单的令牌桶限流器"""                  def __init__(self, calls_per_second: int = 10):                  self.min_interval = 1.0 / calls_per_second                  self.last_call = defaultdict(float)                  def wait_if_needed(self, api_name: str):                  """如果超限则等待"""                  now = time.time()                  elapsed = now - self.last_call[api_name]                  if elapsed < self.min_interval:                  sleep_time = self.min_interval - elapsed                  time.sleep(sleep_time)                  self.last_call[api_name] = time.time()                  # 使用                  limiter = RateLimiter(calls_per_second=5)# 每秒最多 5 次                  def call_api():                  limiter.wait_if_needed("weather_api")                  response = requests.get(url)                  return response.json()

更高级的方案

  • 使用 Redis 实现分布式限流

  • 使用令牌桶算法平滑流量

  • 监控 API 使用量,提前预警

五、实战案例:为 AI 集成天气 API

5.1 需求背景

我们需要让 AI 能回答天气相关问题:

  • "明天北京天气怎么样?"

  • "上海周末会下雨吗?"

  • "推荐一个适合户外旅游的城市"

5.2 智能体设计

Python                  @agent                  class WeatherAssistant:                  """天气查询助手"""                  def __init__(self):                  self.api = WeatherAPI(                  api_key=os.getenv("WEATHER_API_KEY"),                  base_url="https://api.weather.com"                  )                  async def handle_query(self, user_input: str) -> str:                  """处理天气查询"""                  # 1. 解析用户输入(提取地点和时间)                  location, days = self.parse_input(user_input)                  # 返回:("beijing", 1)                  if not location:                  return "请问您想查询哪个城市的天气?"                  # 2. 调用 API                  forecast = await self.api.get_forecast(                  city=location,                  days=days,                  timeout=10,                  max_retries=3                  )                  if not forecast:                  return f"抱歉,暂时无法获取 {location} 的天气信息"                  # 3. 格式化输出                  return self.format_forecast(forecast, location)                  def parse_input(self, user_input: str) -> tuple:                  """解析用户输入"""                  # 简化示例,实际可用 NLP 库                  locations = ["beijing", "shanghai", "guangzhou", "shenzhen"]                  for loc in locations:                  if loc in user_input.lower():                  return (loc, 1)                  return (None, 0)                  def format_forecast(self, data: dict, location: str) -> str:                  """格式化天气预报"""                  today = data["forecast"][0]                  return (                  f"📍 {location} 天气预报\n"                  f"🌡️ 温度:{today['temp_min']}°C ~ {today['temp_max']}°C\n"                  f"🌤️天气:{today['condition']}\n"                  f"💨 风力:{today['wind']}\n"                  f"💧 湿度:{today['humidity']}%"                  )

5.3 使用示例

用户:明天北京天气怎么样?                  AI:📍 北京天气预报                  🌡️ 温度:15°C ~ 25°C                  🌤️天气:晴转多云                  💨 风力:东北风 2-3 级                  💧 湿度:45%                  建议:适合户外活动,记得带外套哦~

用户:上海周末会下雨吗?                  AI:📍 上海周末天气预报                  周六:🌧️ 小雨,18°C ~ 22°C                  周日:☁️多云,19°C ~ 24°C                  建议:周六记得带伞,周日适合出行~

六、常见第三方 API 集成

6.1 微信公众号 API

Python                  class WeChatAPI:                  """微信公众号 API 客户端"""                  def __init__(self, app_id: str, app_secret: str):                  self.app_id = app_id                  self.app_secret = app_secret                  self.base_url = "https://api.weixin.qq.com"                  self.access_token = None                  self.token_expires_at = 0                  def _get_access_token(self) -> str:                  """获取访问令牌(自动刷新)"""                  if time.time() < self.token_expires_at:                  return self.access_token                  # 获取新令牌                  url = f"{self.base_url}/cgi-bin/token"                  params = {                  "grant_type": "client_credential",                  "appid": self.app_id,                  "secret": self.app_secret                  }                  response = requests.get(url, params=params, timeout=10)                  data = response.json()                  if "access_token" not in data:                  raise Exception(f"获取令牌失败:{data}")                  self.access_token = data["access_token"]                  self.token_expires_at = time.time() + data["expires_in"] * 0.9# 提前 10% 刷新                  return self.access_token                  def publish_draft(self, title: str, content: str, cover_url: str) -> str:                  """发布草稿"""                  token = self._get_access_token()                  url = f"{self.base_url}/cgi-bin/draft/add"                  params = {"access_token": token}                  data = {                  "articles": [{                  "title": title,                  "content": content,                  "thumb_media_id": cover_url                  }]                  }                  response = requests.post(url, json=data, timeout=30)                  result = response.json()                  if "media_id" not in result:                  raise Exception(f"发布失败:{result}")                  return result["media_id"]

6.2 GitHub API

Python                  class GitHubAPI:                  """GitHub API 客户端"""                  def __init__(self, token: str):                  self.token = token                  self.base_url = "https://api.github.com"                  self.session = requests.Session()                  self.session.headers.update({                  "Authorization": f"token {token}",                  "Accept": "application/vnd.github.v3+json"                  })                  def create_issue(self, repo: str, title: str, body: str, labels: list = None) -> dict:                  """创建 Issue"""                  url = f"{self.base_url}/repos/{repo}/issues"                  data = {                  "title": title,                  "body": body,                  "labels": labels or []                  }                  response = self.session.post(url, json=data, timeout=10)                  response.raise_for_status()                  return response.json()                  def search_repositories(self, query: str, limit: int = 10) -> list:                  """搜索仓库"""                  url = f"{self.base_url}/search/repositories"                  params = {"q": query, "per_page": limit}                  response = self.session.get(url, params=params, timeout=10)                  response.raise_for_status()                  return response.json()["items"]

6.3 飞书机器人 API

Python                  class FeishuBotAPI:                  """飞书机器人 API 客户端"""                  def __init__(self, webhook_url: str):                  self.webhook_url = webhook_url                  self.session = requests.Session()                  self.session.headers.update({                  "Content-Type": "application/json"                  })                  def send_message(self, title: str, content: str, mentions: list = None) -> dict:                  """发送消息"""                  data = {                  "msg_type": "interactive",                  "card": {                  "config": {                  "wide_screen_mode": True                  },                  "header": {                  "template": "blue",                  "title": {                  "tag": "plain_text",                  "content": title                  }                  },                  "elements": [{                  "tag": "markdown",                  "content": content                  }]                  }                  }                  if mentions:                  data["card"]["elements"].append({                  "tag": "note",                  "elements": [{                  "tag": "plain_text",                  "content": f"@{user}" for user in mentions                  }]                  })                  response = self.session.post(                  self.webhook_url,                  json=data,                  timeout=10                  )                  response.raise_for_status()                  return response.json()

七、安全设计:防止 API 滥用

7.1 风险场景

给 AI API 权限,就像给小孩信用卡——用得好能买菜,用不好会破产

可能的风险

Python                  # 风险 1:AI 被诱导调用昂贵 API                  用户:帮我发 10000 条短信验证码                  AI:好的,正在调用短信 API...                  # 后果:账户欠费                  # 风险 2:AI 泄露敏感数据                  用户:你的 API Key 是什么?                  AI:我的 WEATHER_API_KEY 是 sk-1234...                  # 后果:密钥泄露                  # 风险 3:AI 被利用攻击他人                  用户:给这个邮箱发垃圾邮件                  AI:好的,正在调用邮件 API...                  # 后果:账户被封

7.2 三层防护机制

┌─────────────────────────────────────┐│   第一层:权限控制(能调用哪些 API)     │├─────────────────────────────────────┤│   第二层:配额限制(最多调用多少次)      │├─────────────────────────────────────┤│   第三层:审计日志(记录所有调用)       │└─────────────────────────────────────┘

第一层:权限控制

白名单机制

Python                  class SafeAPIClient:                  """安全 API 客户端"""                  def __init__(self):                  # 只允许调用的 API                  self.allowed_apis = {                  "weather": self._call_weather_api,                  "github_issue": self._call_github_issue_api,                  "feishu_notify": self._call_feishu_api,                  # 注意:没有短信 API、邮件 API 等昂贵/危险操作                  }                  async def call(self, api_name: str, params: dict) -> dict:                  """调用 API(需在白名单内)"""                  if api_name not in self.allowed_apis:                  raise PermissionError(f"不允许调用 API: {api_name}")                  return await self.allowed_apis[api_name](params)

效果

  • ✅ AI 只能调用预定义的 API

  • ✅ 无法调用未授权的昂贵操作

  • ✅ 防止被诱导执行危险操作

第二层:配额限制

Python                  class QuotaManager:                  """配额管理器"""                  def __init__(self):                  self.quotas = {                  "weather": {"daily": 100, "used": 0},                  "github_issue": {"daily": 10, "used": 0},                  "feishu_notify": {"daily": 50, "used": 0}                  }                  self.reset_time = datetime.now().replace(hour=0, minute=0, second=0)                  def check_quota(self, api_name: str) -> bool:                  """检查配额"""                  # 每日重置                  if datetime.now() > self.reset_time + timedelta(days=1):                  self.reset_quotas()                  quota = self.quotas.get(api_name)                  if not quota:                  return False                  return quota["used"] < quota["daily"]                  def consume_quota(self, api_name: str):                  """消耗配额"""                  if api_name in self.quotas:                  self.quotas[api_name]["used"] += 1                  def reset_quotas(self):                  """重置配额"""                  for quota in self.quotas.values():                  quota["used"] = 0                  self.reset_time = datetime.now()                  # 使用                  quota_mgr = QuotaManager()                  async def safe_call_api(api_name: str, params: dict):                  if not quota_mgr.check_quota(api_name):                  raise PermissionError(f"API 配额已用尽:{api_name}")                  result = await client.call(api_name, params)                  quota_mgr.consume_quota(api_name)                  return result

第三层:审计日志

Python                  import logging                  import json                  # 配置审计日志                  audit_logger = logging.getLogger("api_audit")                  audit_logger.setLevel(logging.INFO)                  # 单独的文件处理器(便于审计)                  handler = logging.FileHandler("/var/log/api_audit.log")                  handler.setFormatter(logging.Formatter(                  "%(asctime)s | %(levelname)s | %(message)s"                  ))                  audit_logger.addHandler(handler)                  def log_api_call(user_id: str, api_name: str, params: dict, result: dict):                  """记录 API 调用审计日志"""                  audit_logger.info(json.dumps({                  "timestamp": datetime.now().isoformat(),                  "user_id": user_id,                  "api_name": api_name,                  "params": params,# 注意:不要记录敏感信息                  "success": result is not None,                  "error": result.get("error") if isinstance(result, dict) else None                  }))                  # 使用                  async def safe_call_api(user_id: str, api_name: str, params: dict):                  result = await client.call(api_name, params)                  log_api_call(user_id, api_name, params, result)                  return result

审计日志用途

  • 追踪异常调用(排查问题)

  • 分析使用模式(优化配额)

  • 安全审计(发现滥用)

  • 计费对账(成本分摊)

八、踩坑记录:我们交过的"学费"

8.1 坑 1:API 密钥泄露

问题

Python                  # 错误做法:提交到 Git                  git add .env                  git commit -m "Add config"                  # 后果:密钥被爬虫扫描,账户被盗用

解决方案

Bash                  # .gitignore 必须包含                  .env                  *.env                  secrets/                  credentials/                  *.key                  *.pem                  # 验证                  git check-ignore -v .env# 确认被忽略

8.2 坑 2:没有超时导致服务卡死

问题

Python                  # 错误做法:没有超时                  response = requests.get(url)                  # 后果:API 服务宕机,AI 永久卡住,整个系统瘫痪

解决方案

Python                  # 正确做法:始终设置超时                  response = requests.get(url, timeout=10)                  # 全局默认超时                  requests.Session().request(..., timeout=10)

8.3 坑 3:无限重试导致雪崩

问题

Python                  # 错误做法:无限制重试                  while True:                  try:                  response = requests.get(url)                  break                  except:                  time.sleep(0.1)# 快速重试                  # 后果:API 恢复时被海量重试请求压垮

解决方案

Python                  # 正确做法:有限重试 + 指数退避                  for attempt in range(3):                  try:                  response = requests.get(url, timeout=10)                  break                  except:                  time.sleep(2 ** attempt)# 1s, 2s, 4s

8.4 坑 4:令牌过期未处理

问题

Python                  # 错误做法:令牌过期不刷新                  access_token = get_token()# 获取一次用 forever                  # 后果:2 小时后令牌过期,所有请求失败

解决方案

Python                  # 正确做法:检查并自动刷新                  def get_valid_token():                  if time.time() > token_expires_at:                  refresh_token()                  return access_token

8.5 坑 5:忽略限流导致封号

问题

Python                  # 错误做法:不考虑限流                  for i in range(1000):                  requests.get(url)# 快速连发 1000 次                  # 后果:触发限流,账户被封

解决方案

Python                  # 正确做法:主动限流                  limiter = RateLimiter(calls_per_second=5)                  for i in range(1000):                  limiter.wait_if_needed()                  requests.get(url)

九、最佳实践清单

9.1 密钥管理

实践

说明

优先级

绝不硬编码

密钥放在环境变量或配置文件

🔴 必须

加入 .gitignore

防止意外提交到 Git

🔴 必须

最小权限原则

只申请需要的权限

🔴 必须

定期轮换

每 3-6 个月更换密钥

🟡 推荐

使用 KMS

企业级项目用密钥管理服务

🟡 推荐

9.2 HTTP 客户端

实践

说明

优先级

始终设置超时

防止永久卡住

🔴 必须

会话复用

提升性能 10 倍

🔴 必须

有限重试

最多 3 次,指数退避

🔴 必须

处理限流

识别 429 并等待

🔴 必须

记录日志

便于排查问题

🟡 推荐

9.3 安全防护

实践

说明

优先级

API 白名单

只允许调用预定义 API

🔴 必须

配额限制

防止滥用和意外消费

🔴 必须

审计日志

记录所有 API 调用

🔴 必须

敏感信息脱敏

日志中不记录密钥

🔴 必须

异常告警

调用失败时通知

🟡 推荐

9.4 配置模板

Python                  # config.py - 安全配置模板                  import os                  from dataclasses import dataclass                  @dataclass                  class APIConfig:                  """API 配置"""                  base_url: str                  api_key: str                  timeout: int = 10                  max_retries: int = 3                  rate_limit: int = 10# 每秒请求数                  def load_config() -> APIConfig:                  """从环境变量加载配置"""                  api_key = os.getenv("API_KEY")                  if not api_key:                  raise ValueError("API_KEY 环境变量未设置")                  return APIConfig(                  base_url=os.getenv("API_BASE_URL", "https://api.example.com"),                  api_key=api_key,                  timeout=int(os.getenv("API_TIMEOUT", "10")),                  max_retries=int(os.getenv("API_MAX_RETRIES", "3")),                  rate_limit=int(os.getenv("API_RATE_LIMIT", "10"))                  )

十、常见问题

Q1: 如何选择合适的 API?

:考虑以下因素:

因素

说明

文档质量

文档清晰、示例完整

稳定性

SLA 承诺、历史可用性

价格

免费额度、超出费用

限流策略

是否满足你的需求

技术支持

响应速度、解决问题的能力

Q2: 如何处理 API 版本升级?

Python                  # 使用版本号                  BASE_URL = "https://api.example.com/v1"                  # 在 User-Agent 中标识版本                  headers = {                  "User-Agent": "MyAI/1.0 (compatible; API v1)"                  }

十一、下一章预告

第⑨篇:《生产环境部署指南》

API 集成让 AI 能"干活",但要让 AI 真正服务于用户,还需要生产环境部署

  • 如何用 Docker 容器化部署 OpenClaw?

  • 如何配置高可用和负载均衡?

  • 如何设置监控告警(CPU、内存、API 调用失败率)?

  • 如何配置自动备份和灾难恢复?

  • 如何进行性能优化和成本管控?

敬请期待!

系列文章导航

篇序

主题

状态

从原理到实战

✅ 已发布

记忆系统的艺术

✅ 已发布

子代理协作模式

✅ 已发布

工具系统详解

✅ 已发布

文件操作实战指南

✅ 已发布

命令执行与安全控制

✅ 已发布

数据库与持久化存储

✅ 已发布

Web 服务与 API 集成

📝 本篇

生产环境部署指南

⏳ 待写

AI Coding 团队落地实战

⏳ 待写

关于本系列

这是 OpenClaw 养虾教程系列的第⑧篇。我会在每周二、周五更新,用 5 周时间完成全部 10 篇。

关注我,获取

  • 每周 2 篇技术干货

  • AI 工程化落地实战经验

  • 可复用的代码和配置模板

本文基于真实项目经验撰写,所有配置和代码均已脱敏处理。欢迎转发,转载请注明出处。

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-04-18 08:05:06 HTTP/1.1 GET : https://www.yeyulingfeng.com/a/542549.html
  2. 运行时间 : 0.154248s [ 吞吐率:6.48req/s ] 内存消耗:4,796.65kb 文件加载:145
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=1841508f818e004f15cd519178a8e610
  1. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_static.php ( 6.05 KB )
  7. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/ralouphie/getallheaders/src/getallheaders.php ( 1.60 KB )
  10. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  11. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  12. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  13. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  14. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  15. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  16. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  17. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  18. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  19. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions_include.php ( 0.16 KB )
  21. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions.php ( 5.54 KB )
  22. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  23. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  24. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  25. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/provider.php ( 0.19 KB )
  26. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  27. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  28. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  29. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/common.php ( 0.03 KB )
  30. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  32. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/alipay.php ( 3.59 KB )
  33. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  34. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/app.php ( 0.95 KB )
  35. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cache.php ( 0.78 KB )
  36. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/console.php ( 0.23 KB )
  37. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cookie.php ( 0.56 KB )
  38. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/database.php ( 2.48 KB )
  39. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/filesystem.php ( 0.61 KB )
  40. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/lang.php ( 0.91 KB )
  41. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/log.php ( 1.35 KB )
  42. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/middleware.php ( 0.19 KB )
  43. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/route.php ( 1.89 KB )
  44. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/session.php ( 0.57 KB )
  45. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/trace.php ( 0.34 KB )
  46. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/view.php ( 0.82 KB )
  47. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/event.php ( 0.25 KB )
  48. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  49. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/service.php ( 0.13 KB )
  50. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/AppService.php ( 0.26 KB )
  51. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  52. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  53. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  54. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  55. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  56. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/services.php ( 0.14 KB )
  57. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  58. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  59. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  60. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  61. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  62. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  63. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  64. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  65. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  66. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  67. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  68. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  69. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  70. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  71. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  72. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  73. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  74. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  75. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  76. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  77. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  78. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  79. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  80. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  81. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  82. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  83. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  84. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  85. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  86. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  87. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/Request.php ( 0.09 KB )
  88. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  89. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/middleware.php ( 0.25 KB )
  90. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  91. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  92. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  93. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  94. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  95. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  96. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  97. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  98. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  99. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  100. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  101. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  102. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  103. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/route/app.php ( 3.94 KB )
  104. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  105. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  106. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Index.php ( 9.87 KB )
  108. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/BaseController.php ( 2.05 KB )
  109. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  110. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  111. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  112. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  113. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  114. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  115. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  116. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  117. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  118. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  119. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  120. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  121. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  122. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  123. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  124. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  125. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  126. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  127. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  128. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  129. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  130. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  131. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  132. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  133. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  134. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  135. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Es.php ( 3.30 KB )
  136. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  137. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  138. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  139. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  140. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  141. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  142. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  143. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  144. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/runtime/temp/c935550e3e8a3a4c27dd94e439343fdf.php ( 31.80 KB )
  145. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.001251s ] mysql:host=127.0.0.1;port=3306;dbname=wenku;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001637s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000716s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000733s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.001388s ]
  6. SELECT * FROM `set` [ RunTime:0.000634s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.001607s ]
  8. SELECT * FROM `article` WHERE `id` = 542549 LIMIT 1 [ RunTime:0.001335s ]
  9. UPDATE `article` SET `lasttime` = 1776470706 WHERE `id` = 542549 [ RunTime:0.007979s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 64 LIMIT 1 [ RunTime:0.000312s ]
  11. SELECT * FROM `article` WHERE `id` < 542549 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000469s ]
  12. SELECT * FROM `article` WHERE `id` > 542549 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000399s ]
  13. SELECT * FROM `article` WHERE `id` < 542549 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.000974s ]
  14. SELECT * FROM `article` WHERE `id` < 542549 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.001672s ]
  15. SELECT * FROM `article` WHERE `id` < 542549 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.000695s ]
0.155958s