|
@@ -75,6 +75,8 @@ class Api
|
|
|
|
|
|
// 控制器初始化
|
|
// 控制器初始化
|
|
$this->_initialize();
|
|
$this->_initialize();
|
|
|
|
+ //日志
|
|
|
|
+ $this->request_log();
|
|
|
|
|
|
// 前置操作方法
|
|
// 前置操作方法
|
|
if ($this->beforeActionList) {
|
|
if ($this->beforeActionList) {
|
|
@@ -360,5 +362,36 @@ class Api
|
|
$this->request->token();
|
|
$this->request->token();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * api 请求日志
|
|
|
|
+ * */
|
|
|
|
+ protected function request_log(){
|
|
|
|
+ //api_request_log
|
|
|
|
+ $modulename = $this->request->module();
|
|
|
|
+ $controllername = $this->request->controller();
|
|
|
|
+ $actionname = $this->request->action();
|
|
|
|
+
|
|
|
|
+ $data = [
|
|
|
|
+ 'uid' => $this->auth->id,
|
|
|
|
+ 'api' => $modulename.'/'.$controllername.'/'.$actionname,
|
|
|
|
+ 'params' => json_encode($this->request->request()),
|
|
|
|
+ 'addtime' => time(),
|
|
|
|
+ 'adddatetime' => date('Y-m-d H:i:s'),
|
|
|
|
+ 'ip' => request()->ip(),
|
|
|
|
+ ];
|
|
|
|
+ $request_id = db('api_request_log')->insertGetId($data);
|
|
|
|
+ defined('API_REQUEST_ID') or define('API_REQUEST_ID', $request_id);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function request_log_update($log_result){
|
|
|
|
+ if(defined('API_REQUEST_ID')) { //记录app正常返回结果
|
|
|
|
+ if(strlen(json_encode($log_result['data'])) > 10000) {
|
|
|
|
+ $log_result['data'] = '数据太多,不记录';
|
|
|
|
+ }
|
|
|
|
+ db('api_request_log')->where('id',API_REQUEST_ID)->update(['result'=>json_encode($log_result)]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|