单独讲一下laravel跟Dingo结合编写api及api路由配置文件的作用
Laravel  /  管理员 发布于 3年前   1330
单独讲一下这个api配置文件(我的接口路由都写这里):
\vendor\wanglelecc\laracms-framework\routes\api.php
截取一些常用的配置项及其作用 做注释
$api = app('Dingo\Api\Routing\Router');
/** v1 Version API Routes */
$api->version('v1', [
//命名空间 定义我的api的控制器
'namespace' => 'Wanglelecc\Laracms\Http\Controllers\Api\V1',
'middleware' => 'serializer:array',
], function($api) {
//api分组编写 字面意思相同的写到一起 方面维护管理及控制
$api->group([
//中间件
'middleware' => 'api.throttle',
//接口频率限制 次数
'limit' => config('api.rate_limits.sign.limit'),
//接口频率限制 时间(这里是时间 分钟)
'expires' => config('api.rate_limits.sign.expires'),
], function($api){
#里面就是接口路由了
$api->post('verificationCodes', 'VerificationCodesController@store')->name('api.verificationCodes.store');# 短信验证码
$api->post('users', 'UsersController@store')->name('api.users.store');# 用户注册
$api->post('captchas', 'CaptchasController@store')->name('api.captchas.store'); # 图片验证码
$api->post('socials/{social_type}/authorizations', 'AuthorizationsController@socialStore')->name('api.socials.authorizations.store');# 第三方登录
$api->post('authorizations', 'AuthorizationsController@store')->name('api.authorizations.store');# 登录
$api->put('authorizations/current', 'AuthorizationsController@update')->name('api.authorizations.update');# 刷新token
$api->delete('authorizations/current', 'AuthorizationsController@destroy')->name('api.authorizations.destroy');# 删除token
$api->get('cardnewsarticles/{category_id}', 'CardNewsArticleController@index')->name('api.article.index');
$api->get('cardnewssearcharticles', 'CardNewsArticleController@search');
$api->get('loansnewsarticles/{category_id}', 'CardNewsArticleController@loansart')->name('api.article.loansart');
$api->get('loansnewssearcharticles', 'CardNewsArticleController@loanssearch');
# 获取区块内容
$api->get('blocks/{block_id}', 'BlockController@show')->name('api.block.show');
//评论
$api->post('comment', 'CommentController@comment')->name('api.comment.comment');
$api->get('commentpages', 'CommentController@commentpages')->name('api.comment.commentpages');
//up/dowm
$api->get('creditcardupdown', 'CommentController@creditcardupdown')->name('api.comment.creditcardupdown');
});
//第二个api分组了 可以对应不同的接口频率限制 access
$api->group([
'middleware' => 'api.throttle',
'limit' => config('api.rate_limits.access.limit'),
'expires' => config('api.rate_limits.access.expires'),], function($api) {
//AB版
$api->get('cbbab', 'DbgController@ab')->name('api.dbg.ab');
//小程序
$api->get('xcxkfstatus', 'XcxController@xcxkfstatus')->name('api.xcx.xcxkfstatus');
$api->get('topcarousel', 'XcxController@topcarousel')->name('api.xcx.topcarousel');
$api->get('centericon', 'XcxController@centericon')->name('api.xcx.centericon');
$api->get('xcxcentericonid', 'XcxController@xcxcentericonid')->name('api.xcx.xcxcentericonid');
$api->get('xcxkfxx', 'XcxController@xcxkfxx')->name('api.xcx.xcxkfxx');
$api->post('xcxkfxx', 'XcxController@xcxkfxx')->name('api.xcx.xcxkfxx');
//baidu
$api->get('bxcxkfxx', 'XcxController@bxcxkfxx')->name('api.xcx.bxcxkfxx');
$api->post('bxcxkfxx', 'XcxController@bxcxkfxx')->name('api.xcx.bxcxkfxx');
});
});
接口频率限制 (上面的分组接口频率限制 时间次数就是读这里)
配置文件路径:\config\api.php
/** 接口频率限制 */
'rate_limits' => [
// 访问频率限制,次数/分钟
'access' => [
'expires' => env('RATE_LIMITS_EXPIRES', 1),
'limit' => env('RATE_LIMITS', 600),
],
// 登录相关,次数/分钟
'sign' => [
'expires' => env('SIGN_RATE_LIMITS_EXPIRES', 1),
'limit' => env('SIGN_RATE_LIMITS', 10),
],
],
看到没有两个分组读的是 assess跟sign
assess:config('api.rate_limits.access.limit')
sign:config('api.rate_limits.sign.limit')
看一下效果:
1.默认每分钟600次
2.设置成每分钟400次
路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..博主 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 @ mashrdn 多切换几个节点测试,免费ssr是没那么稳..mashrdn 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 V2rayn免费节点添加上去了,youtobe无法打开网页,是怎么回事..张伟 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 3q!有用,不过免费节点隔天就要去git上复制新的导进去..博主 在
科学上网翻墙访问Google , 上外网神器佛跳墙VPN(永久免费)使用流程步骤中评论 该篇教程已不能用了,告知大家,免的老有老铁问我!..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号