Download the PHP package wiseadmin/wise-api without Composer
On this page you can find all versions of the php package wiseadmin/wise-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wiseadmin/wise-api
More information about wiseadmin/wise-api
Files in wiseadmin/wise-api
Package wise-api
Short Description WiseAdmin API 快速开发工具包 — 提供限流、签名验证、JWT 鉴权、统一响应格式、调试面板与 API 日志记录能力
License Apache-2.0
Homepage https://github.com/hiwiseadmin/wise-api
Informations about the package wise-api
wiseadmin/wise-api
为 ThinkPHP 6.0+ 或 8.0+ 提供的 API 快速开发工具包——开箱即用的限流、签名、JWT 鉴权、统一响应、字段过滤与分页包装、Debug 模式调试面板。
特性
| 模块 | 说明 |
|---|---|
| API 版本管理 | 通过 URL 前缀 api/v1、api/v2 自动路由到不同子命名空间 |
| 接口限流 | 令牌桶 + 滑动窗口双算法,原生 Redis Lua 脚本保证原子性 |
| 签名验证 | HMAC-SHA256,支持时间戳防重放 + Nonce 防重放 |
| JWT 鉴权 | 纯 PHP 实现 HS256/RS256,零外部依赖,支持自动续签 |
| 统一响应 | {code, msg, data, timestamp} 结构,错误码枚举 |
| 字段过滤 | ?fields=id,name + allowFields() 显式过滤 |
| 统一分页 | {list, total, page, page_size} 自动包装 |
| 调试面板 | Debug 模式下记录耗时、内存、限流状态、JWT、签名过程、SQL 日志 |
安装
包通过 composer.json 的 extra.think.services 自动注册服务提供者,无需手动配置。
配置
将 vendor/wiseadmin/wise-api/config/wise-api.php 复制到项目 config/ 目录后按需修改:
基础用法
1. 控制器继承 ApiController
2. 路由(API 版本管理)
业务请求 /api/v1/users 自动路由到 app\api\controller\v1\UserController。
增加 /api/v2/users 只需新建 app\api\controller\v2\UserController + app/api/route/v2.php。
3. JWT 签发与解析
4. 在控制器获取当前登录用户
5. 手动签名(供业务方主动签名时复用)
6. 限流分组
匹配到分组时,相应 API 自动使用分组配置;未匹配时使用 default。
7. 自动续签
JwtAuthMiddleware 在剩余有效期 < refresh_ttl 时,会在响应头自动添加:
客户端在 axios/fetch 拦截器中替换本地 token 即可。
调试面板(仅 Debug 模式)
启动应用时调用 app()->isDebug() 必须为 true。启用后:
- 每次请求的 Header 中附带
X-Debug-Info(base64 编码的 JSON) - 访问
GET /__debug_api返回最近一次请求的完整调试快照 - 包含:耗时、内存、限流状态、JWT payload、签名原始串与本地计算结果、SQL 日志
生产环境
app()->isDebug()为 false 时,/__debug_api路由自动不注册。
架构概览
错误码
| Code | HTTP | 含义 |
|---|---|---|
| 0 | 200 | 成功 |
| 1000 | 500 | 未知错误 |
| 1001 | 400 | 参数无效 |
| 2000 | 401 | 未鉴权 |
| 2001 | 401 | Token 无效 |
| 2002 | 401 | Token 过期 |
| 2100 | 400 | 签名错误 |
| 2101 | 400 | 时间戳超出容差 |
| 2102 | 400 | Nonce 重复 |
| 2200 | 403 | 无权限 |
| 3000 | 429 | 触发限流 |
| 4001 | 404 | 数据不存在 |
| 4002 | 409 | 数据冲突 |
| 9000 | 502 | 上游错误 |
License
MIT
All versions of wise-api with dependencies
topthink/framework Version ^8.0
psr/log Version ^1.1 || ^2.0 || ^3.0
wiseadmin/wise-jwt Version 1.0.*
wiseadmin/wise-support Version 1.0.*
ext-json Version *