<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                cd /www/wwwroot/tpapi php think build api ``` <?php declare (strict_types = 1); namespace app\api\controller; use app\api\BaseController; use app\api\middleware\Auth; use app\api\service\JwtAuth; use think\facade\Db; use think\facade\Request; class Index extends BaseController { /** * 控制器中間件 [登錄、注冊 不需要鑒權] * @var array */ protected $middleware = [ Auth::class => ['except' => ['index','login','reg'] ] ]; /** * @api {post} /index/index API頁面 * @apiDescription 返回首頁信息 */ public function index() { $list = Db::name('Article')->select(); $seo = get_system_config('web'); add_user_log('api', '首頁'); $this->apiSuccess('請求成功',['list' => $list,'seo' => $seo]); } /** * @api {post} /index/login 會員登錄 * @apiDescription 系統登錄接口,返回 token 用于操作需驗證身份的接口 * @apiParam (請求參數:) {string} username 登錄用戶名 * @apiParam (請求參數:) {string} password 登錄密碼 * @apiParam (響應字段:) {string} token Token * @apiSuccessExample {json} 成功示例 * {"code":0,"msg":"登錄成功","time":1627374739,"data":{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuZ291Z3VjbXMuY29tIiwiYXVkIjoiZ291Z3VjbXMiLCJpYXQiOjE2MjczNzQ3MzksImV4cCI6MTYyNzM3ODMzOSwidWlkIjoxfQ.gjYMtCIwKKY7AalFTlwB2ZVWULxiQpsGvrz5I5t2qTs"}} * @apiErrorExample {json} 失敗示例 * {"code":1,"msg":"帳號或密碼錯誤","time":1627374820,"data":[]} */ public function login() { $param = get_params(); if(empty($param['username']) || empty($param['password'])){ $this->apiError('參數錯誤'); } // 校驗用戶名密碼 $user = Db::name('User')->where(['username' => $param['username']])->find(); if (empty($user)) { $this->apiError('帳號或密碼錯誤'); } $param['pwd'] = set_password($param['password'], $user['salt']); if ($param['pwd'] !== $user['password']) { $this->apiError('帳號或密碼錯誤'); } if ($user['status'] == -1) { $this->apiError('該用戶禁止登錄,請于平臺聯系'); } $data = [ 'last_login_time' => time(), 'last_login_ip' => request()->ip(), 'login_num' => $user['login_num'] + 1, ]; $res = Db::name('user')->where(['id' => $user['id']])->update($data); if($res){ //獲取jwt的句柄 $jwtAuth = JwtAuth::getInstance(); $token = $jwtAuth->setUid($user['id'])->encode()->getToken(); add_user_log('api', '登錄'); $this->apiSuccess('登錄成功',['token' => $token]); } } /** * @api {post} /index/reg 會員注冊 * @apiDescription 系統注冊接口,返回是否成功的提示,需再次登錄 * @apiParam (請求參數:) {string} username 用戶名 * @apiParam (請求參數:) {string} password 密碼 * @apiSuccessExample {json} 成功示例 * {"code":0,"msg":"注冊成功","time":1627375117,"data":[]} * @apiErrorExample {json} 失敗示例 * {"code":1,"msg":"該賬戶已經存在","time":1627374899,"data":[]} */ public function reg() { $param = get_params(); if(empty($param['username']) || empty($param['pwd'])){ $this->apiError('參數錯誤'); } $user = Db::name('user')->where(['username' => $param['username']])->find(); if (!empty($user)) { $this->apiError('該賬戶已經存在'); } $param['salt'] = set_salt(20); $param['password'] = set_password($param['pwd'], $param['salt']); $param['register_time'] = time(); $param['headimgurl'] = '/static/admin/images/icon.png'; $param['register_ip'] = request()->ip(); $char = mb_substr($param['username'], 0, 1, 'utf-8'); $uid = Db::name('User')->strict(false)->field(true)->insertGetId($param); if($uid){ add_user_log('api', '注冊'); $this->apiSuccess('注冊成功'); }else{ $this->apiError('注冊失敗'); } } /** * @api {post} /index/demo 測試頁面 * @apiDescription 返回文章列表信息 * @apiParam (請求參數:) {string} token Token * @apiSuccessExample {json} 響應數據樣例 * {"code":1,"msg":"","time":1563517637,"data":{"id":13,"email":"test110@qq.com","password":"e10adc3949ba59abbe56e057f20f883e","sex":1,"last_login_time":1563517503,"last_login_ip":"127.0.0.1","qq":"123455","mobile":"","mobile_validated":0,"email_validated":0,"type_id":1,"status":1,"create_ip":"127.0.0.1","update_time":1563507130,"create_time":1563503991,"type_name":"注冊會員"}} */ public function demo() { $list = Db::name('Article')->select(); $jwtAuth = JwtAuth::getInstance(); $uid = $jwtAuth->getUid(); $userInfo = Db::name('User')->where(['id' => $uid])->find(); add_user_log('api', '測試頁面'); $this->apiSuccess('請求成功',['list' => $list,'user' => $userInfo]); } /** * 獲取用戶id * @return mixed */ protected function getUid() { $jwtAuth = JwtAuth::getInstance(); return $jwtAuth->getUid(); } } ```
                  <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>

                              哎呀哎呀视频在线观看