123,'password'=>456]){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ $data = input('post.'); } if(!array_key_exists('account', $data) && !array_key_exists('password', $data)){ return $this->msg(10001); } $return_data = $this->login_action($data); // 成功 $this->record_api_log($data, null, $return_data); return $return_data; } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); $logContent["line"] = $e->getLine(); $logContent['all_content'] = "异常信息:\n"; $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); return $this->msg(99999); } } public function login_api($data = ['account'=>123,'password'=>456]){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ $data = input('post.'); } if(!array_key_exists('account', $data) && !array_key_exists('password', $data)){ return $this->msg(10001); } $return_data = $this->login_action($data); // 成功 $this->record_api_log($data, null, $return_data); return $return_data; } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); $logContent["line"] = $e->getLine(); $logContent['all_content'] = "异常信息:\n"; $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); return $this->msg(99999); } } #######################################################################action####################################################################### public function login_action($data){ // dump($data); $user = Db::table('admin_user_account_number')->where(["account_num"=>$data['account'],'password'=>$data['password']])->find(); // dump($user); // die; if($user){ return $this->msg(['token'=>$user['token']]); }else{ return $this->msg(10004); } } }