diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/01_\345\272\217\350\250\200.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/01_\345\272\217\350\250\200.md" new file mode 100644 index 0000000000000000000000000000000000000000..b8bd4ba5ea08ae90046c0cce9fdf2edf68521ddf --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/01_\345\272\217\350\250\200.md" @@ -0,0 +1,21 @@ +## 本节目标 + +1. 最简单的api +2. thinkphp的api +3. api uri设计:简短、易读。 +3. api版本处理。 +4. 响应数据设计:json,xml,jsonp +5. api文档编写 + +## 序言 + +前面我们编写了简单的api接口,只是返回了一个json格式。如果在实务中编写api接口,还有一些常见的实践经验: + +1. uri设计要简短、易读。 +2. api支持不同的版本。 +3. 请求api接口的数据格式是? +3. 响应的数据格式除了json,还有xml和jsonp。 +4. api编写的时候需要测试,如果get还好,直接浏览器访问。如果是post请求就很麻烦了。怎样方便测试接口呢? +5. api写好后,接收参数是什么?返回数据是什么?要让他人知晓,那么就需要编写api文档了。 + +下面将针对这些实践的经验进行逐一解释。 diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/02_url\350\256\276\350\256\241.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/02_url\350\256\276\350\256\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..115f9f3c289b0d1ecba34caff1d2ceeda29b2061 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/02_url\350\256\276\350\256\241.md" @@ -0,0 +1,56 @@ +## 本节目标 + +1. 了解api接口的url设计。 + +## url设计 + +我们在提供api接口的时候,url可以说是首要的一个信息,url如果简短、易读,那么就很容易可以猜出这个api接口的含义。 + +如果太过复杂,就需要很多的文档来补充说明了。 + +**示例1**,下面这个api是什么作用呢? + + http://www.example.com/article/article/ + +我们知道文章,但是具体是文章什么,好像有点看不懂了。 + +**示例2**: + + http://www.example.com/article/list/ + +现在可以看出应该是读取文章列表的地址。只是这个会给人疑问,这个地址到底是一个html页面,还是一个接口呢? + +**示例3**: + + http://www.example.com/api/article/list/ + +现在这个意思就比较明了了,是一个提供文章列表的api接口。这边二级域名是www,一般是指访问网站的主页。 + +如果是专门的api服务,我们可以把域名修改为api的域名,这样就移除uri中的api了,形如: + + http://api.example.com/article/list/ + +这样的url在设计上就比较易读和简洁了。 + +**更多的例子**: + + http://api.example.com/article/add/ + http://api.example.com/article/update/ + http://api.example.com/article/detail/ + http://api.example.com/article/search/ + +思考: + + 上面api分别表示什么意思呢? + +## 本节总结 + +url设计要简短、易读,单词要见名识意。 + +api url的常见格式: + + http://api域名/模块名称/操作名称/ + + + + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/03_\347\211\210\346\234\254\350\256\276\350\256\241.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/03_\347\211\210\346\234\254\350\256\276\350\256\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..2ca5436c71e1c93a7261348c1fb24aea00ab5a6c --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/03_\347\211\210\346\234\254\350\256\276\350\256\241.md" @@ -0,0 +1,139 @@ +## 本节目标 + +1. 了解api接口版本设计 + +## api多版本支持 + +api设计好的时候:接收参数和返回数据都已经确认。如果要更改数据格式怎么办? + +例如,我们之前计算了英文文章出现的单词列表,返回的数据格式如下: + +```php +[ + 'status' => 0, + 'message' => '', + 'data' => [ + ['where', 'is', 'how'] + ], +] +``` + +如果现在还需要统计每个词出现的次数。那么可能需要改成如下结构: + +```php +[ + 'status' => 0, + 'message' => '', + 'data' => [ + [ + 'where' => 5, + 'is' => 1, + 'how' => 2, + ] + ], +] +``` + +如果直接修改原来的代码,那么就会导致之前调用的接口的客户端出现错误。为了避免这个问题,可以使用版本号的设计。 + +**版本号的设计思路**: + +新增加一个参数v表示版本的意思,默认值为1,表示版本1的意思,根据不同的版本定位到不同的方法。 + +```php +if ($v == 1) { + // 版本1的代码 +} else ($v == 2) { + // 版本1的代码 +} +``` + +**示例1**,以上面英文单词例子为例(基于thinkphp框架): + +第一个版本: + +```php +public function word() +{ + $content = Request::param("content"); + $validate = Validate::rule([ + 'content|文章内容' => 'require|min:10|max:100', + ]); + if (!$validate->check(['content' => $content])) { + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + $words = array_values(array_unique( + explode(" ", strtolower($content)) + )); + + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => $words, + ]; + return json($data); +} +``` + +示例句子: + + Whatever is worth doing is worth doing well. + +现在需要增加词频,设计一个v参数,可以区别版本: + +```php +public function word() +{ + $v = Request::param("v", 1); + if ($v == 1) { + // 版本1的代码 + } else if ($v == 2) { + $content = Request::param("content"); + $validate = Validate::rule([ + 'content|文章内容' => 'require|min:10|max:100', + ]); + if (!$validate->check(['content' => $content])) { + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + $words = explode(" ", strtolower($content)); + $result = []; + foreach ($words as $word) { + if (empty($result[$word])) { + $result[$word] = 0; + } + $result[$word]++; + } + + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => $result, + ]; + return json($data); + } +} +``` + +这样就不会影响原来的客户端调用,又可以增加新的调用。同时api接口的地址也不用修改。 + +## 多版本支持维护成本 + +如果一个接口提供过多版本,是不是会造成维护成本变大? + +所以当一个接口版本过多的时候,那么可以通过逐步废弃旧版本接口减少维护压力。 + +## 本节总结 + +1. api接口版本设计是为了兼容之前的客户端的调用。 +2. 在实现上通过设计版本号参数即可实现。 +3. api接口设计过多的版本,会导致维护困难,应当逐步废弃旧的版本。 diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/04_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_files/1.jpg" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/04_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_files/1.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..b9d34e7b6be157879a6d56fdcdcba70e648893aa Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/04_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_files/1.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/04_\350\257\267\346\261\202\346\225\260\346\215\256\350\256\276\350\256\241.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/04_\350\257\267\346\261\202\346\225\260\346\215\256\350\256\276\350\256\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..87dde520c960c71dd6c360fb1a7263e78212d968 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/04_\350\257\267\346\261\202\346\225\260\346\215\256\350\256\276\350\256\241.md" @@ -0,0 +1,100 @@ +## 本节目标 + +1. 熟悉读取数据请求数据设计。 +2. 熟悉写入数据请求数据设计。 +3. 了解restful风格的api请求 + +## 请求数据设计 + +前面我们设计了api的url,也设计了api的版本号。那么用户请求api接口,怎么传递参数呢? + +是用get,还是post?或者是其他方式呢? + +本节将就这个问题进行讲解。 + +一般来讲,常规的请求参数设计就两种: + +1. 读取数据使用get请求,参数就在url后面。 +2. 写入数据使用post请求,参数放在http请求体。 + +## 读取数据 + +像文章列表、分类列表、搜索文章等等这样功能都是属于读取数据的,用get请求,参数接在url后面。 + +**示例1**,获取文章列表,一般需要有页码和每页显示条目数: + + GET http://api.example.com/article/list/?page=1&count=20 + +其中: + + page 表示页码。 + count 表示条目数。 + +**示例2**,获取文章详情,一般需要传递文章id参数: + + GET http://api.example.com/article/detail/?id=1 + +其中: + + id 表示文章id。 + +**示例3**:搜索文章,一般需要传递搜索词、页码和每页显示条目数: + + GET http://api.example.com/article/list/?word=life&page=1&count=20 + +## 写入数据 + +像增加文章,修改文章和删除等这些操作都叫做写入数据。写入数据一般用post请求。 + +**示例1**,增加文章,一般需要有文章标题、文章简介、文章内容等等: + + POST http://api.example.com/article/add/ + + 表单数据: article_title=标题&article_intro=简介&article_content=内容 + +这边采用post请求,表单的数据放在请求数据体里面。 + +**示例2**,修改文章,一般需要有文章id、文章标题、文章简介、文章内容等等: + + POST http://api.example.com/article/update/ + + 表单数据: article_id=1&article_title=标题&article_intro=简介&article_content=内容 + +这边采用post请求,表单的数据放在请求数据体里面。 + +**示例3**,删除文章,一般需要有文章id即可: + + POST http://api.example.com/article/update/ + + 表单数据: article_id=1 + +这边采用post请求,表单的数据放在请求数据体里面。 + +## restful风格 + +REST(Representational State Transfer)表述性状态转换,REST指的是一组架构约束条件和原则。 + +如果一个架构符合REST的约束条件和原则,我们就称它为RESTful架构。 + +GET:查询 + + GET /artile + GET /artile/1 + +POST:创建单个资源。POST一般向“资源集合”型uri发起 + + POST /artile + +PUT:更新单个资源(全量),客户端提供完整的更新后的资源。与之对应的是 PATCH,PATCH 负责部分更新,客户端提供要更新的那些字段。PUT/PATCH一般向“单个资源”型uri发起 + + PUT /artile/1 + +DELETE:删除 + + DELETE /artile/1 + +这边对restful风格的api介绍并不全面,仅供参考。 + +## 本节总结 + +一般来讲读取数据使用get请求,写入数据使用post请求。 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/05_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_ajax.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/05_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_ajax.md" new file mode 100644 index 0000000000000000000000000000000000000000..1ccb1ea5e1bd2fb8f71461c124256da6215f07f0 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/05_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_ajax.md" @@ -0,0 +1,204 @@ +## 本节目标 + +1. 熟悉ajax get请求。 +2. 熟悉ajax post请求。 + +## 响应的数据格式 + +前面我们设计了api的url,也设计了api的版本号,请求数据也进行了说明,本篇将对响应数据进行讲解。 + +响应数据是指api接口返回给客户端的数据。 + +响应的数据格式除了json之外,还有xml和jsonp。现在xml用的少,重点关注和json和jsonp就行了。 + +## ajax异步请求(get) + +接口设计完成后,都是给其他应用调用的,最常见的就是web客户端(web前端)、安卓客户端、IOS客户端、其他应用服务端。 + +**这边web客户端调用接口就是用ajax的技术**。ajax是属于javascript的知识体系,这边做一下简单的回顾。 + +比如我们有一个登录表单: + +```html + + + + + 登录表单 + + +
+

邮箱:

+

密码:

+

