-
Notifications
You must be signed in to change notification settings - Fork 66
Configuration
Zewail edited this page Sep 11, 2018
·
1 revision
该扩展包共有3个配置文件
-
api.php:管理接口配置 -
resources.php:过滤管理器配置 -
jwt.php:JWT相关配置
配置文件可以在vendor/zewail/think-api/config目录下找到,也可以手动创建它们
retrun [
//配置项
];api的默认版本
api返回的数据格式,可选:
-
DataArray:数组带data格式,默认值// item { 'data': [...], 'meta': [...], ... } // collection { 'data': [ {...}, {...}, {...}, ], 'meta': [...], ... } -
Array:数组格式// item { 'item_field1': '...', 'item_field2': '...', 'meta': [...], ... } // collection { [ {...}, {...}, ], 'meta': [...], ... }
retrun [ //配置项 // 用户相关接口 // 例如设置一些用户的相关接口资源 'user.age' => ['id', 'name', 'age'], 'user.mobile' => ['id', 'name', 'mobile'], ];
该配置文件用于数据过滤管理,在返回接口数据的时候在item collection paginator第二个参数传入该标识来使用
// 返回{'data': {'id':1, 'name': 'xiaoming', 'age': 20}} return $this->response->item($user, 'user.age'); // 返回{'data': {'id':1, 'name': 'xiaoming', 'mobile': '13777777777'}} return $this->response->item($user, 'user.mobile');
retrun [
//配置项
];token的过期时间, 默认为120分钟,单位分钟
允许误差时间,默认为60秒,单位秒
加密算法,支持:
-
HS256:HMAC 使用 SHA-256 算法加密 -
HS512:HMAC 使用 SHA-512 算法加密 -
RS256:RSA 使用 SHA-256 算法加密
如果使用了HMAC加密方式,则需要配置该项,为自定义字符串
如果使用了RSA加密方式,则需要配置该项,为.pem结尾的私钥文件路径
如果使用了RSA加密方式,则需要配置该项,为.pem结尾的公钥文件路径
如果需要使用用户操作相关方法,则需定义该项,为用户模型所在路径,如
'user' => app\index\model\User::class,