侯体宗的博客
  • 首页
  • Hyperf2.1版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

单独讲一下laravel跟Dingo结合编写api及api路由配置文件的作用

Laravel  /  管理员 发布于 2年前   846

单独讲一下这个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.png

1.默认每分钟600次

2.png

2.设置成每分钟400次

image.png


  • 上一条:
    根据不同的数字用php编程画出动态饼状图
    下一条:
    很久以前刚学php编程的时候写的单例模式理解逻辑分享一下
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • TP(3/5)
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel 9.13版本发布(0个评论)
    • Laravel角色和权限:拦截器Gates和策略Policies的解释(0个评论)
    • Laravel 9.12版本发布(0个评论)
    • laravel8框架集成RabbitMQ队列驱动程序(0个评论)
    • laravel框架应用拦截器:Laravel Gates(0个评论)
    • 近期文章
    • Laravel 9.13版本发布(0个评论)
    • beego+GeoLite2免费数据库获取ip地址经纬度等定位归属信息(0个评论)
    • redis安全配置之修改端口、添加密码流程步骤及启动使用(0个评论)
    • PHP + Memcache实现简单的统计当前在线人数功能(0个评论)
    • Thinkphp5.1框架中实现Session+Redis会话共享流程步骤(0个评论)
    • go语言中使用Signbit()函数判断一个整数是正数或负数(0个评论)
    • 删库跑路之一链家程序员删除公司9TB数据被判7年,望各大码农警之!(0个评论)
    • Laravel角色和权限:拦截器Gates和策略Policies的解释(0个评论)
    • Laravel 9.12版本发布(0个评论)
    • go语言中实现把数据写入文件函数WriteFile()编写(0个评论)
    • 近期评论
    • 博主 在

      hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 @路过的靓仔:cdn静态资源被墙,已修复..
    • GGGGGGGGG 在

      layui框架常用输入框介绍中评论 写的很好解决问题..
    • 路过的靓仔 在

      hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 剩下好多 wait 状态的..
    • 激光豆芽 在

      为什么你不能安逸?国内996为什么没有国外955香?中评论 国内现在无意义的内卷太多了..
    • 激光豆芽 在

      阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 厉害了..
    • 2016-10
    • 2016-11
    • 2017-07
    • 2017-08
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2020-10
    • 2020-11
    • 2021-01
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客