+
+ + +``` + +当我们提交这个表单的时候页面会跳转到表单的提交地址,然后对账号密码进行检验,如果有问题,就返回登录页面。 + +有没什么办法,可以在当前页面直接提交,而不进行跳转呢? + +这边就可以使用ajax技术,ajax语法格式: + +```js +let xmlHttp = new XMLHttpRequest(); +xmlHttp.onreadystatechange = function () { + if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { + console.log(xmlHttp.responseText); + } +}; +xmlHttp.open("请求方法", "服务端url", true); +xmlHttp.send(); +``` + +其中: + + 1. XMLHttpRequest 是发起异步请求的类,需要先实例化这个类的对象。 + 2. onreadystatechange 声明一个事件,每当 readyState 改变时,就会触发 onreadystatechange 事件。 + 3. open 表示开启一个请求,具体参数:请求方法(post,get)、请求url,是否是异步请求。 + 4. send 表示发送请求。 + 5. xmlHttp.status 表示http响应状态。 + 6. xmlHttp.readyState 表示异步请求就绪状态。有5种,详见如下: + +xmlHttp.readyState 5种情况: + + 0 (未初始化): (XMLHttpRequest)对象已经创建,但还没有调用open()方法。 + 1 (载入):已经调用open() 方法,但尚未发送请求。 + 2 (载入完成): 请求已经发送完成。 + 3 (交互):可以接收到部分响应数据。 + 4 (完成):已经接收到了全部数据,并且连接已经关闭。 + +**示例1**,异步发送请求到服务端接口:/index.php?s=api/test/test/,并将返回数据显示在页面: + +```html + + + + + 一个演示ajax的静态页面 + + +
+ + + + +``` + +服务端接口: + +```php +public function test() +{ + return 'test 接口返回'; +} +``` + +运行后,点击按钮可以发现页面上显示了如下: + + test 接口返回 + +通过谷歌工具抓包查看,可以看有一个另外的请求: + +![](04_响应数据设计_files/1.jpg) + +思考: + + 假如我们要传递参数num=1,请问修改哪里? + +注意: + + 这边我们把接口直接放在index(前台)应用下面,正常应用在前期一般不会拆分出单独的api应用。 + +## ajax异步请求(post) + +前面我们使用ajax发起了get请求,当然ajax也可以发起post请求,发起post请求有一些不太一样。 + +ajax post语法格式: + +```js +let xmlHttp = new XMLHttpRequest(); +xmlHttp.onreadystatechange = function () { + if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { + console.log(xmlHttp.responseText); + } +}; +xmlHttp.open("POST", "服务端url", true); +xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); +xmlHttp.send("数据主体"); +``` + +大部分和get请求类似,不一样的地方: + + 1. 请求方法固定为POST。 + 2. setRequestHeader 表示设置http请求头的方法。 + 3. send方法增加数据主体。 + +**示例1**,异步发送请求到服务端接口:/index.php?s=api/test/test/,并传入数据 name=盘古: + +```html + + + + + 一个演示ajax的静态页面 + + +
+ + + + +``` + +服务端接口: + +```php +public function test() +{ + $name = Request::param("name"); + return '你好, ' . $name; +} +``` + +运行后,点击按钮可以发现页面上显示了如下: + + 你好, 盘古 + +通过谷歌工具抓包查看,可以看有一个另外的请求: + +![](05_响应数据设计_ajax_files/1.jpg) + +思考: + + 如果需要再传入一个参数,age=123,请问修改哪里? + +## 本节总结 + +web客户端使用ajax技术,可以在不刷新页面的情况下发起请求。 + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/05_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_ajax_files/1.jpg" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/05_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_ajax_files/1.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..ea78497b52b0aac2278a770b6170abf15b6c3dfb Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/05_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_ajax_files/1.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/06_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_json.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/06_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_json.md" new file mode 100644 index 0000000000000000000000000000000000000000..7f77bb5243e437b43118702394dc37d7df60c649 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/06_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_json.md" @@ -0,0 +1,254 @@ +## 本节目标 + +1. 熟悉接口返回json格式。 +2. 熟悉web客户端如何调用数据格式为json的接口。 + +## json + +上面我们返回的数据是一个简单的字符串,在实务中为了方便区分请求的各种状况,一般都会定义状态、信息、数据等字段。 + +因为json是键值对的数据格式,这时候用json格式就非常方便了,例如php返回json格式数据: + +```php +$data = [ + 'status' => 0, // 表示接口返回的状态 + 'message' => '', // 表示接口返回的消息 + 'data' => [ // 表示接口返回的数据 + ], +]; +header("Content-Type: application/json"); +echo json_encode($data); +``` + +其中: + + $data 表示返回的数据,这边是一个数组。 + status 表示状态,0表示没有出现错误。 + message 表示返回的一些 提示信息,一般status > 0时有写入。 + data 就表示返回的一些数据,比如文章列表、编辑文章结果等等。 + 备注:实务中这边数据字段和格式并非都是这样,但是大体都类似,只是字段名不一样。 + header 表示设置返回的数据格式为json格式,即Content-Type为application/json。 + json_encode 表示将php数组编码为json格式的数据。 + +注意: + + 这边定义的字段是比较常见的字段,在实务中有很多命名方式,但是基本都表达了这些个意思。 + +**示例1**,已知api接口返回当前服务器时间,编写并调用这个接口: + +服务端代码: + +```php +public function test() +{ + $data = [ + 'status' => 0, + 'message' => '', + 'data' => [ + 'time' => date("Y-m-d H:i:s") + ], + ]; + return json($data); +} +``` + +其中服务端返回的是一个json格式,在客户端解析这个json结果: + +```html + + + + + 一个演示ajax的静态页面 + + +
+ + + + +``` + +这里需要对 responseData.status 进行一个判断,如果大于0表示有错误发生的意思。 + +**示例2**,设计api接口,传入长度参数,生成随机字符串(a-z0-9),并返回json格式: + +```php +public function randStr() +{ + $length = Request::param("length"); + $validate = Validate::rule([ + 'length' => 'require|between:1,32', + ]); + if (!$validate->check(['length' => $length])) { + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + + $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; + $charsLength = mb_strlen($chars); + + $str = ''; + for ($i = 0; $i < $length; $i++) { + $rand = mt_rand(0, $charsLength - 1); + $str .= $chars[$rand]; + } + + $data = [ + 'status' => 0, + 'message' => '', + 'data' => [ + 'str' => $str, + ], + ]; + return json($data); +} +``` + +其中: + + 这边返回了json格式的数据。 + +web客户端进行调用: + +```html + + + + + 一个演示ajax的静态页面 + + +
+

这是一个生成随机字符串的应用(0-9a-z)。

+

+ 请输入生成的长度: + +

+ + + + +``` + +这边我们使用post请求,传递参数需要放在send方法里。 + +**示例3**,blog系统中,设计api接口,查询文章列表,返回文章列表的数据,其中包含文章id、文章标题、文章分类、文章简介,增加时间,修改时间: + +这边使用blog系统进行演示: + +```php +public function index() +{ + $articleList = ArticleModel::getList(); + + $articleData = []; + foreach ($articleList as $row) { + $articleData[] = [ + 'article_id' => $row['article_id'], + 'article_title' => $row['article_title'], + 'category_name' => $row['category_name'], + 'intro' => $row['intro'], + 'add_time' => $row['add_time'], + ]; + } + $data = [ + 'status' => 0, + 'message' => '', + 'data' => [ + 'articleData' => $articleData, + ], + ]; + + return json($data); +} +``` + +其中: + + 读取所有文章后,遍历存放到数组,最后返回json格式。 + +设计了这个接口后,后台就可以进行异步调用了: + +```js +let xmlHttp = new XMLHttpRequest(); +xmlHttp.onreadystatechange = function () { + if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { + let data = JSON.parse(xmlHttp.responseText); + if (data.status > 0) { + window.alert("出现错误:" + data.message); + } else { + // 获取表格的内的html内容 + let listHtml = document.getElementById('list').innerHTML; + + // 遍历文章数据,拼接表格html代码 + let articleData = data.data.articleData; + for (let i in articleData) { + console.log(articleData[i]); + let trString = ''; + trString += ''; + trString += '' + articleData[i].article_id + ''; + trString += '' + articleData[i].article_title + ''; + trString += '' + articleData[i].category_name + ''; + trString += '' + articleData[i].intro + ''; + trString += '' + articleData[i].add_time + ''; + trString += '' + articleData[i].update_time + ''; + trString += ''; + trString += ''; + + listHtml += trString; + } + + // 替换表格内容为相应的html + document.getElementById('list').innerHTML = listHtml; + } + } +}; +xmlHttp.open("GET", "/api/article/index/", true); +xmlHttp.send(); +``` + +这边请求到文章接口后,就会遍历显示在页面上。其中增加时间和修改时间没有完成,请自行完善。 + +## 本节总结 + +api接口一般返回json格式的数据,在web客户端可以通过json格式数据的语法进行访问。 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/07_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_jsonp.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/07_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_jsonp.md" new file mode 100644 index 0000000000000000000000000000000000000000..30c230559a9be798c68551fcc7c8527e1d66c8ea --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/07_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_jsonp.md" @@ -0,0 +1,204 @@ +## 本节目标 + +1. 熟悉为什么要用jsonp? +2. 熟悉jsonp的数据格式。 +3. 熟悉客户端调用jsonp的方式。 + +## 为什么要用jsonp + +前面我们讲解了ajax异步请求接口,接口返回json格式的处理方法。 + +如果碰到web客户端地址和服务端地址不在同一个域的情况下,会出现跨域的问题。 + +那么什么是跨域呢?我们用下面一个示例进行讲解。 + +**示例1**,我们在localhost:8888下面制作客户端页面,访问tp项目接口,获取服务端当前时间: + +```html + + + + + 一个演示ajax的静态页面 + + +
+ + + + +``` + +因为页面的访问地址是: + + http://localhost:8888/test.html + +而请求的接口地址是: + + http://localhost:8900/index.php?s=api/test/test + +**两个的端口不一致,这个称为跨域。除了端口不一致,如果域名不一致,那么也是跨域。** + +访问就会报如下的错误: + +![](07_响应数据设计_jsonp_files/1.jpg) + +随着前后端分离的流行,客户端和服务端域名或者端口不一致的情况非常常见,所以就有jsonp这样一种技术用来解决跨域问题。 + +## jsonp + +jsonp(json with padding)是json的一种“使用模式”,主要用于解决主流浏览器的跨域数据访问的问题。 + +jsonp的核心原理就是目标页面回调本地页面的方法,并带入参数。 + +使用jsonp总结有3步: + + 1. 前端页面定义好相关的回调方法。 + 2. 服务端返回的内容是调用第1步定义好的方法。 + 3. 前端页面以js的方式引入第2步的内容。 + +**示例1**,使用jsonp的方式在页面上显示服务端返回的内容: + +1) 前端页面: + +```html + + + + + + + +
+ + + + +``` + +其中: + + 定义了show方法,显示内容在id="content"的div内。 + +2) 服务端(基于thinkphp)页面: + +```php +public function content() +{ + $content = "这个是服务端返回的数据"; + return "show('" . $content . "');"; +} +``` + +其中: + + 服务端输出show()这样一个字符串,其实就是调用js的方法; + +3) 前端以js的方式引入服务端页面: + +```html + +``` + +这个时候访问前端页面,可以看到页面上显示了:这个是服务端返回的数据。这样的字眼了。 + +**改进方案,show方法由前端传递**: + +前面这边show方法是服务端写死的,一般来讲后端并知道前端需要调用什么方法,所以这个参数可以由前端进行传递,后端获取就可以了。 + +```php +public function content() +{ + $callback = Request::param("callback"); // 获取传递的方法 + $content = "这个是服务端返回的数据"; + return $callback . "('" . $content . "');"; +} +``` + +thinkphp中,可以使用jsonp方法直接进行: + +```php +public function content() +{ + $content = "这个是服务端返回的数据"; + return jsonp($content); // 自动获取callback这个参数,并输出。 +} +``` + +## json和jsonp结合 + +前面介绍了json和jsonp格式的返回数据,当然这边两种也可以结合在一起。 + +其实就是把jsonp返回的数据用json格式代替就可以了: + +```php +public function content() +{ + $data = [ + 'status' => 0, + 'message' => '', + 'data' => [ + 'content' => "这个是服务端返回的数据", + ], + ]; + return jsonp($data); +} +``` + +因为这边改成了返回json格式,前端就需要相应调整回调方法了: + +```html + + + + + + + +
+ + + + + +``` + +## 本节总结 + +jsonp格式主要是用来解决跨域问题,当然不跨域也可以使用。 + +jsonp的三步骤: + + 1. 前端页面定义好相关的回调方法。 + 2. 服务端返回的内容是调用第1步定义好的方法。 + 3. 前端页面以js的方式引入第2步的内容。 + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/07_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_jsonp_files/1.jpg" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/07_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_jsonp_files/1.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..aefdd7159a8bb001aaa067b64c3eeb83e9d10171 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/07_\345\223\215\345\272\224\346\225\260\346\215\256\350\256\276\350\256\241_jsonp_files/1.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243.md" new file mode 100644 index 0000000000000000000000000000000000000000..4621af6be441307e61abf8fd52f4e12a5506492b --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243.md" @@ -0,0 +1,128 @@ +## 本节目标 + +1. 熟悉api接口文档编写 + +## api接口文档 + +前面我们设计了也开发了不少api接口。我们自己知道接口干了啥事,也知道如何调用。 + +只是如果我们要把接口提供给其他人使用,其他人要怎么知道调用呢? + +这会我们就可以统一编写文档对api接口进行说明,俗称api文档。 + +## api接口文档要素 + +基本来看,文档至少需要如下5个要素: + + 1. 接口用途 + 2. 接口地址 + 3. 请求方式 + 4. 请求参数 + 5. 返回数据 + +这样使用者才能正常调用这个接口。 + +**示例1**,已知接口返回服务器当前时间,编写api: + +接口用途:获取当前系统时间戳。 + +接口地址:http://localhost:8900/api/system/time/ + +请求方式:get + +请求参数:无 + +返回数据: + +``` +{ + "status": 0, // 状态 + "message": "", // 信息提示 + "data": { // 返回数据 + "time": "2021-05-06 21:09:20" // 时间 + } +} +``` + +**示例2**,已知接口返回随机字符串,编写api文档: + +接口用户:生成随机字符串。 + +接口地址:http://localhost:8900/api/tool/randstring/ + +请求方式:post + +请求参数: + + 1. length 正整数,1~32 随机字符串长度。 + +返回数据: + +``` +// 接口正常返回 +{ + "status": 0, + "message": "", + "data": { + "string": "w4kejv3vrptgj2vikt4v3u0l9e57kn3c" // 随机字符串 + } +} + +// 参数错误返回格式 +{ + "status": 1, + "message": "length只能在 1 - 32 之间", + "data": [ ] +} +``` + +在接口少的时候,我们可以使用文本工具和软件来编写api文档,随着接口越来越多,协作人员越来越多,有一个统一的管理平台会好些。 + +下面我们介绍一款平台showdoc,实现接口的管理。 + +## 开源文档管理工具showdoc + +showdoc官网: + + https://www.showdoc.com.cn/ + +我们可以在官网上直接编辑api文档。也可以通过客户端工具进行编辑,还支持模拟请求。 + +几个步骤: + + 1. 下载 runapi-1.0.0.exe,并安装。 + 2. 创建项目 + 3. 新建接口 + 4. 获取项目文档链接 + +下面详细讲解每个步骤: + +1)下载 runapi + +下载地址: + + https://www.showdoc.com.cn/runapi?page_id=30291 + +下载完成后直接安装即可。 + +2)创建项目,并进入。 + +![](08_编写api文档_files/1.jpg) + +3)新建接口 + +![](08_编写api文档_files/2.jpg) + +并填写相关的信息 + +![](08_编写api文档_files/3.jpg) + +4)通过项目获取相关链接 + +![](08_编写api文档_files/4.jpg) + +这样就可以通过浏览器进行访问了。并且其他人也可以访问,方便团队之间协作了。 + +## 本节总结 + +api文档就是将api的使用方式写出来,通过编写api文档可以很方便的实现团队之间的协作。 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/1.jpg" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/1.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..3502f8130934d81894ab3e5e468dc6b1e0d7b33e Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/1.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/2.jpg" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/2.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..b5063b1836b9201ace5349dc589783bea9a03094 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/2.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/3.jpg" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/3.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..10f059e4177f3e872a3a8235a6c119499772c490 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/3.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/4.jpg" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/4.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..defbc9956744a57ab60ceff2ab146b3e35386d92 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/08_\347\274\226\345\206\231api\346\226\207\346\241\243_files/4.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/80_\347\273\203\344\271\240\351\242\230.md" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/80_\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..20880ce670770e8f1777bb4a2b1ea18c1e542a2f --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/03_webapi\350\256\276\350\256\241\345\222\214\345\274\200\345\217\221/80_\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,32 @@ +## url设计 + +1. 已知需要开发分类模块的增删改查,设计相关的接口url。 +2. 已知需要开发文章模块的增删改查,设计相关的接口url。 +3. 已知登录功能需要使用接口实现,设计相关的接口url。 + +## 版本设计 + +1. 接第一章节练习题第2题,现在需要改进接口,移除首尾的空格再计算长度,请使用版本设计的方式改进。 +2. 接第一章节练习题第4题,现在需要改进接口,返回如下数据: + +``` +[ + 'status' => 0, + 'message' => '', + 'data' => [ + 'where' => 5, + 'is' => 1, + 'how' => 2, + ], +] +``` + +请使用版本设计的方式改进。 + +## 响应数据设计 + +1. 设计表单页面,用户可以输入字符串,然后使用ajax调用服务端接口计算长度,并把结果显示在页面上。 +2. 设计表单页面,用户可以输入英文文章,然后使用ajax调用服务端接口统计词频,并把结果显示在页面上。 +3. 设计表单页面,用户可以输入数字,然后使用ajax调用服务端斐波那契接口,判断是否是斐波那契数,并把结果显示在页面上。 +4. 设计表单页面,用户可以输入身份证,然后使用ajax调用服务端身份证分析接口,计算年龄和性别,并把结果显示在页面上。 +5. 改进jsonp章节的第一个示例,使用jsonp的方式解决跨域问题,并将服务器时间显示到页面上。 diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/\350\257\276\345\240\202\347\273\203\344\271\240.txt" "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/\350\257\276\345\240\202\347\273\203\344\271\240.txt" new file mode 100644 index 0000000000000000000000000000000000000000..f02d70f851bd43d7e444c4f6b8a088cd7f4216d0 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210510/\350\257\276\345\240\202\347\273\203\344\271\240.txt" @@ -0,0 +1,2 @@ +1. 03_webapiƺͿ/80_ϰ.md url 1 ~ 3 +2. 03_webapiƺͿ/80_ϰ.md 汾 1 ~ 2 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/.example.env" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/.example.env" new file mode 100644 index 0000000000000000000000000000000000000000..c27f74caea59e0bc78bae1941793a6ac34c85a9c --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/.example.env" @@ -0,0 +1 @@ +APP_DEBUG = true [APP] DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 DATABASE = test USERNAME = username PASSWORD = password HOSTPORT = 3306 CHARSET = utf8 DEBUG = true [LANG] default_lang = zh-cn \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/.gitignore" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..d465120e74b813c80d55c418ed3cab757a22033c --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/.gitignore" @@ -0,0 +1,5 @@ +/.idea +/.vscode +/vendor +*.log +.env \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/.travis.yml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/.travis.yml" new file mode 100644 index 0000000000000000000000000000000000000000..36f7b6f90dafe374d0eca306886df83f09ff13a9 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/.travis.yml" @@ -0,0 +1,42 @@ +sudo: false + +language: php + +branches: + only: + - stable + +cache: + directories: + - $HOME/.composer/cache + +before_install: + - composer self-update + +install: + - composer install --no-dev --no-interaction --ignore-platform-reqs + - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip . + - composer require --update-no-dev --no-interaction "topthink/think-image:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0" + - composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0" + - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip . + +script: + - php think unit + +deploy: + provider: releases + api_key: + secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw= + file: + - ThinkPHP_Core.zip + - ThinkPHP_Full.zip + skip_cleanup: true + on: + tags: true diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/LICENSE.txt" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/LICENSE.txt" new file mode 100644 index 0000000000000000000000000000000000000000..574a39c401ff71ffcb90d15edb906b8046c7661b --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/LICENSE.txt" @@ -0,0 +1,32 @@ + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 +版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn) +All rights reserved。 +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +Apache Licence是著名的非盈利开源组织Apache采用的协议。 +该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, +允许代码修改,再作为开源或商业软件发布。需要满足 +的条件: +1. 需要给代码的用户一份Apache Licence ; +2. 如果你修改了代码,需要在被修改的文件中说明; +3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 +带有原来代码中的协议,商标,专利声明和其他原来作者规 +定需要包含的说明; +4. 如果再发布的产品中包含一个Notice文件,则在Notice文 +件中需要带有本协议内容。你可以在Notice中增加自己的 +许可,但不可以表现为对Apache Licence构成更改。 +具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/README.md" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..2929dad091236d93f73380bd02d6a0bbb58b5b2f --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/README.md" @@ -0,0 +1,56 @@ +ThinkPHP 6.0 +=============== + +> 运行环境要求PHP7.1+,兼容PHP8.0。 + +[官方应用服务市场](https://market.topthink.com) | [`ThinkAPI`——官方统一API服务](https://docs.topthink.com/think-api) + +ThinkPHPV6.0版本由[亿速云](https://www.yisu.com/)独家赞助发布。 + +## 主要新特性 + +* 采用`PHP7`强类型(严格模式) +* 支持更多的`PSR`规范 +* 原生多应用支持 +* 更强大和易用的查询 +* 全新的事件系统 +* 模型事件和数据库事件统一纳入事件系统 +* 模板引擎分离出核心 +* 内部功能中间件化 +* SESSION/Cookie机制改进 +* 对Swoole以及协程支持改进 +* 对IDE更加友好 +* 统一和精简大量用法 + +## 安装 + +~~~ +composer create-project topthink/think tp 6.0.* +~~~ + +如果需要更新框架使用 +~~~ +composer update topthink/framework +~~~ + +## 文档 + +[完全开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content) + +## 参与开发 + +请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)。 + +## 版权信息 + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 + +本项目包含的第三方源码和二进制文件之版权信息另行标注。 + +版权所有Copyright © 2006-2020 by ThinkPHP (http://thinkphp.cn) + +All rights reserved。 + +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +更多细节参阅 [LICENSE.txt](LICENSE.txt) diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/common.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/common.php" new file mode 100644 index 0000000000000000000000000000000000000000..124361568ff89529382ad44b04b53d6fd7543152 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/common.php" @@ -0,0 +1,2 @@ +$adminList]); + } + public function add(){ + return View::fetch(); + } + public function addSave() + { + $params = Request::param(); + $rule = Validate::rule([ + 'admin_name|管理员名称'=>'require|min:2|max:50', + 'admin_email|管理员邮箱'=>'require|min:8|max:100', + 'admin_password|管理员密码'=>'require|min:6|max:100' + ]); + if (!$rule->check($params)){ + return View::fetch('public/tips_error',['massage'=>$rule->getError()]); + } + if ($params['admin_password']!=$params['admin_password2']){ + echo '两次密码错误'; + exit(); + } + $name=AdminModel::where('category_name','=',$params['category_name'])->find(); + if ($name){ + echo "用户名已存在"."返回上一页"; + exit(); + } + $params['update_time']=time(); + $params['add_time']=time(); + $result=AdminModel::create($params); + $addr='Admin'; + return View::fetch('public/tips',['result'=>$result, + 'addr'=>$addr + ]); + + } + public function edit(){ + $params=Request::param('admin_id') ?? ''; + $admin=AdminModel::find($params); +// if (empty($params['admin_id'])){ +// echo "找不到管理员"."返回管理员列表"; +// exit(); +// } + return View::fetch('',['admin'=>$admin]); + } + public function editSave(){ + $params=Request::param(); + $rule = Validate::rule([ + 'admin_name|管理员名称'=>'require|min:2|max:50', + 'admin_email|管理员邮箱'=>'require|min:8|max:100', + 'admin_password|管理员密码'=>'require|min:6|max:100', + 'admin_password2|确认密码'=>'require|min:6|max:100' + ]); + + if (!$rule->check($params)){ + return View::fetch('public/tips_error',['massage'=>$rule->getError()]); + } + $admin=AdminModel::find($params['admin_id']); + $admin['admin_name']=$params['admin_name']; +// $admin['admin_email']=$params['admin_email']; + $admin['admin_password']=$params['admin_password']; + $admin['update_time']=time(); + $result=$admin->save(); + $addr='Admin'; + return View::fetch('public/tips',['result'=>$result, + 'addr'=>$addr + ]); + } +} \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Article.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Article.php" new file mode 100644 index 0000000000000000000000000000000000000000..bfc0691e41254c748f019a92a2443e02be4dde71 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Article.php" @@ -0,0 +1,116 @@ +1,//每页显示几条数据 + 'query'=>$queryParams//实际上页面所有的get参数 + ]); + //第一种 +// $articleList=ArticleModel::select(); +// +// foreach ($articleList as &$item){ +// $CategoryList=CategoryModel::find($item['category_id']); +// $item['category_name']=$CategoryList['category_name']; +//// View::assign('',$CategoryList); +// } +// unset($item); +// return View::fetch('',['articleList'=>$articleList]); + //第二种 +// $articleList=ArticleModel::select(); + foreach ($articleList as $item){ + $CategoryList=CategoryModel::find($item['category_id']); + $item['category_name']=$CategoryList['category_name']; + } +// unset($item); + View::assign('articleList',$articleList); + return View::fetch(); + } + public function add(){ + $categotyList=CategoryModel::select(); + return View::fetch('',['categoryList'=>$categotyList]); + } + public function addSave(){ + $params=Request::param(); + $rule=Validate::rule([ + 'article_title|文章标题'=>'require|min:2|max:45', + 'category_id|分类'=>'require|between:1,'.PHP_INT_MAX, + 'intro|文章简介'=>'require|min:10|max:255', + 'content|文章内容'=>'require|min:10|max:255' + ]); + if(!$rule->check($params)){ + return View::fetch('public/tips_error',['massage'=>$rule->getError()]); + } + $params['update_time']=time(); + $params['add_time']=time(); + $result=ArticleModel::create($params); + $addr='Article'; + return View::fetch('public/tips',['result'=>$result, + 'addr'=>$addr + ]); + } + public function edit(){ + $params=Request::param('article_id'); + $article=ArticleModel::find($params); +// View::assign('articleList',$article); + $categoryList=CategoryModel::select(); + View::assign([ + 'categoryList'=>$categoryList, + 'article'=>$article + ]); +// if (empty($params['article_id'])){ +// echo "找不到文章"."返回文章列表"; +// exit(); +// } + return View::fetch(); + } + public function editSave(){ + $params=Request::param(); + $rule=Validate::rule([ + 'article_title|文章标题'=>'require|min:2|max:45', + 'category_id|分类'=>'require|between:1,'.PHP_INT_MAX, + 'intro|文章简介'=>'require|min:10|max:255', + 'content|文章内容'=>'require|min:10|max:255' + ]); + if(!$rule->check($params)){ + return View::fetch('public/tips_error',['massage'=>$rule->getError()]); + } + + $Article=ArticleModel::find($params['article_id']); + $Article['article_title']=$params['article_title']; + $Article['category_id']=$params['category_id']; + $Article['intro']=$params['intro']; + $Article['content']=$params['content']; + $Article['update_time']=time(); + $result=$Article->save(); + $addr='Article'; + return View::fetch('public/tips',['result'=>$result, + 'addr'=>$addr + ]); + } + public function delete(){ + $params=Request::param('article_id'); + $result=ArticleModel::destroy($params); + $addr='Article'; + return View::fetch('public/tips',['result'=>$result, + 'addr'=>$addr + ]); + } +} \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Category.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Category.php" new file mode 100644 index 0000000000000000000000000000000000000000..8f5c04967be96a314fecba09933bab235f892507 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Category.php" @@ -0,0 +1,102 @@ +1,//每页显示几条数据 + 'query'=>$queryParams//实际上页面所有的get参数 + ]); +// $return=CategoryModel::select(); + View::assign('return',$return); +// return View::fetch('',['return'=>$return]); + return View::fetch(); + } + public function add(){ + return View::fetch(); + } + public function addSave(){ + $params=Request::param(); + $rule=Validate::rule([ + 'category_name|分类名称'=>'require|min:2|max:45', + 'category_desc|分类描述'=>'require|min:10|max:255' + ]); + $name=CategoryModel::where('category_name','=',$params['category_name'])->find(); + if ($name){ + echo "用户名已存在"."返回上一页"; + exit(); + } + if(!$rule->check($params)){ + return View::fetch('public/tips_error',['massage'=>$rule->getError()]); + } + $params['update_time']=time(); + $params['add_time']=time(); + $result=CategoryModel::create($params); + $addr='Category'; + return View::fetch('public/tips',['result'=>$result, + 'addr'=>$addr + ]); + + + } + public function edit(){ + $params=Request::param('category_id'); + $category=CategoryModel::find($params); +// if (empty($params['category_id'])){ +// echo "找不到分类"."返回分类列表"; +// exit(); +// } + return View::fetch('',['category'=>$category]); + } + public function editSave(){ + $params=Request::param(); + $rule=Validate::rule([ + 'category_name|分类名称'=>'require|min:2|max:45', + 'category_desc|分类描述'=>'require|min:10|max:255' + ]); + if(!$rule->check($params)){ + return View::fetch('public/tips_error',['massage'=>$rule->getError()]); + } + $category=CategoryModel::find($params['category_id']); + $category['category_name']=$params['category_name']; + $category['category_desc']=$params['category_desc']; + $category['update_time']=time(); + $result=$category->save(); + $addr='Category'; + return View::fetch('public/tips',['result'=>$result, + 'addr'=>$addr + ]); + + } + + public function delete() + { + $params = Request::param('category_id'); + $article =ArticleModel::find($params); + if ($article) { + echo "分类下面有文章" . "返回列表页"; + exit(); + } + $result = CategoryModel::destroy($params); + $addr='Category'; + return View::fetch('public/tips',['result'=>$result, + 'addr'=>$addr + ]); + } +} \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Index.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Index.php" new file mode 100644 index 0000000000000000000000000000000000000000..677cfdd769a13e3a88e5ce221c799c49820d1cae --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/controller/Index.php" @@ -0,0 +1,12 @@ +返回上一页"; + exit(); + } + if (empty($params['admin_password'])){ + echo "密码不能为空"."返回上一页"; + exit(); + } + $admin=AdminModel::where("admin_email","=",$params['admin_email'])->find(); + $salt = "0w37qVYCCu#SV7s4x3ctMNwQS@&4Hc"; + $adminPassword = md5($salt. md5($salt . $params['admin_password'] . $salt) . $salt); + if($admin['admin_password']==$adminPassword){ + session('admin_name',$admin['admin_name']); + session('admin_email',$params['admin_email']); + session('admin_password',$params['admin_password']); + echo "登录成功"."前往文章列表页面"; + }else{ + echo "密码错误"."返回上一页"; + exit(); + } + } + public function logout(){ + session('admin_email',''); + session('admin_email',''); + session('admin_password',''); + echo "登出成功"."前往登录页面"; + exit(); + } +} \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/event.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/event.php" new file mode 100644 index 0000000000000000000000000000000000000000..4eff8908bd643cd6072b9fde6ee38ca4ad6f04ad --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/event.php" @@ -0,0 +1,5 @@ +pathinfo())) {//获取地址 + if (empty(session("admin_email"))){ + return redirect('/index.php?s=admin/Login/index'); + } + } + $response=$next($request); + + return $response; + } + public function end(Response $response){ + + } +} \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/add.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/add.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..1396a39203379bceef65e232abf2f6aedb6c919d --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/add.phtml" @@ -0,0 +1,42 @@ + + + + + + + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/edit.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/edit.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..3826d902c9d837e86f2df91b2c9d10172c067c5d --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/edit.phtml" @@ -0,0 +1,41 @@ + + + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/index.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/index.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..807c852ac07179ea91951368dd45d295124bdbbe --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Admin/index.phtml" @@ -0,0 +1,42 @@ + + + \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/add.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/add.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..e9e57cdc8e1e09c9b04113825e9288ac95267d9c --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/add.phtml" @@ -0,0 +1,52 @@ + + + + \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/edit.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/edit.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..9413752ae5e8cc4a153a09898e986b0966276ae2 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/edit.phtml" @@ -0,0 +1,53 @@ + + + + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/index.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/index.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..ee247f01858879f7b7894d47d99dd1300c5f881a --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Article/index.phtml" @@ -0,0 +1,52 @@ + + + + + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/add.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/add.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..a5ec462d78bb96ea4d8640b39067d4b80a858bf3 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/add.phtml" @@ -0,0 +1,34 @@ + + + \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/edit.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/edit.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..2febdb22d8dda6201d3e27d99c5d62719b2be012 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/edit.phtml" @@ -0,0 +1,40 @@ + + + \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/index.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/index.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..69c31066f8301ad3dce726c37f6be7c12b158916 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Category/index.phtml" @@ -0,0 +1,45 @@ + + + + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Login/index.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Login/index.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..0e8a4d917c7c3b1544ff9f8e24d23777551fd76e --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/Login/index.phtml" @@ -0,0 +1,33 @@ + + + + + 登录 + + + +
+
+
+

非常日记后台管理

+
+ +
+

请输入账号和密码

+
+
+
+
+ + +
+
记住我
+ +
+
+ + +
+
+ + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/fool.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/fool.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..6cd1c4bb227e91d90b4d8059fb0421efd017af6d --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/fool.phtml" @@ -0,0 +1,4 @@ + + + + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/herd.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/herd.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..a2b57e40aa4675d89de46eaf8537d309b726a6ca --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/herd.phtml" @@ -0,0 +1,28 @@ + + + + + + + + + + + + +
+ + +
+ +
\ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/tips.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/tips.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..441101e6d66515b20442d43a9371c052c4df1b3c --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/tips.phtml" @@ -0,0 +1,9 @@ +返回列表页"; + exit(); +} else { + echo "操作失败,错误信息 " ."返回列表页; +"; +} diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/tips_error.phtml" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/tips_error.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..49077b1e6b418015d34b5c0d2e7579d8189765fb --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/admin/view/public/tips_error.phtml" @@ -0,0 +1,3 @@ +返回上一页"; \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/index/common.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/index/common.php" new file mode 100644 index 0000000000000000000000000000000000000000..124361568ff89529382ad44b04b53d6fd7543152 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/index/common.php" @@ -0,0 +1,2 @@ +wordv1(); + }else if($v==2){ + return $this->wordv2(); + } + + } + public function wordv1(){ + $content = Request::param("content"); + $validate = Validate::rule([ + 'content|文章内容' => 'require|min:10|max:100', + ]); + if (!$validate->check(['content' => $content])) { + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + $words = array_values(array_unique(explode(' ', $content))); + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => $words, + ]; + return json($data); + } + public function wordv2(){ + $content = Request::param("content"); + $validate = Validate::rule([ + 'content|文章内容' => 'require|min:10|max:100', + ]); + if (!$validate->check(['content' => $content])) { + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + $contList=[]; + $words = explode(' ', $content); + foreach ($words as $word){ + if (empty($contList[$word])){ + $contList[$word]=0; + }; + $contList[$word]++; + }; + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => $contList, + ]; + return json($data); + } + public function jisuan(){ + $str=Request::param('str'); + $str=trim($str); + $validate = Validate::rule([ + 'str|文章内容' => 'require|min:1|max:100', + ]); + if (!$validate->check(['str' => $str])) { + $data = [ + 'status' => 1, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + $strLen=mb_strlen($str); + $date=[ + 'status' => 0, + 'message' => $validate->getError(), + 'data' => [ + 'length' =>$strLen, + ], + ]; + return json($date); + } +} diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/app/index/event.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/index/event.php" new file mode 100644 index 0000000000000000000000000000000000000000..4eff8908bd643cd6072b9fde6ee38ca4ad6f04ad --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/app/index/event.php" @@ -0,0 +1,5 @@ +=7.1.0", + "topthink/framework": "^6.0.0", + "topthink/think-orm": "^2.0", + "topthink/think-multi-app": "^1.0", + "topthink/think-view": "^1.0" + }, + "require-dev": { + "symfony/var-dumper": "^4.2", + "topthink/think-trace":"^1.0" + }, + "autoload": { + "psr-4": { + "app\\": "app" + }, + "psr-0": { + "": "extend/" + } + }, + "config": { + "preferred-install": "dist" + }, + "scripts": { + "post-autoload-dump": [ + "@php think service:discover", + "@php think vendor:publish" + ] + } +} diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/composer.lock" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/composer.lock" new file mode 100644 index 0000000000000000000000000000000000000000..0d1f4ccfc363a869d9b77d3bd6abd0d760c5e613 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/composer.lock" @@ -0,0 +1,1202 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "af4c1d3fa817eb8c58caa9a7ec0362b0", + "packages": [ + { + "name": "league/flysystem", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem.git", + "reference": "9be3b16c877d477357c015cec057548cf9b2a14a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/9be3b16c877d477357c015cec057548cf9b2a14a", + "reference": "9be3b16c877d477357c015cec057548cf9b2a14a", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-fileinfo": "*", + "league/mime-type-detection": "^1.3", + "php": "^7.2.5 || ^8.0" + }, + "conflict": { + "league/flysystem-sftp": "<1.0.6" + }, + "require-dev": { + "phpspec/prophecy": "^1.11.1", + "phpunit/phpunit": "^8.5.8" + }, + "suggest": { + "ext-fileinfo": "Required for MimeType", + "ext-ftp": "Allows you to use FTP server storage", + "ext-openssl": "Allows you to use FTPS server storage", + "league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2", + "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3", + "league/flysystem-azure": "Allows you to use Windows Azure Blob storage", + "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching", + "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem", + "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files", + "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib", + "league/flysystem-webdav": "Allows you to use WebDAV storage", + "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter", + "spatie/flysystem-dropbox": "Allows you to use Dropbox storage", + "srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Flysystem\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frenky.net" + } + ], + "description": "Filesystem abstraction: Many filesystems, one API.", + "keywords": [ + "Cloud Files", + "WebDAV", + "abstraction", + "aws", + "cloud", + "copy.com", + "dropbox", + "file systems", + "files", + "filesystem", + "filesystems", + "ftp", + "rackspace", + "remote", + "s3", + "sftp", + "storage" + ], + "support": { + "issues": "https://github.com/thephpleague/flysystem/issues", + "source": "https://github.com/thephpleague/flysystem/tree/1.x" + }, + "funding": [ + { + "url": "https://offset.earth/frankdejonge", + "type": "other" + } + ], + "time": "2020-08-23T07:39:11+00:00" + }, + { + "name": "league/flysystem-cached-adapter", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-cached-adapter.git", + "reference": "d1925efb2207ac4be3ad0c40b8277175f99ffaff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-cached-adapter/zipball/d1925efb2207ac4be3ad0c40b8277175f99ffaff", + "reference": "d1925efb2207ac4be3ad0c40b8277175f99ffaff", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "league/flysystem": "~1.0", + "psr/cache": "^1.0.0" + }, + "require-dev": { + "mockery/mockery": "~0.9", + "phpspec/phpspec": "^3.4", + "phpunit/phpunit": "^5.7", + "predis/predis": "~1.0", + "tedivm/stash": "~0.12" + }, + "suggest": { + "ext-phpredis": "Pure C implemented extension for PHP" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\Cached\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "frankdejonge", + "email": "info@frenky.net" + } + ], + "description": "An adapter decorator to enable meta-data caching.", + "support": { + "issues": "https://github.com/thephpleague/flysystem-cached-adapter/issues", + "source": "https://github.com/thephpleague/flysystem-cached-adapter/tree/master" + }, + "time": "2020-07-25T15:56:04+00:00" + }, + { + "name": "league/mime-type-detection", + "version": "1.7.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/mime-type-detection.git", + "reference": "3b9dff8aaf7323590c1d2e443db701eb1f9aa0d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/3b9dff8aaf7323590c1d2e443db701eb1f9aa0d3", + "reference": "3b9dff8aaf7323590c1d2e443db701eb1f9aa0d3", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-fileinfo": "*", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.18", + "phpstan/phpstan": "^0.12.68", + "phpunit/phpunit": "^8.5.8 || ^9.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\MimeTypeDetection\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "Mime-type detection for Flysystem", + "support": { + "issues": "https://github.com/thephpleague/mime-type-detection/issues", + "source": "https://github.com/thephpleague/mime-type-detection/tree/1.7.0" + }, + "funding": [ + { + "url": "https://github.com/frankdejonge", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/league/flysystem", + "type": "tidelift" + } + ], + "time": "2021-01-18T20:58:21+00:00" + }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "support": { + "source": "https://github.com/php-fig/cache/tree/master" + }, + "time": "2016-08-06T20:24:11+00:00" + }, + { + "name": "psr/container", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf", + "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/1.1.1" + }, + "time": "2021-03-05T17:36:06+00:00" + }, + { + "name": "psr/log", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.3" + }, + "time": "2020-03-23T09:12:05+00:00" + }, + { + "name": "psr/simple-cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "support": { + "source": "https://github.com/php-fig/simple-cache/tree/master" + }, + "time": "2017-10-23T01:57:42+00:00" + }, + { + "name": "topthink/framework", + "version": "v6.0.7", + "source": { + "type": "git", + "url": "https://github.com/top-think/framework.git", + "reference": "db8fe22520a9660dd5e4c87e304034ac49e39270" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/framework/zipball/db8fe22520a9660dd5e4c87e304034ac49e39270", + "reference": "db8fe22520a9660dd5e4c87e304034ac49e39270", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "league/flysystem": "^1.0", + "league/flysystem-cached-adapter": "^1.0", + "php": ">=7.1.0", + "psr/container": "~1.0", + "psr/log": "~1.0", + "psr/simple-cache": "^1.0", + "topthink/think-helper": "^3.1.1", + "topthink/think-orm": "^2.0" + }, + "require-dev": { + "mikey179/vfsstream": "^1.6", + "mockery/mockery": "^1.2", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "autoload": { + "files": [], + "psr-4": { + "think\\": "src/think/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + }, + { + "name": "yunwuxin", + "email": "448901948@qq.com" + } + ], + "description": "The ThinkPHP Framework.", + "homepage": "http://thinkphp.cn/", + "keywords": [ + "framework", + "orm", + "thinkphp" + ], + "support": { + "issues": "https://github.com/top-think/framework/issues", + "source": "https://github.com/top-think/framework/tree/v6.0.7" + }, + "time": "2021-01-25T14:48:29+00:00" + }, + { + "name": "topthink/think-helper", + "version": "v3.1.4", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-helper.git", + "reference": "c28d37743bda4a0455286ca85b17b5791d626e10" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-helper/zipball/c28d37743bda4a0455286ca85b17b5791d626e10", + "reference": "c28d37743bda4a0455286ca85b17b5791d626e10", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "think\\": "src" + }, + "files": [ + "src/helper.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "yunwuxin", + "email": "448901948@qq.com" + } + ], + "description": "The ThinkPHP6 Helper Package", + "support": { + "issues": "https://github.com/top-think/think-helper/issues", + "source": "https://github.com/top-think/think-helper/tree/3.0" + }, + "time": "2019-11-08T08:01:10+00:00" + }, + { + "name": "topthink/think-multi-app", + "version": "v1.0.14", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-multi-app.git", + "reference": "ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-multi-app/zipball/ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3", + "reference": "ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1.0", + "topthink/framework": "^6.0.0" + }, + "type": "library", + "extra": { + "think": { + "services": [ + "think\\app\\Service" + ] + } + }, + "autoload": { + "psr-4": { + "think\\app\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "thinkphp6 multi app support", + "support": { + "issues": "https://github.com/top-think/think-multi-app/issues", + "source": "https://github.com/top-think/think-multi-app/tree/master" + }, + "time": "2020-07-12T13:50:37+00:00" + }, + { + "name": "topthink/think-orm", + "version": "v2.0.39", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-orm.git", + "reference": "39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-orm/zipball/39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7", + "reference": "39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-json": "*", + "ext-pdo": "*", + "php": ">=7.1.0", + "psr/log": "~1.0", + "psr/simple-cache": "^1.0", + "topthink/think-helper": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^7|^8|^9.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "think\\": "src" + }, + "files": [ + "stubs/load_stubs.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "think orm", + "keywords": [ + "database", + "orm" + ], + "support": { + "issues": "https://github.com/top-think/think-orm/issues", + "source": "https://github.com/top-think/think-orm/tree/v2.0.39" + }, + "time": "2021-02-26T10:20:00+00:00" + }, + { + "name": "topthink/think-template", + "version": "v2.0.8", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-template.git", + "reference": "abfc293f74f9ef5127b5c416310a01fe42e59368" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-template/zipball/abfc293f74f9ef5127b5c416310a01fe42e59368", + "reference": "abfc293f74f9ef5127b5c416310a01fe42e59368", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1.0", + "psr/simple-cache": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "think\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "the php template engine", + "support": { + "issues": "https://github.com/top-think/think-template/issues", + "source": "https://github.com/top-think/think-template/tree/v2.0.8" + }, + "time": "2020-12-10T07:52:03+00:00" + }, + { + "name": "topthink/think-view", + "version": "v1.0.14", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-view.git", + "reference": "edce0ae2c9551ab65f9e94a222604b0dead3576d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-view/zipball/edce0ae2c9551ab65f9e94a222604b0dead3576d", + "reference": "edce0ae2c9551ab65f9e94a222604b0dead3576d", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1.0", + "topthink/think-template": "^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "think\\view\\driver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "thinkphp template driver", + "support": { + "issues": "https://github.com/top-think/think-view/issues", + "source": "https://github.com/top-think/think-view/tree/v1.0.14" + }, + "time": "2019-11-06T11:40:13+00:00" + } + ], + "packages-dev": [ + { + "name": "symfony/polyfill-mbstring", + "version": "v1.22.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "5232de97ee3b75b0360528dae24e73db49566ab1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/5232de97ee3b75b0360528dae24e73db49566ab1", + "reference": "5232de97ee3b75b0360528dae24e73db49566ab1", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.22.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-22T09:19:47+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.22.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "cc6e6f9b39fe8075b3dabfbaf5b5f645ae1340c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/cc6e6f9b39fe8075b3dabfbaf5b5f645ae1340c9", + "reference": "cc6e6f9b39fe8075b3dabfbaf5b5f645ae1340c9", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php72/tree/v1.22.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-07T16:49:33+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "v1.22.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dc3063ba22c2a1fd2f45ed856374d79114998f91", + "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php80/tree/v1.22.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-07T16:49:33+00:00" + }, + { + "name": "symfony/var-dumper", + "version": "v4.4.21", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "0da0e174f728996f5d5072d6a9f0a42259dbc806" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/0da0e174f728996f5d5072d6a9f0a42259dbc806", + "reference": "0da0e174f728996f5d5072d6a9f0a42259dbc806", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1.3", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php72": "~1.5", + "symfony/polyfill-php80": "^1.15" + }, + "conflict": { + "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", + "symfony/console": "<3.4" + }, + "require-dev": { + "ext-iconv": "*", + "symfony/console": "^3.4|^4.0|^5.0", + "symfony/process": "^4.4|^5.0", + "twig/twig": "^1.43|^2.13|^3.0.4" + }, + "suggest": { + "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", + "ext-intl": "To show region name in time zone dump", + "symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script" + }, + "bin": [ + "Resources/bin/var-dump-server" + ], + "type": "library", + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides mechanisms for walking through any arbitrary PHP variable", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "support": { + "source": "https://github.com/symfony/var-dumper/tree/v4.4.21" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-03-27T19:49:03+00:00" + }, + { + "name": "topthink/think-trace", + "version": "v1.4", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-trace.git", + "reference": "9a9fa8f767b6c66c5a133ad21ca1bc96ad329444" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-trace/zipball/9a9fa8f767b6c66c5a133ad21ca1bc96ad329444", + "reference": "9a9fa8f767b6c66c5a133ad21ca1bc96ad329444", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1.0", + "topthink/framework": "^6.0.0" + }, + "type": "library", + "extra": { + "think": { + "services": [ + "think\\trace\\Service" + ], + "config": { + "trace": "src/config.php" + } + } + }, + "autoload": { + "psr-4": { + "think\\trace\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "thinkphp debug trace", + "support": { + "issues": "https://github.com/top-think/think-trace/issues", + "source": "https://github.com/top-think/think-trace/tree/v1.4" + }, + "time": "2020-06-29T05:27:28+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=7.1.0" + }, + "platform-dev": [], + "plugin-api-version": "2.0.0" +} diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/app.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/app.php" new file mode 100644 index 0000000000000000000000000000000000000000..8c153135db47557b0fcd01695ed6eaee24cfb701 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/app.php" @@ -0,0 +1,32 @@ + env('app.host', ''), + // 应用的命名空间 + 'app_namespace' => '', + // 是否启用路由 + 'with_route' => true, + // 默认应用 + 'default_app' => 'index', + // 默认时区 + 'default_timezone' => 'Asia/Shanghai', + + // 应用映射(自动多应用模式有效) + 'app_map' => [], + // 域名绑定(自动多应用模式有效) + 'domain_bind' => [], + // 禁止URL访问的应用列表(自动多应用模式有效) + 'deny_app_list' => [], + + // 异常页面的模板文件 + 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', + + // 错误显示信息,非调试模式有效 + 'error_message' => '页面错误!请稍后再试~', + // 显示错误信息 + 'show_error_msg' => true, +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/cache.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/cache.php" new file mode 100644 index 0000000000000000000000000000000000000000..a8d69d247be95ccf50446556d71ec782080a56bb --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/cache.php" @@ -0,0 +1,29 @@ + env('cache.driver', 'file'), + + // 缓存连接方式配置 + 'stores' => [ + 'file' => [ + // 驱动方式 + 'type' => 'File', + // 缓存保存目录 + 'path' => '', + // 缓存前缀 + 'prefix' => '', + // 缓存有效期 0表示永久缓存 + 'expire' => 0, + // 缓存标签前缀 + 'tag_prefix' => 'tag:', + // 序列化机制 例如 ['serialize', 'unserialize'] + 'serialize' => [], + ], + // 更多的缓存连接 + ], +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/console.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/console.php" new file mode 100644 index 0000000000000000000000000000000000000000..a818a9800951114c99173356086b5906b6d2eb4c --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/console.php" @@ -0,0 +1,9 @@ + [ + ], +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/cookie.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/cookie.php" new file mode 100644 index 0000000000000000000000000000000000000000..d3b3aab925a32374481749793a5b71fdc3e89569 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/cookie.php" @@ -0,0 +1,20 @@ + 0, + // cookie 保存路径 + 'path' => '/', + // cookie 有效域名 + 'domain' => '', + // cookie 启用安全传输 + 'secure' => false, + // httponly设置 + 'httponly' => false, + // 是否使用 setcookie + 'setcookie' => true, + // samesite 设置,支持 'strict' 'lax' + 'samesite' => '', +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/database.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/database.php" new file mode 100644 index 0000000000000000000000000000000000000000..f39318e6dac05ed5e262f5ed8bb32569c0e006e7 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/database.php" @@ -0,0 +1,60 @@ + env('database.driver', 'mysql'), + + // 自定义时间查询规则 + 'time_query_rule' => [], + + // 自动写入时间戳字段 + // true为自动识别类型 false关闭 + // 字符串则明确指定时间字段类型 支持 int timestamp datetime date + 'auto_timestamp' => true, + + // 时间字段取出后的默认时间格式 + 'datetime_format' => 'Y-m-d H:i:s', + + // 数据库连接配置信息 + 'connections' => [ + 'mysql' => [ + // 数据库类型 + 'type' => env('database.type', 'mysql'), + // 服务器地址 + 'hostname' => env('database.hostname', '127.0.0.1'), + // 数据库名 + 'database' => env('database.database', 'blog'), + // 用户名 + 'username' => env('database.username', 'root'), + // 密码 + 'password' => env('database.password', '123456'), + // 端口 + 'hostport' => env('database.hostport', '3306'), + // 数据库连接参数 + 'params' => [], + // 数据库编码默认采用utf8 + 'charset' => env('database.charset', 'utf8mb4'), + // 数据库表前缀 + 'prefix' => env('database.prefix', ''), + + // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'deploy' => 0, + // 数据库读写是否分离 主从式有效 + 'rw_separate' => false, + // 读写分离后 主服务器数量 + 'master_num' => 1, + // 指定从服务器序号 + 'slave_no' => '', + // 是否严格检查字段是否存在 + 'fields_strict' => true, + // 是否需要断线重连 + 'break_reconnect' => false, + // 监听SQL + 'trigger_sql' => env('app_debug', true), + // 开启字段缓存 + 'fields_cache' => false, + ], + + // 更多的数据库配置信息 + ], +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/filesystem.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/filesystem.php" new file mode 100644 index 0000000000000000000000000000000000000000..965297e8f471c082fb48395c09a1c15753c7c31e --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/filesystem.php" @@ -0,0 +1,24 @@ + env('filesystem.driver', 'local'), + // 磁盘列表 + 'disks' => [ + 'local' => [ + 'type' => 'local', + 'root' => app()->getRuntimePath() . 'storage', + ], + 'public' => [ + // 磁盘类型 + 'type' => 'local', + // 磁盘路径 + 'root' => app()->getRootPath() . 'public/storage', + // 磁盘路径对应的外部URL路径 + 'url' => '/storage', + // 可见性 + 'visibility' => 'public', + ], + // 更多的磁盘配置信息 + ], +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/lang.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/lang.php" new file mode 100644 index 0000000000000000000000000000000000000000..59f320ffd7c568df4aeb9ac751de08616268a16b --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/lang.php" @@ -0,0 +1,27 @@ + env('lang.default_lang', 'zh-cn'), + // 允许的语言列表 + 'allow_lang_list' => [], + // 多语言自动侦测变量名 + 'detect_var' => 'lang', + // 是否使用Cookie记录 + 'use_cookie' => true, + // 多语言cookie变量 + 'cookie_var' => 'think_lang', + // 多语言header变量 + 'header_var' => 'think-lang', + // 扩展语言包 + 'extend_list' => [], + // Accept-Language转义为对应语言包名称 + 'accept_language' => [ + 'zh-hans-cn' => 'zh-cn', + ], + // 是否支持语言分组 + 'allow_group' => false, +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/log.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/log.php" new file mode 100644 index 0000000000000000000000000000000000000000..ea24ff9d26657863f36b69824896780b6755ca96 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/log.php" @@ -0,0 +1,45 @@ + env('log.channel', 'file'), + // 日志记录级别 + 'level' => [], + // 日志类型记录的通道 ['error'=>'email',...] + 'type_channel' => [], + // 关闭全局日志写入 + 'close' => false, + // 全局日志处理 支持闭包 + 'processor' => null, + + // 日志通道列表 + 'channels' => [ + 'file' => [ + // 日志记录方式 + 'type' => 'File', + // 日志保存目录 + 'path' => '', + // 单文件日志写入 + 'single' => false, + // 独立日志级别 + 'apart_level' => [], + // 最大日志文件数量 + 'max_files' => 0, + // 使用JSON格式记录 + 'json' => false, + // 日志处理 + 'processor' => null, + // 关闭通道日志写入 + 'close' => false, + // 日志输出格式化 + 'format' => '[%s][%s] %s', + // 是否实时写入 + 'realtime_write' => false, + ], + // 其它日志通道配置 + ], + +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/middleware.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/middleware.php" new file mode 100644 index 0000000000000000000000000000000000000000..7e1972f5a09c7f09a1801dca6742e1971cc4e26d --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/middleware.php" @@ -0,0 +1,8 @@ + [], + // 优先级设置,此数组中的中间件会按照数组中的顺序优先执行 + 'priority' => [], +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/route.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/route.php" new file mode 100644 index 0000000000000000000000000000000000000000..2f4cd12902712b07c826a16d7653399c45184a44 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/route.php" @@ -0,0 +1,45 @@ + '/', + // URL伪静态后缀 + 'url_html_suffix' => 'html', + // URL普通方式参数 用于自动生成 + 'url_common_param' => true, + // 是否开启路由延迟解析 + 'url_lazy_route' => false, + // 是否强制使用路由 + 'url_route_must' => false, + // 合并路由规则 + 'route_rule_merge' => false, + // 路由是否完全匹配 + 'route_complete_match' => false, + // 访问控制器层名称 + 'controller_layer' => 'controller', + // 空控制器名 + 'empty_controller' => 'Error', + // 是否使用控制器后缀 + 'controller_suffix' => false, + // 默认的路由变量规则 + 'default_route_pattern' => '[\w\.]+', + // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则 + 'request_cache_key' => false, + // 请求缓存有效期 + 'request_cache_expire' => null, + // 全局请求缓存排除规则 + 'request_cache_except' => [], + // 默认控制器名 + 'default_controller' => 'Index', + // 默认操作名 + 'default_action' => 'index', + // 操作方法后缀 + 'action_suffix' => '', + // 默认JSONP格式返回的处理方法 + 'default_jsonp_handler' => 'jsonpReturn', + // 默认JSONP处理方法 + 'var_jsonp_handler' => 'callback', +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/session.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/session.php" new file mode 100644 index 0000000000000000000000000000000000000000..c1ef6e16d3d96f671bae7842196338ab0347ca7d --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/session.php" @@ -0,0 +1,19 @@ + 'PHPSESSID', + // SESSION_ID的提交变量,解决flash上传跨域 + 'var_session_id' => '', + // 驱动方式 支持file cache + 'type' => 'file', + // 存储连接标识 当type使用cache的时候有效 + 'store' => null, + // 过期时间 + 'expire' => 1440, + // 前缀 + 'prefix' => '', +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/trace.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/trace.php" new file mode 100644 index 0000000000000000000000000000000000000000..fad2392d9bba5b6e9aaedf64824bc30560212aee --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/trace.php" @@ -0,0 +1,10 @@ + 'Html', + // 读取的日志通道名 + 'channel' => '', +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/config/view.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/view.php" new file mode 100644 index 0000000000000000000000000000000000000000..f602edee99b12421458261c616465da6e2778f88 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/config/view.php" @@ -0,0 +1,25 @@ + 'Think', + // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法 + 'auto_rule' => 1, + // 模板目录名 + 'view_dir_name' => 'view', + // 模板后缀 + 'view_suffix' => 'phtml', + // 模板文件名分隔符 + 'view_depr' => DIRECTORY_SEPARATOR, + // 模板引擎普通标签开始标记 + 'tpl_begin' => '{', + // 模板引擎普通标签结束标记 + 'tpl_end' => '}', + // 标签库标签开始标记 + 'taglib_begin' => '{', + // 标签库标签结束标记 + 'taglib_end' => '}', +]; diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/extend/.gitignore" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/extend/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..c96a04f008ee21e260b28f7701595ed59e2839e3 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/extend/.gitignore" @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/.htaccess" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/.htaccess" new file mode 100644 index 0000000000000000000000000000000000000000..cbc786893a070c031adbbd5f9cfb3ec3051bdf0b --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/.htaccess" @@ -0,0 +1,8 @@ + + Options +FollowSymlinks -Multiviews + RewriteEngine On + + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] + diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/left.css" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/left.css" new file mode 100644 index 0000000000000000000000000000000000000000..f42f332628b8bcf4f8db578820c2cbed8ee8c530 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/left.css" @@ -0,0 +1,18 @@ +#left { + border-right: 1px solid #ccc; + width: 13rem; + position: fixed; + padding: .875rem 1rem; + z-index: 1; +} + +#left a { + color: #28313b; + line-height: 1.875rem; + width: 100%; + display: inline-block; +} + +#left a:hover { + color: #346cb0; +} diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/login.css" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/login.css" new file mode 100644 index 0000000000000000000000000000000000000000..882e83d8a26f150790ad2ebd33cbe8369bd363db --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/login.css" @@ -0,0 +1,105 @@ +* { + margin: 0; + padding: 0; +} + +body { + background-color: #346CB0; + color: #6a6c6f; + padding-top: 8%; + font-size: 14px; +} + +#login { + width: 380px; + margin: 0 auto; +} + +#login p { + text-align: center; +} + +#login-header { + color: white; + margin: 0 0 24px 0; +} + +#login-header p { + font-size: 24px; +} + +#login-center { + background-color: white; + padding: 24px; + border-radius: 6px; + margin: 0 0 24px 0; +} + +#login-center p { + text-align: center; + margin: 10px 0; + font-size: 18px; +} + +#login-center form {} + +#login-center form div { + margin-bottom: 32px; +} + +#login-center .remember-me-div {} + +#login-center .remember-me-span { + font-weight: bold; + font-size: 14px; +} + +#login-center input[type=text], +#login-center input[type=password] { + width: 100%; + border: none; + border-bottom: 1px solid #DDDDDD; + height: 40px; + border-radius: 4px; + padding: 6px 12px; + color: #555555; + box-sizing: border-box; +} + +#login-center #verify-code { + width: 58%; +} + +#login-center #verify-img { + vertical-align: middle; + width: 40%; +} + +#login-center input[type=text]:focus, +#login-center input[type=password]:focus { + border: none; + border-bottom: 1px solid #346CB0; + outline: none; + box-shadow: none; +} + +#login-center input[type=checkbox] { + margin: 0 0 0 10px; +} + + +#login-center form .btn { + width: 100%; + height: 40px; + background-color: #346CB0; + color: white; + text-align: center; + border-radius: 4px; + border: none; + cursor: pointer; +} + +#login-footer { + color: white; + text-align: center; +} diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/main.css" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/main.css" new file mode 100644 index 0000000000000000000000000000000000000000..8fbc17523be5f8f1135189bd64bda1de577f8e22 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/main.css" @@ -0,0 +1,106 @@ +* { + margin: 0; + padding: 0; +} + +body { + font-size: 1rem; + color: #28313b; +} + +#container { + width: 100%; + min-width: 960px; + margin: 0 auto 0; +} + +ul { + list-style-type: none; +} + +a { + color: #346cb0; + text-decoration: none; +} + +a:hover { + color: #234875; + text-decoration: underline; +} + +table { + width: 100%; + border-collapse: collapse; + margin: 0 auto; +} + +.btn { + padding: 0.5rem 0.8rem; + border: none; + border-radius: 0.25rem; + outline: none; +} + +.btn:hover { + cursor: pointer; + background-color: #dedede; +} + +.btn:active { + background-color: #cccccc; +} + + + +table.list { + text-align: center; +} + +table.update tr td:first-child { + text-align: right; +} + +table caption { + margin: 10px 0; +} + +table tr th, +table tr td { + border: 1px solid #DDDDDD; + padding: 5px; +} + +input[type=text], +input[type=password] { + width: 17.5rem; + line-height: 1.3rem; + padding: .375rem .75rem; + border: 1px solid #d4d5d7; + border-radius: 0.25rem; + outline: none; +} + +textarea { + width: 460px; + height: 230px; + border: 1px solid #d4d5d7; + border-radius: 0.25rem; + padding: .375rem .75rem; + outline: none; +} + +select { + width: 6.25rem; + height: 30px; + border: 1px solid #d4d5d7; + border-radius: 0.25rem; + outline: none; +} + +input[type=text]:focus, +input[type=password]:focus, +textarea:focus, +select:focus, +select:active,select:hover { + border-color: #346cb0; +} \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/right.css" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/right.css" new file mode 100644 index 0000000000000000000000000000000000000000..0e22d365e1392cbcfce741d0f46aad59dc97737d --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/right.css" @@ -0,0 +1,30 @@ +#right { + /* border: 1px solid #ccc; */ + font-size: 0.875rem; + padding-left: 15rem; + position: relative; + overflow: hidden; +} + +#right a { + /* color: ; */ +} + +#breadcrumb { + height: 1rem; + clear: both; + margin: 0 0 1rem 0; +} + +#content { + padding: 1rem; +} + +#choose_div { + margin: 1rem 0; + line-height: 2rem; +} + +#choose_div .add { + float: right; +} \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/top.css" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/top.css" new file mode 100644 index 0000000000000000000000000000000000000000..7ff27cdfa0f1d5df7ff3f9301134718f1e5c889f --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/css/top.css" @@ -0,0 +1,29 @@ +#header { + /* border: 1px solid #ccc; */ + height: 60px; + background-color: #346CB0; + color: white; +} + +#header a { + color: #C2D3E7; +} + +#header h1 { + width: 14rem; + display: inline-block; + border-right: 1px solid #2E5F9B; + line-height: 60px; + background-color: #2E5F9B; + color: white; + text-align: left; + padding: 0 0 0 1rem; + font-size: 1.5rem; +} + +#header #login_info { + float: right; + text-align: right; + line-height: 60px; + padding: 0 10px; +} \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/favicon.ico" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/favicon.ico" new file mode 100644 index 0000000000000000000000000000000000000000..e71815a6618c6ef19c78d27840b8995fb2521499 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/favicon.ico" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/index.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/index.php" new file mode 100644 index 0000000000000000000000000000000000000000..e3c0fe9083c5540d7149b1277acc679ea18ed48e --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/index.php" @@ -0,0 +1,24 @@ + +// +---------------------------------------------------------------------- + +// [ 应用入口文件 ] +namespace think; + +require __DIR__ . '/../vendor/autoload.php'; + +// 执行HTTP应用并响应 +$http = (new App())->http; + +$response = $http->run(); + +$response->send(); + +$http->end($response); diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/robots.txt" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/robots.txt" new file mode 100644 index 0000000000000000000000000000000000000000..eb0536286f3081c6c0646817037faf5446e3547d --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/robots.txt" @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/router.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/router.php" new file mode 100644 index 0000000000000000000000000000000000000000..9b39a62c9771c00bd676713be4bb48f3a5cdc443 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/router.php" @@ -0,0 +1,19 @@ + +// +---------------------------------------------------------------------- +// $Id$ + +if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) { + return false; +} else { + $_SERVER["SCRIPT_FILENAME"] = __DIR__ . '/index.php'; + + require __DIR__ . "/index.php"; +} diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/public/static/.gitignore" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/static/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..c96a04f008ee21e260b28f7701595ed59e2839e3 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/public/static/.gitignore" @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/route/app.php" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/route/app.php" new file mode 100644 index 0000000000000000000000000000000000000000..d8e09e382ddf3b67e3193d5ac5cc6b9226959a68 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/route/app.php" @@ -0,0 +1,17 @@ + +// +---------------------------------------------------------------------- +use think\facade\Route; + +Route::get('think', function () { + return 'hello,ThinkPHP6!'; +}); + +Route::get('hello/:name', 'index/hello'); diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/runtime/.gitignore" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/runtime/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..c96a04f008ee21e260b28f7701595ed59e2839e3 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/runtime/.gitignore" @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/think" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/think" new file mode 100644 index 0000000000000000000000000000000000000000..2429d223a2e44b29a52a721ae88d4085c0d274f3 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/think" @@ -0,0 +1,10 @@ +#!/usr/bin/env php +console->run(); \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/blog/view/README.md" "b/\350\224\241\346\226\207\351\276\231/5.10/blog/view/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..360eb2468af9fd86de756c4cf26e9b90ee63cb26 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/blog/view/README.md" @@ -0,0 +1 @@ +如果不使用模板,可以删除该目录 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.10/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/\350\224\241\346\226\207\351\276\231/5.10/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" new file mode 100644 index 0000000000000000000000000000000000000000..c1e2b1e6d6b19be9b7ebdae2107abbdd2fb2974b --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.10/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" @@ -0,0 +1,13 @@ +1. ֪ҪģɾIJ飬صĽӿurl + http://api.example.com/category/add/ + http://api.example.com/category/update/ + http://api.example.com/category/detail/ + http://api.example.com/category/search/ +2. ֪ҪģɾIJ飬صĽӿurl + + http://api.example.com/article/add/ + http://api.example.com/article/update/ + http://api.example.com/article/detail/ + http://api.example.com/article/search/ +3. ֪¼Ҫʹýӿʵ֣صĽӿurl + http://api.example.com/login/login/ \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/01_http\344\273\213\347\273\215.md" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/01_http\344\273\213\347\273\215.md" new file mode 100644 index 0000000000000000000000000000000000000000..4f9fc0e90857dc9e1e55da9c930cb988e4a9f4a9 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/01_http\344\273\213\347\273\215.md" @@ -0,0 +1,84 @@ +## 本节目标 + +1. 对http协议有大概的了解。 + +## 序言 + +前面我们对api和web api有个初步的认识,了解到web api是基于http协议的。 + +那么http协议是什么呢?本章将对http做一个简单的介绍。 + +## HTTP协议简介 + +超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一种用于分布式、协作式和超媒体信息系统的应用层协议。HTTP是万维网的数据通信的基础。 + +HTTP的发展是由蒂姆·伯纳斯-李于1989年在欧洲核子研究组织(CERN)所发起。 + +HTTP的标准制定由万维网协会(World Wide Web Consortium,W3C)和互联网工程任务组(Internet Engineering Task Force,IETF)进行协调,最终发布了一系列的RFC,其中最著名的是1999年6月公布的 RFC 2616,定义了HTTP协议中现今广泛使用的一个版本——HTTP 1.1。 + +2014年12月,互联网工程任务组(IETF)的Hypertext Transfer Protocol Bis(httpbis)工作小组将HTTP/2标准提议递交至IESG进行讨论,于2015年2月17日被批准。 HTTP/2标准于2015年5月以RFC 7540正式发表,取代HTTP 1.1成为HTTP的实现标准。 + +简单理解:http协议是由国际标准组织设计和定义的。 + +## HTTP协议概述 + +HTTP是一个客户端终端(用户)和服务器端(网站)请求和应答的标准(TCP)。 + +这边涉及3个端: + +1. 客户端(必须) +2. 服务端(必须) +3. 中间层(可选) + +### 客户端 + +通过使用网页浏览器、网络爬虫或者其它的工具,客户端发起一个HTTP请求到服务器上指定端口(默认端口为80)。我们称这个客户端为用户代理程序(user agent)。 + +### 服务端 + +应答的服务器上存储着一些资源,比如HTML文件和图像。我们称这个应答服务器为源服务器(origin server)。 + +思考: + + 当我们访问淘宝网站的时候,服务端是指?客户端是指? + +### 中间层 + +在用户代理和源服务器中间可能存在多个“中间层”,比如代理服务器、网关或者隧道(tunnel)。 + +思考: + + 我们访问国外的网站,如果访问不了,可以有什么解决办法呢? + +## 传输层tcp协议 + +尽管TCP/IP协议是互联网上最流行的应用,HTTP协议中,并没有规定必须使用它或它支持的层。 + +事实上,HTTP可以在任何互联网协议上,或其他网络上实现。 + +HTTP假定其下层协议提供可靠的传输。 + +因此,任何能够提供这种保证的协议都可以被其使用。因此也就是其在TCP/IP协议族使用TCP作为其传输层。 + +## http原理简介 + +1. HTTP服务器则在指定端口(默认是80)监听客户端的请求。 +2. 由HTTP客户端发起一个请求,创建一个到服务器指定端口(默认是80端口)的TCP连接。 +3. 一旦收到请求,服务器会向客户端返回一个状态,比如"HTTP/1.1 200 OK",以及返回的内容,如请求的文件、错误消息、或者其它信息。 + +请大家思考下: + + 如果用户不请求服务端,服务端会发送数据吗? + +这边只有客户端发送请求,服务端才会响应,这种可以叫做被动式的响应,这个可以称作是http的一个特点。 + +思考: + + 有没有什么业务场景服务端会主动发送数据的? + +## 本节总结 + +1. http是国际标准组织设计和定义的。 +2. http使用tcp协议作为传输层。 +3. http中有客户端和服务端的概念。 +4. http是被动式的一种协议,有请求才相应。 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/02_http\345\216\237\347\220\206.md" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/02_http\345\216\237\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..345c6e91a2ab78149048de9c64f08cfe6540ea49 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/02_http\345\216\237\347\220\206.md" @@ -0,0 +1,120 @@ +## 本节目标 + +1. 熟悉http的工作原理 + +## http步骤 + +前面我们对http原理进行了简单的介绍,本节介绍的更详细一些。 + +HTTP协议定义Web客户端如何从Web服务器请求Web页面,以及服务器如何把Web页面传送给客户端。 + +HTTP协议采用了请求/响应模型。客户端向服务器发送一个请求报文,请求报文包含请求的方法、URL、协议版本、请求头部和请求数据。 + +服务器以一个状态行作为响应,响应的内容包括协议的版本、成功或者错误代码、服务器信息、响应头部和响应数据。 + +参考下图: + +![](02_http原理_files/1.jpg) + +### 详细步骤 + +以下是 HTTP 请求/响应的步骤: + +1)客户端连接到Web服务器 + +一个HTTP客户端,通常是浏览器,与Web服务器的HTTP端口(默认为80)建立一个TCP套接字连接。例如,http://www.baidu.com + +2)发送HTTP请求 + +通过TCP套接字,客户端向Web服务器发送一个文本的请求报文,一个请求报文由请求行、请求头部、空行和请求数据4部分组成。 + +3)服务器接受请求并返回HTTP响应 + +Web服务器解析请求,定位请求资源。服务器将资源复本写到TCP套接字,由客户端读取。一个响应由状态行、响应头部、空行和响应数据4部分组成。 + +4)释放连接TCP连接 + +若connection 模式为close,则服务器主动关闭TCP连接,客户端被动关闭连接,释放TCP连接;若connection 模式为keepalive,则该连接会保持一段时间,在该时间内可以继续接收请求; + +5)客户端浏览器解析HTML内容 + +客户端浏览器首先解析状态行,查看表明请求是否成功的状态代码。然后解析每一个响应头,响应头告知以下为若干字节的HTML文档和文档的字符集。客户端浏览器读取响应数据HTML,根据HTML的语法对其进行格式化,并在浏览器窗口中显示。 + +**例如**:在浏览器地址栏键入URL,按下回车之后会经历以下流程: + +1. 浏览器向 DNS 服务器请求解析该 URL 中的域名所对应的 IP 地址; +2. 解析出 IP 地址后,根据该 IP 地址和默认端口 80,和服务器建立TCP连接; +3. 浏览器发出读取文件(URL 中域名后面部分对应的文件)的HTTP 请求,该请求报文作为 TCP 三次握手的第三个报文的数据发送给服务器; +4. 服务器对浏览器请求作出响应,并把对应的 html 文本发送给浏览器; +5. 释放 TCP连接; +6. 浏览器将该 html 文本并显示内容; + +**http协议是基于TCP/IP协议之上的应用层协议。** + +## 请求/响应模式 + +HTTP协议规定,请求从客户端发出,最后服务器端响应该请求并 返回。 + +换句话说,肯定是先从客户端开始建立通信的,服务器端在没有 接收到请求之前不会发送响应。 + +![](02_http原理_files/2.jpg) + +## 无状态 + +HTTP是一种不保存状态,即无状态(stateless)协议。 + +HTTP协议 自身不对请求和响应之间的通信状态进行保存。也就是说在HTTP这个 级别,协议对于发送过的请求或响应都不做持久化处理。 + +![](02_http原理_files/3.jpg) + +使用HTTP协议,每当有新的请求发送时,就会有对应的新响应产生。协议本身并不保留之前一切的请求或响应报文的信息。 + +这是为了更快地处理大量事务,确保协议的可伸缩性,而特意把HTTP协议设计成 如此简单的。 + +**示例1**,我们访问一个页面index.php,传递一个参数m,告诉他我是 “小明”: + +```js + |%3E| +|? |%3F| +|@ |%40| +|\ |%5C| +|\| |%7C| + +思考: + + 1. 从码云上clone,可以使用什么协议方式? + 2. 如果使用http方法,尝试在http协议上加上凭据信息,从而可以直接clone,而不用弹出账号和密码输入框。 + +## 本节总结 + +url其实就是访问服务器资源的规则。 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/03_http\350\257\267\346\261\202\346\226\271\346\263\225_files/1.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/03_http\350\257\267\346\261\202\346\226\271\346\263\225_files/1.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..80b2ce6d7caa315ccc599418642f565f76daef86 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/03_http\350\257\267\346\261\202\346\226\271\346\263\225_files/1.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/04_http\350\257\267\346\261\202\346\226\271\346\263\225.md" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/04_http\350\257\267\346\261\202\346\226\271\346\263\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..070ae73cd78a4af974403a7307429480f04b1a1b --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/04_http\350\257\267\346\261\202\346\226\271\346\263\225.md" @@ -0,0 +1,84 @@ +## 本节目标 + +1. 熟悉get请求方法 +2. 熟悉post请求方法 +3. 了解其他http请求方法 + +## http请求方法 + +HTTP/1.1协议中共定义了八种方法(也叫“动作”)来以不同方式操作指定的资源: + +1)GET + +向指定的资源发出“显示”请求。使用GET方法应该只用在读取数据,而不应当被用于产生“副作用”的操作中,例如在Web Application中。其中一个原因是GET可能会被网络蜘蛛等随意访问。 + +2)HEAD + +与GET方法一样,都是向服务器发出指定资源的请求。只不过服务器将不传回资源的本文部分。它的好处在于,使用这个方法可以在不必传输全部内容的情况下,就可以获取其中“关于该资源的信息”(元信息或称元数据)。 + +3)POST + +向指定资源提交数据,请求服务器进行处理(例如提交表单或者上传文件)。数据被包含在请求本文中。这个请求可能会创建新的资源或修改现有资源,或二者皆有。 + +4)PUT + +向指定资源位置上传其最新内容。 + +5)DELETE + +请求服务器删除Request-URI所标识的资源。 + +6)TRACE + +回显服务器收到的请求,主要用于测试或诊断。 + +7)OPTIONS + +这个方法可使服务器传回该资源所支持的所有HTTP请求方法。用'*'来代替资源名称,向Web服务器发送OPTIONS请求,可以测试服务器功能是否正常运作。 + +8)CONNECT + +HTTP/1.1协议中预留给能够将连接改为管道方式的代理服务器。通常用于SSL加密服务器的链接(经由非加密的HTTP代理服务器)。 + +这边重点了解get和post方法即可。 + +## GET方法 + +GET提交的数据会放在URL之后,也就是请求行里面,以?分割URL和传输数据,参数之间以&相连。 + +例如: + + EditBook?name=test1&id=123456 + +## POST方法 + +POST方法是把提交的数据放在HTTP包的请求体中。不在url地址栏上呈现。 + +**示例1**,比如设计一个表单post提交到save.php页面: + +```html + + + + + + + +
+ 用户名: +
+ 手机号: +
+ +
+ + +``` + +输入内容进行提交,我们可以看到地址栏并没有用户名和手机号信息,通过浏览器的调试工具可以看到提交的数据: + +![](04_http请求方法_files/1.jpg) + +## 本节总结 + +http有很多中请求方法,一般熟悉get和post就可以了。 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/04_http\350\257\267\346\261\202\346\226\271\346\263\225_files/1.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/04_http\350\257\267\346\261\202\346\226\271\346\263\225_files/1.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..b04a084782da83d9a6e8d64fd8e19ed6f7ebb106 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/04_http\350\257\267\346\261\202\346\226\271\346\263\225_files/1.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201.md" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201.md" new file mode 100644 index 0000000000000000000000000000000000000000..2c16219db8281c697ad3b21e73a6816642fcf904 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201.md" @@ -0,0 +1,117 @@ +## 本节目标 + +1. 熟悉http中常见状态码 + +## http状态码 + +所有HTTP响应的第一行都是状态行,依次是当前HTTP版本号,3位数字组成的状态代码,以及描述状态的短语,彼此由空格分隔。 + +状态代码的第一个数字代表当前响应的类型: + +1. 1xx消息——请求已被服务器接收,继续处理。 +2. 2xx成功——请求已成功被服务器接收、理解、并接受。 +3. 3xx重定向——需要后续操作才能完成这一请求。 +4. 4xx请求错误——请求含有词法错误或者无法被执行。 +5. 5xx服务器错误——服务器在处理某个正确请求时发生错误。 + +虽然 RFC 2616 中已经推荐了描述状态的短语,例如"200 OK","404 Not Found",但是WEB开发者仍然能够自行决定采用何种短语,用以显示本地化的状态描述或者自定义信息。 + +## 常见状态码 + + 1. 200 ok。 + 2. 302 跳转。 + 3. 304 没有修改 + 3. 403 没有权限。 + 4. 404 文件不存在。 + 5. 502 网关错误。 + 6. 504 网关超时。 + +### 200 + +200 状态表示访问的文件正常。 + +**示例1**, 假设web根目录下存在index.html文件,访问这个文件,使用浏览器调试工具查看: + +![](05_http状态码_files/1.jpg) + +### 302 + +302表示重定向的意思,俗称跳转。 + +**示例1**,设置一个页面,跳转到 www.baidu.com 首页: + +```js +header("Location: http://www.baidu.com"); +``` + +![](05_http状态码_files/2.jpg) + +### 304 + +304表示页面没有修改,直接加载缓存里的数据。 + +**示例1**,设置一个html页面1.html,第一次访问是200,再次访问就是304了: + +![](05_http状态码_files/10.jpg) + +思考:304状态的设计有什么意义? + +如果要重新从服务端下载,强制刷新即可。快捷键是:Ctrl+Shirt+F5。 + +### 403 + +403表示没有访问权限。 + +**示例1**,web服务器不开启目录内文件的访问方式,访问目录就会提示没有权限: + +![](05_http状态码_files/7.jpg) + +**示例2**,开启访问目录的权限: + + location / { + root html; + index index.html index.htm; + autoindex on; + } + +autoindex on; 表示允许访问目录。 + +![](05_http状态码_files/8.jpg) + +### 404 + +404 表示请求的资源不存在。简单的说就是访问的页面不存在。 + +**示例1**,访问一个不存在的页面,提示404: + +![](05_http状态码_files/3.jpg) + +我们访问网站的时候,经常会碰到如下一个请求是404: + +![](05_http状态码_files/4.jpg) + +请问这个是什么原因? + +### 502 + +502 表示网关错误的意思。 + +**示例1**,修改nginx.conf,将php-cgi端口改掉: + +![](05_http状态码_files/6.jpg) + +### 504 + +504表示超时的意思,一般在服务器宕机的时候经常会出现。 + +**示例1**,使用sleep方法然服务器慢点返回数据: + +```js +sleep(60); +``` + +![](05_http状态码_files/5.jpg) + +## 本节总结 + +http状态表示的时候请求返回的时候设置的一个状态值。 \ No newline at end of file diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/1.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/1.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..1489771af853cec1825564c3b08af6eaaba55c02 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/1.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/10.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/10.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..de29731744b4da8042c49499cca04120e297d0a4 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/10.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/2.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/2.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..2f93ac08141e446d758f0128d3619eeae1bb99f3 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/2.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/3.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/3.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..9481076cbcea0174f996fe91be105326125f1303 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/3.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/4.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/4.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..67472f4621dceffb0cec6ec0cb376159da94b122 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/4.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/5.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/5.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..bcdbb67f060a17dfe93e9873ba9272a0f165880a Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/5.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/6.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/6.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..000076406fb761fe29af5da81643610c75422702 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/6.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/7.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/7.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..c72d36f03adc5c73f17d7bf027711e8b7f92a73e Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/7.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/8.jpg" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/8.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..e56e316abff4c23d04e4c76df3ef897fb84ad130 Binary files /dev/null and "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/05_http\347\212\266\346\200\201\347\240\201_files/8.jpg" differ diff --git "a/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/06_http\350\257\267\346\261\202\346\240\274\345\274\217.md" "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/06_http\350\257\267\346\261\202\346\240\274\345\274\217.md" new file mode 100644 index 0000000000000000000000000000000000000000..ff2858d588b4a52dc71fe47b6b9c9ae7cb520019 --- /dev/null +++ "b/\350\224\241\346\226\207\351\276\231/5.7/2019\347\272\247\350\256\241\345\272\224\347\217\255_webapi_20210507/02_http\345\215\217\350\256\256/06_http\350\257\267\346\261\202\346\240\274\345\274\217.md" @@ -0,0 +1,90 @@ +## 本节目标 + +1. 了解http请求格式 + +## 软件准备 + +为了更好的看到包的格式,我们安装Charles抓包工具。 + +Charles官方地址: + + https://www.charlesproxy.com/ + +配置localhost.charleproxy.com域名指向127.0.0.1。 + +编辑 C:\Windows\System32\drivers\etc\hosts 文件,增加: + + 127.0.0.1 localhost.charleproxy.com + +修改代理端口为8889,避免和原先的8888冲突: + + proxy->proxy setting,修改端口。 + +## http请求格式 + +一个完整的http请求格式: + +![](06_http请求格式_files/1.jpg) + +其中: + + 1. 请求方法 就是get和post等方法。 + 2. URL 就是指请求的地址。 + 3. 协议版本 http协议的版本,一般是HTTP/1.1。 + 4. 头部字段 这边包含了名称和值,例如Host,User-Agent等。 + 5. 请求数据 本次请求提交的数据,post的数据就是放在这里的。 + +一个简单的示例: + +![](06_http请求格式_files/1.png) + +**示例1**,请求1.html,并抓包: + +![](06_http请求格式_files/2.jpg) + +其中: + + Host 表示请求的域名。 + User-Agent 表示发起请求的客户端头信息。 + +**示例2**,比如设计一个表单post提交到save.php页面: + +```html + + + + + + + +
+ 用户名: +
+ 手机号: +
+ +
+ + +``` + +save.php页面: + +```js + + + + + Title + + +111 + + +``` + +抓包查看: + +![](07_http响应格式_files/3.jpg) + +其中: + + Content-Type 表示返回的文档格式,text/html 表示是一个html网页。 + Content-Length 表示返回的文档长度。 + 下面html代码就是返回的主体内容。 + +**示例2**,访问一个图片文件,抓包显示: + +![](07_http响应格式_files/4.jpg) + +抓包显示: + +![](07_http响应格式_files/5.jpg) + +其中: + + Content-Type 表示返回的文档格式,image/jpeg 表示是一个jpg的图片。 + Content-Length 表示返回的文档长度,这里表示什么含义呢?请同学们思考。 + 主体就是图片文件的内容。 + +**示例3**,使用thinkphp创建一个api接口,并访问: + +```php +public function sample() + { + $data = [ + 'status' => 0, + 'message' => '我只是一个美丽的错误', + 'data' => [], + ]; + return json($data); + } +``` + +抓包查看: + +![](07_http响应格式_files/7.jpg) + +其中: + + Content-Type 表示返回的文档格式,application/json 表示是一个json数据格式。 + 下面的json格式数据,就是返回的主体。 + +**示例4**,假如我们直接使用json_encode方法,看下抓包情况: + +```php +public function sample() +{ + $data = [ + 'status' => 0, + 'message' => '我只是一个美丽的错误', + 'data' => [], + ]; + return json_encode($data, JSON_UNESCAPED_UNICODE); +} +``` + +抓包查看: + +![](07_http响应格式_files/6.jpg) + +思考: + + 和上例有什么不同? + +实际上thinkphp json方法里,封装了设置header头的代码: + +```php +header("Content-Type: application/json"); +``` + +**示例5**,一个页面会实现跳转功能,访问并抓包: + +```php +