From 17b38485fd80f60bbc39bb3903807129c5bbdaf2 Mon Sep 17 00:00:00 2001 From: qinzongqing Date: Mon, 10 Apr 2023 15:24:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/Oauth2Controller.php | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/app/controllers/Oauth2Controller.php b/app/controllers/Oauth2Controller.php index b611dcd..8039af2 100644 --- a/app/controllers/Oauth2Controller.php +++ b/app/controllers/Oauth2Controller.php @@ -66,9 +66,45 @@ class Oauth2Controller extends ControllerBase{ //获取上次请求日期 $last_req_time = $appinfo->LastReqTime; $last_req_date = date("Y-m-d", strtotime($last_req_time)); - // + //获取当前时间及当天日期 + $current_time = time(); + $current_datetime = date("Y-m-d H:i:s", $current_time); + $current_date = date("Y-m-d", $current_time); + //获取上次请求日期所在日的请求次数 + $today_req_times = $appinfo->TodayReqTimes; + //获取接口请求次数限制 + $day_max_req_times = $appinfo->DayMaxReqTimes; + //如果上次请求日期是当天日期 + if($last_req_date==$current_date){ + //如果当天请求次数已达到接口请求次数限制 + if($today_req_times>=$day_max_req_times){ + //告知用户request today reached the request limit,err detail:超过请求上限限制 + $rs['errcode'] = 80102; + $rs['errmsg'] = "request today reached the request limit,err detail:超过请求上限限制"; + $rs['data'] = null; + } + //如果当天请求次数尚未达到接口请求次数限制 + else{ + + } + } + //如果上次请求日期不是当天日期 + else{ + //如果接口请求次数限制不大于0 + if($day_max_req_times<=0){ + //告知用户request today reached the request limit,err detail:超过请求上限限制 + $rs['errcode'] = 80102; + $rs['errmsg'] = "request today reached the request limit,err detail:超过请求上限限制"; + $rs['data'] = null; + } + } + //如果以上判断都通过 + if(empty($rs['errcode'])){ + //开启事务 + $this->db->begin(); //准备更新请求次数 + } } } }