<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ```` <?php /** * api基類,添加用于所有api控制器的方法 * @author ianzhi * @date 2018-06-20 */ namespace app\ninty9api\controller; use app\ninty9api\service\Token as TokenService; use app\admin\model\Nintyuser; use app\admin\model\User; use app\admin\model\Trainer; class Api { /** * @var array 用于記錄不需要token驗證的方法,將方法名放進數組即可 */ protected $no_need_token = [ ]; /** * Api constructor. * @throws \think\exception\DbException */ public function __construct() { // 公共響應頭 header('Content-Type:Application/json'); // 如果需要跨域,寫在這里 header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Headers:x-token,user-type,Origin, Access-Control-Request-Headers, SERVER_NAME, Access-Control-Allow-Headers, cache-control, token, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE'); // 驗證用戶登陸 $user_type = request()->header('user-type'); $action = request()->dispatch()['module'][2] ?: 'index'; if (request()->method() == 'OPTIONS') { exit(); } // 攔截器(放行數組中的方法) // if (!in_array($action, $this->no_need_token)) { // if ($user_type == 'admin') { // $token = request()->header('x-token'); // $user = User::get(['api_token'=>$token]); // request()->bind('user', $user); // } else { // $uid = TokenService::getCurrentUid(); // if (!is_numeric($uid) || $uid == 0) { // $this->success([], 'token不存在,請重新獲取!', 401); // } else { // if ($user_type == 'trainer') { // $user = Trainer::get($uid); // } else { // $user = NintyUser::get($uid); // } // request()->bind('user', $user); // } // } // } } /** * 用于成功返回 * @param array $data 響應的數據 * @param string $message 響應信息 * @param int $code 響應碼 * @param array $headers 特殊的響應頭信息 */ public function success($data=[], $message='請求成功!', $code=200, $headers=[]) { // 添加自定義頭 if ($headers) { foreach ($headers as $header_key=>$header_value) { header($header_key . ':' . $header_value); } } // 構造響應內容 $return_data = [ 'code' => $code, 'message' => $message ]; if ($data) { $return_data['data'] = $data; } echo json_encode($return_data, JSON_UNESCAPED_UNICODE); exit; } }
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看