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(); //准备更新请求次数 + } } } }