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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 網上搜索巨多的教程,終于找到一篇能夠實現的教程了。 原文地址:[https://blog.csdn.net/qq\_38757174/article/details/116301882](https://blog.csdn.net/qq_38757174/article/details/116301882) 環境:小皮面板 php7x ### 1.新建項目 官網地址:[http://www.hmoore.net/manual/thinkphp6\_0/1037479](http://www.hmoore.net/manual/thinkphp6_0/1037479) 新建項目命令 ~~~ composer create-project topthink/think tp ~~~ ### 2.安裝依賴 ~~~ composer require zircote/swagger-php 3.* ~~~ 最新已經到4.\*了,如果不指定版本,會導致后面進行不下去。 安裝成功后 ![](https://img.kancloud.cn/47/5f/475fcd0648f8d32bf29bb0766fb642a4_336x162.png) ### 3.修改路由 在route文件夾下app.php; ~~~ //下面是新加的 Route::get('/swagger', function() { $openapi = OpenApi\scan(root_path().'app'); // $openapi = OpenApi\scan('../app');//當然,你也可以用這種相對路徑的寫法,但是我建議還是用上面,避免更換route路徑后出現問題 header('Content-Type: application/json'); echo $openapi->toJson(); }); ~~~ 如果 報錯??OpenApi\\scan undefined ,那可能就是??swagger 的版本不對,重新安裝到3x的版本即可。 ### 4.示例代碼 修改?controller\\Index.php: ~~~ <?php namespace app\controller; use app\BaseController; /** * @OA\Info(title="thinkphp6接口文檔", version="1.0.1") */ class Index extends BaseController { /** * @OA\Get(path="/api/article", * tags={"文章管理"}, * summary="文章列表", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string", default="123456")), * @OA\Parameter(name="page", in="query", description="頁碼", @OA\Schema(type="int", default="1")), * @OA\Parameter(name="limit", in="query", description="行數", @OA\Schema(type="int", default="10")), * @OA\Response(response="200", description="The User") * ) */ public function index() { return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">14載初心不改 - 你值得信賴的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">億速云</a> 獨家贊助發布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>'; } /** * @OA\Post(path="/api/article", * tags={"文章管理"}, * summary="新增文章", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="文章名稱", property="title", type="string", default="dd"), * @OA\Property(description="文章內容", property="content", type="string"), * required={"title", "content"}) * ) * ), * @OA\Response(response="200", description="successful operation") * ) */ public function save() { //save業務代碼 } /** * @OA\Get(path="/api/article/{id}", * tags={"文章管理"}, * summary="文章詳情", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="id", in="path", description="文章id", @OA\Schema(type="int")), * @OA\Response(response="200", description="The User") * ) */ public function read($id) { //read業務代碼 } /** * @OA\Put(path="/api/article/{id}", * tags={"文章管理"}, * summary="編輯文章", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="id", in="path", description="文章id", @OA\Schema(type="int")), * @OA\RequestBody( * @OA\MediaType( * mediaType="content-type/json", * @OA\Schema( * @OA\Property(description="文章名稱", property="title", type="string"), * @OA\Property(description="文章內容", property="content", type="string"), * required={"title", "content"}) * ) * ), * @OA\Response(response="200", description="successful operation") * ) */ public function update($id) { //update業務代碼 } /** * @OA\Delete(path="/api/article/{id}", * tags={"文章管理"}, * summary="刪除文章", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="id", in="path", description="文章id", @OA\Schema(type="int")), * @OA\Response(response="200", description="The User") * ) */ public function delete($id) { //delete業務代碼 } } ~~~ 接下來瀏覽器打開?[http://127.0.0.1/tp/public/index.php/swagger](http://127.0.0.1/tp/public/index.php/swagger)?查看 ![](https://img.kancloud.cn/5f/7f/5f7fecffe13318672f729c60ce5ef868_1912x316.png) ?這樣就是成功了(因為我們要拿到他的json文件)。 ### 5.下載swagger 地址:[https://github.com/swagger-api/swagger-ui/tree/3.x](https://github.com/swagger-api/swagger-ui/tree/3.x) 記得要選3.0的版本 ![](https://img.kancloud.cn/54/f6/54f611a6cd39c0ebc43ab2379f934adf_388x566.png) ### 6.修改 swagger 文件 將 swagger 里的 dist 里的 index.html 改成下面這樣就好了。 ![](https://img.kancloud.cn/f1/e4/f1e45616805527afeb9ff317b6244a38_834x356.png) ~~~ http://127.0.0.1/tp/public/index.php/swagger ~~~ ### 7.最后一步 **修改完成直接打開文件,直接打開文件,直接打開文件** 但是會提示這樣 ![](https://img.kancloud.cn/dd/ab/ddabf5be23e9b42ca2f1d252584273c6_1692x516.png) 此時把地址前面修改成 127.0.0.1 即可 ~~~ http://127.0.0.1/tp/public/swagger/dist/index.html ~~~ ![](https://img.kancloud.cn/68/a7/68a73404ba793b16dbb0b07a6ecf7197_1903x596.png) 然后我就只會到這一步了。 剩下的自己去研究吧。? * * * 以上是全部內容了
                  <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>

                              哎呀哎呀视频在线观看