Files
geneagro_cms/doc/API.md

1.5 KiB
Raw Blame History

GeneAgro CMS API 使用与认证说明

开启与配置

  • 后台系统配置页提供 WebAPI 设置:
    • api_open是否开启接口能力
    • api_auth是否开启签名认证建议开启
    • api_appid接口用户名
    • api_secret接口密钥。

认证机制

  • 时间戳与签名:
    • 传参appid、timestamp、sign
    • 有效期timestamp 在 15 秒内有效;
    • 生成sign = md5( md5( appid + secret + timestamp ) )
    • 当 api_auth=1 且校验失败时,接口拒绝访问。
  • 示例PHP 生成签名):
    $appid = 'YOUR_APPID';
    $secret = 'YOUR_SECRET';
    $ts = time();
    $sign = md5(md5($appid . $secret . $ts));
    $url = "https://your-domain/api/list?appid={$appid}&timestamp={$ts}&sign={$sign}";
    

内置接口apps/common/route.php

  • list内容列表
  • content单条内容
  • about关于信息
  • search内容搜索
  • 具体字段取决于模型层实现,实际项目可扩展 apps/api 以提供自定义数据结构。

调用建议

  • 使用 HTTPS
  • 发起端与服务端时间同步;
  • 控制速率与并发,对搜索与列表类接口做分页与缓存(如 Memcache

错误与排查

  • 403/认证失败:检查 appid/secret 与签名算法,确认时间戳是否过期;
  • 404/路由不存在:检查 apps/common/route.php 与 config/route.php 是否定义;
  • 500/内部错误:查看 log/ 文本日志或 ay_syslog 数据库日志,定位模型/控制器异常。