GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hapyli/thinkphp5-restfulapi: php restful-api风格接口 oauth2.0 接口版本管理 接口鉴权 tp5

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

18 Commits
18 Commits

Folders and files

NameName
Last commit message
Last commit date
application
application
 
 
extend
extend
 
 
public
public
 
 
runtime
runtime
 
 
screenshot
screenshot
 
 
tests
tests
 
 
thinkphp
thinkphp
 
 
vendor
vendor
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
build.php
build.php
 
 
composer.json
composer.json
 
 
oauth.sql
oauth.sql
 
 
phpunit.xml
phpunit.xml
 
 
think
think
 
 

Repository files navigation

ThinkPHP5 restfulapi

基于ThinkPHP5 基础上开发的一个简单的restful api ,带权限验证等

ThinkPHP5的运行环境要求PHP5.4以上。

详细开发文档参考 ThinkPHP5完全开发手册

目录结构

初始的目录结构如下:

www  WEB部署目录(或者子目录)
├─application           应用目录
│  ├─common             公共模块目录(可以更改)
│  ├─api                接口目录
│  │  ├─controller      控制器目录
│  │  │     ├─v1        版本1目录
|  |  |     ├─v2        版本2目录
│  │  ├─Api.php         授权基类
│  │  ├─Oauth.php       授权验证
│  │  ├─Send.php        返回格式
│  │  ├─model           模型目录
|  |      ├─model     
│  │  ├─view            视图目录
│  │  └─ ...            更多类库目录
│  │
│  ├─command.php        命令行工具配置文件
│  ├─common.php         公共函数文件
│  ├─config.php         公共配置文件
│  ├─route.php          路由配置文件
│  ├─tags.php           应用行为扩展定义文件
│  └─database.php       数据库配置文件
│
├─public                WEB目录(对外访问目录)
│  ├─index.php          入口文件
│  ├─router.php         快速测试文件
│  └─.htaccess          用于apache的重写
│
├─thinkphp              框架系统目录
│  ├─lang               语言文件目录
│  ├─library            框架类库目录
│  │  ├─think           Think类库包目录
│  │  └─traits          系统Trait目录
│  │
│  ├─tpl                系统模板目录
│  ├─base.php           基础定义文件
│  ├─console.php        控制台入口文件
│  ├─convention.php     框架惯例配置文件
│  ├─helper.php         助手函数文件
│  ├─phpunit.xml        phpunit配置文件
│  └─start.php          框架入口文件
│
├─extend                扩展类库目录
├─runtime               应用的运行时目录(可写,可定制)
├─vendor                第三方类库目录(Composer依赖库)
├─build.php             自动生成定义文件(参考)
├─composer.json         composer 定义文件
├─LICENSE.txt           授权说明文件
├─README.md             README 文件
├─think                 命令行入口文件

流程

  • router.php中定义了restful资源路由,具体请查看代码。
  • 访问相应的url,例如:http://localhost/tp5test/public/index.php/v1/user
  • user控制器是集成了Api类,会在初始化检测user控制器定义的访问限制 $restMethodList = 'get|post|put';
  • 在Api类中,会有方法checkAuth()检测用户是否有权限调用接口
  • checkAuth方法会调用Oauth类中的鉴权,$baseAuth = Factory::getInstance(\app\api\controller\OAuth::class);
  • 根据用户端传递过来的app_key获取缓存中的access_token,在进行对比,如果true,则可以调用user中的各种方法,否则返回不能调用原因
  • Oauth类中的具体请看代码
  • 生成access_token,缓存access_token等相关逻辑在v1/Token.php代码中,使用的是本地缓存,如果需要使用数据库或者redis请查询相关注释说明
  • 写的比较乱,直接看片段截图把。。。。

相关流程截图

流程图

截图

  • 用户类

  • Api类

  • Oauth类

  • v1/Token类

  • 测试

快速创建一个restful控制器

cd 到项目根目录

命令行 :php think make:controller api/v1/Goods

修改路由,注册一个资源路由:在route.php加入下面一行代码: Route::resource(':version/goods','api/:version.Goods');

其他说明

交流QQ群号:645233951

版权信息

遵循Apache2开源协议发布,并提供免费使用。

更多细节参阅 LICENSE.txt

About

php restful-api风格接口 oauth2.0 接口版本管理 接口鉴权 tp5

Resources

Readme
License
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.