备份提交

This commit is contained in:
qinzongqing 2023-04-10 17:57:17 +08:00
parent 429cc6d4d7
commit c9cfc49650

View File

@ -57,9 +57,9 @@ class Oauth2Controller extends ControllerBase{
//准备判断appid是否有效 //准备判断appid是否有效
$appid = $request_arr['appid']; $appid = $request_arr['appid'];
//查询接口信息 //查询接口信息
$app_info = AppInfo::findFirst("AppId = '$appid' AND Enable = 0"); $AppInfo = AppInfo::findFirst("AppId = '$appid' AND Enable = 0");
//如果未查询到接口信息 //如果未查询到接口信息
if(empty($app_info)){ if(empty($AppInfo)){
//告知用户找不到app配置信息,appid无效,err detail:找不到app配置信息 //告知用户找不到app配置信息,appid无效,err detail:找不到app配置信息
$rs['errmsg'] = "找不到app配置信息,appid无效,err detail:找不到app配置信息"; $rs['errmsg'] = "找不到app配置信息,appid无效,err detail:找不到app配置信息";
$rs['errcode'] = 40036; $rs['errcode'] = 40036;
@ -68,16 +68,16 @@ class Oauth2Controller extends ControllerBase{
//如果有查询到接口信息 //如果有查询到接口信息
else{ else{
//获取上次请求日期 //获取上次请求日期
$last_req_time = $app_info->LastReqTime; $last_req_time = $AppInfo->LastReqTime;
$last_req_date = date("Y-m-d", strtotime($last_req_time)); $last_req_date = date("Y-m-d", strtotime($last_req_time));
//获取当前时间及当天日期 //获取当前时间及当天日期
$current_time = time(); $current_time = time();
$current_datetime = date("Y-m-d H:i:s", $current_time); $current_datetime = date("Y-m-d H:i:s", $current_time);
$current_date = date("Y-m-d", $current_time); $current_date = date("Y-m-d", $current_time);
//获取上次请求日期所在日的请求次数 //获取上次请求日期所在日的请求次数
$today_req_times = $app_info->TodayReqTimes; $today_req_times = $AppInfo->TodayReqTimes;
//获取接口请求次数限制 //获取接口请求次数限制
$day_max_req_times = $app_info->DayMaxReqTimes; $day_max_req_times = $AppInfo->DayMaxReqTimes;
//如果上次请求日期是当天日期 //如果上次请求日期是当天日期
if($last_req_date==$current_date){ if($last_req_date==$current_date){
//如果当天请求次数已达到接口请求次数限制 //如果当天请求次数已达到接口请求次数限制
@ -111,12 +111,12 @@ class Oauth2Controller extends ControllerBase{
//如果以上判断都通过 //如果以上判断都通过
if(empty($rs['errcode'])){ if(empty($rs['errcode'])){
//准备更新当天请求次数 //准备更新当天请求次数
$app_info->LastModifiedTime = $current_datetime; $AppInfo->LastModifiedTime = $current_datetime;
//更新字段 //更新字段
$app_info->TodayReqTimes = $today_req_times; $AppInfo->TodayReqTimes = $today_req_times;
$app_info->LastReqTime = $current_date; $AppInfo->LastReqTime = $current_date;
//如果更新失败 //如果更新失败
if(!($app_info->save())){ if(!($AppInfo->save())){
//告知用户系统繁忙,请稍候再试 //告知用户系统繁忙,请稍候再试
$rs['errmsg'] = "系统繁忙,请稍候再试"; $rs['errmsg'] = "系统繁忙,请稍候再试";
$rs['errcode'] = -1; $rs['errcode'] = -1;
@ -124,27 +124,27 @@ class Oauth2Controller extends ControllerBase{
} }
//如果更新成功 //如果更新成功
else{ else{
//查询当前接口今天是否有生成过code //查询当前接口过去是否有生成过code
$temp_code = TempCode::findFirst("AppId = '$appid'"); $TempCode = TempCode::findFirst("AppId = '$appid'");
//如果当前接口过去未生成过code //如果当前接口过去未生成过code
if(empty($temp_code)){ if(empty($TempCode)){
//准备新增临时code //准备新增临时code
$temp_code = new TempCode(); $TempCode = new TempCode();
$temp_code->AppId = $appid; $TempCode->AppId = $appid;
$temp_code->CreateTime = $current_datetime; $TempCode->CreateTime = $current_datetime;
$temp_code->LastModifiedTime = $current_datetime; $TempCode->LastModifiedTime = $current_datetime;
} }
//如果当前接口过去有生成过code //如果当前接口过去有生成过code
else{ else{
//准备更新临时code //准备更新临时code
$temp_code->LastModifiedTime = $current_datetime; $TempCode->LastModifiedTime = $current_datetime;
} }
//更新字段 //更新字段
$temp_code->Code = $code = $this->_get_act_code(32); $TempCode->Code = $code = $this->_get_act_code(32);
$temp_code->IsUsed = 0; $TempCode->IsUsed = 0;
$temp_code->ExpireTime = date("Y-m-d H:i:s", $current_time+300); $TempCode->ExpireTime = date("Y-m-d H:i:s", $current_time+300);
//如果保存失败 //如果保存失败
if(!($temp_code->save())){ if(!($TempCode->save())){
//告知用户系统繁忙,请稍候再试 //告知用户系统繁忙,请稍候再试
$rs['errmsg'] = "系统繁忙,请稍候再试"; $rs['errmsg'] = "系统繁忙,请稍候再试";
$rs['errcode'] = -1; $rs['errcode'] = -1;
@ -212,9 +212,9 @@ class Oauth2Controller extends ControllerBase{
//准备判断appid是否有效 //准备判断appid是否有效
$appid = $request_arr['appid']; $appid = $request_arr['appid'];
//查询接口信息 //查询接口信息
$app_info = AppInfo::findFirst("AppId = '$appid' AND Enable = 0"); $AppInfo = AppInfo::findFirst("AppId = '$appid' AND Enable = 0");
//如果未查询到接口信息 //如果未查询到接口信息
if(empty($app_info)){ if(empty($AppInfo)){
//告知用户找不到app配置信息,appid无效,err detail:找不到app配置信息 //告知用户找不到app配置信息,appid无效,err detail:找不到app配置信息
$rs['errmsg'] = "找不到app配置信息,appid无效,err detail:找不到app配置信息"; $rs['errmsg'] = "找不到app配置信息,appid无效,err detail:找不到app配置信息";
$rs['errcode'] = 40036; $rs['errcode'] = 40036;
@ -223,16 +223,16 @@ class Oauth2Controller extends ControllerBase{
//如果有查询到接口信息 //如果有查询到接口信息
else{ else{
//获取上次请求日期 //获取上次请求日期
$last_req_time = $app_info->LastReqTime; $last_req_time = $AppInfo->LastReqTime;
$last_req_date = date("Y-m-d", strtotime($last_req_time)); $last_req_date = date("Y-m-d", strtotime($last_req_time));
//获取当前时间及当天日期 //获取当前时间及当天日期
$current_time = time(); $current_time = time();
$current_datetime = date("Y-m-d H:i:s", $current_time); $current_datetime = date("Y-m-d H:i:s", $current_time);
$current_date = date("Y-m-d", $current_time); $current_date = date("Y-m-d", $current_time);
//获取上次请求日期所在日的请求次数 //获取上次请求日期所在日的请求次数
$today_req_times = $app_info->TodayReqTimes; $today_req_times = $AppInfo->TodayReqTimes;
//获取接口请求次数限制 //获取接口请求次数限制
$day_max_req_times = $app_info->DayMaxReqTimes; $day_max_req_times = $AppInfo->DayMaxReqTimes;
//如果上次请求日期是当天日期 //如果上次请求日期是当天日期
if($last_req_date==$current_date){ if($last_req_date==$current_date){
//如果当天请求次数已达到接口请求次数限制 //如果当天请求次数已达到接口请求次数限制
@ -266,12 +266,12 @@ class Oauth2Controller extends ControllerBase{
//如果以上判断都通过 //如果以上判断都通过
if(empty($rs['errcode'])){ if(empty($rs['errcode'])){
//准备更新当天请求次数 //准备更新当天请求次数
$app_info->LastModifiedTime = $current_datetime; $AppInfo->LastModifiedTime = $current_datetime;
//更新字段 //更新字段
$app_info->TodayReqTimes = $today_req_times; $AppInfo->TodayReqTimes = $today_req_times;
$app_info->LastReqTime = $current_date; $AppInfo->LastReqTime = $current_date;
//如果更新失败 //如果更新失败
if(!($app_info->save())){ if(!($AppInfo->save())){
//告知用户系统繁忙,请稍候再试 //告知用户系统繁忙,请稍候再试
$rs['errmsg'] = "系统繁忙,请稍候再试"; $rs['errmsg'] = "系统繁忙,请稍候再试";
$rs['errcode'] = -1; $rs['errcode'] = -1;
@ -282,7 +282,7 @@ class Oauth2Controller extends ControllerBase{
//准备判断appsecrect是否匹配 //准备判断appsecrect是否匹配
$appsecrect = $request_arr['appsecrect']; $appsecrect = $request_arr['appsecrect'];
//如果appsecrect不匹配 //如果appsecrect不匹配
if($appsecrect!=$app_info->AppSecret){ if($appsecrect!=$AppInfo->AppSecret){
//告知用户密钥不匹配,err detail:密钥不匹配 //告知用户密钥不匹配,err detail:密钥不匹配
$rs['errmsg'] = "密钥不匹配,err detail:密钥不匹配"; $rs['errmsg'] = "密钥不匹配,err detail:密钥不匹配";
$rs['errcode'] = 40037; $rs['errcode'] = 40037;
@ -293,9 +293,9 @@ class Oauth2Controller extends ControllerBase{
//准备判断code是否匹配 //准备判断code是否匹配
$code = $request_arr['code']; $code = $request_arr['code'];
//查询临时code //查询临时code
$temp_code = TempCode::findFirst("AppId = '$appid' AND Code = '$code'"); $TempCode = TempCode::findFirst("AppId = '$appid' AND Code = '$code'");
//如果未查询到临时code //如果未查询到临时code
if(empty($temp_code)){ if(empty($TempCode)){
//告知用户code 不正确,err detail:code 不匹配 //告知用户code 不正确,err detail:code 不匹配
$rs['errmsg'] = "code 不正确,err detail:code 不匹配"; $rs['errmsg'] = "code 不正确,err detail:code 不匹配";
$rs['errcode'] = 40038; $rs['errcode'] = 40038;
@ -304,7 +304,7 @@ class Oauth2Controller extends ControllerBase{
//如果有查询到临时code //如果有查询到临时code
else{ else{
//准备判断code是否已失效 //准备判断code是否已失效
$expire_time = $temp_code->ExpireTime; $expire_time = $TempCode->ExpireTime;
//如果code已失效 //如果code已失效
if($current_datetime>=$expire_time){ if($current_datetime>=$expire_time){
//告知用户authorize code is expired,err detail:code 已过期 //告知用户authorize code is expired,err detail:code 已过期
@ -315,7 +315,7 @@ class Oauth2Controller extends ControllerBase{
//如果code未失效 //如果code未失效
else{ else{
//准备判断code是否已使用过 //准备判断code是否已使用过
$is_used = $temp_code->IsUsed; $is_used = $TempCode->IsUsed;
//如果code已使用过 //如果code已使用过
if(!empty($is_used)){ if(!empty($is_used)){
//告知用户 //告知用户
@ -325,7 +325,40 @@ class Oauth2Controller extends ControllerBase{
} }
//如果code未使用过 //如果code未使用过
else{ else{
//查询当前接口过去是否有生成过access_token
$AccessToken = AccessToken::findFirst("AppId = $appid");
//如果当前接口过去未生成过access_token
if(empty($AccessToken)){
//准备新增AccessToken
$AccessToken = new AccessToken();
$AccessToken->AppId = $appid;
$AccessToken->CreateTime = $current_datetime;
$AccessToken->LastModifiedTime = $current_datetime;
}
//如果当前接口过去有生成过access_token
else{
//准备更新AccessToken
$AccessToken->LastModifiedTime = $current_datetime;
}
//更新字段
$AccessToken->Code = $code = $this->_get_act_code(32);
$AccessToken->IsUsed = 0;
$AccessToken->ExpireTime = date("Y-m-d H:i:s", $current_time+300);
//如果保存失败
if(!($AccessToken->save())){
//告知用户系统繁忙,请稍候再试
$rs['errmsg'] = "系统繁忙,请稍候再试";
$rs['errcode'] = -1;
$rs['data'] = null;
}
//如果保存成功
else{
//告知用户ok
$rs['errmsg'] = "ok";
$rs['errcode'] = 0;
$rs['data']['access_token'] = $access_token;
$rs['data']['expire_in'] = 14400;
}
} }
} }
} }