PHPackages                             yihao-company/mqtt-test - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. yihao-company/mqtt-test

ActiveProject[Framework](/categories/framework)

yihao-company/mqtt-test
=======================

the new thinkphp framework

5.0(7y ago)02Apache-2.0PHPPHP &gt;=5.4.0

Since May 30Pushed 5y agoCompare

[ Source](https://github.com/yiyiyihao/thinkphp5-restfulapi)[ Packagist](https://packagist.org/packages/yihao-company/mqtt-test)[ Docs](http://thinkphp.cn/)[ RSS](/packages/yihao-company-mqtt-test/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

ThinkPHP5.1\* restfulapi
========================

[](#thinkphp51-restfulapi)

基于ThinkPHP5.1\* 基础上开发的一个简单的restful api ，带权限验证等

> ThinkPHP5.1的运行环境要求PHPPHP5.6+以上。

详细开发文档参考 [ThinkPHP5完全开发手册](https://www.kancloud.cn/manual/thinkphp5_1/353946)

使用目前tp5.1相关新增功能，包含容器依赖注入、Facade、验证器等，与上一个版本相比，简化代码量，整个代码量只有不到200行，增加鉴权白名单，refresh\_token、全局异常处理等
------------------------------------------------------------------------------------------------

[](#使用目前tp51相关新增功能包含容器依赖注入facade验证器等与上一个版本相比简化代码量整个代码量只有不到200行增加鉴权白名单refresh_token全局异常处理等)

欢迎PR
----

[](#欢迎pr)

老版本tp5.0\*相关代码请到release下载对应代码
-----------------------------

[](#老版本tp50相关代码请到release下载对应代码)

目录结构
----

[](#目录结构)

初始的目录结构如下：

```
www  WEB部署目录（或者子目录）==
├─application           应用目录
│  ├─common             公共模块目录（可以更改）
│  ├─api                接口目录
│  │  ├─controller      控制器目录
│  │  │     ├─v1        版本1目录
|  |  |     ├─v2        版本2目录
│  │  ├─Api.php         授权基类
│  │  ├─Oauth.php       授权验证
│  │  ├─Send.php        返回格式
|  |  |─exception       重写异常
│  │  ├─model           模型目录
|  |      ├─model
│  │  ├─view            视图目录
│  │  └─ ...            更多类库目录
│  │
│  ├─command.php        命令行工具配置文件
│  ├─common.php         公共函数文件
│  ├─config.php         公共配置文件
│  ├─route.php          路由配置文件
│  ├─tags.php           应用行为扩展定义文件
│  └─database.php       数据库配置文件
|─config                配置文件
|-routte                路由文件
├─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，例如：
- user控制器是继承了Api类
- 在Api类中，会有方法init()检测用户是否有权限调用接口
- init方法会调用Oauth类中的鉴权，$oauth = app('app\\api\\controller\\Oauth');;
- 根据用户端传递过来的app\_key获取缓存中的access\_token，在进行对比，如果true，则可以调用user中的各种方法，否则返回不能调用原因
- Oauth类中的具体请看代码
- 生成access\_token，缓存access\_token等相关逻辑在v1/Token.php代码中，使用的是本地缓存，如果需要使用数据库或者redis请查询相关注释说明
- api端请求需要在header中进行authentication字段拼接，拼接规则：authentication:USERID base64\_encode(appid:accesstoken:uid) PS:拼接示例：USERID c25haWx5X3hjeF9uZXc6M0U1TjBtR3dGSTZjZ1BoNEpLdHY4eWQyOVpqTXM3a2Y6Mzgw ，其中USERID后面跟了个空格，空格后面的一串字符串就是appid:accesstoken:uid这几个参数base64\_encode后的字符串
- uid 就是请求生成token时候返回

### 不知道header怎么传，请查看文档最后一张图，如果对参数不明白，请查看代码/Application/api/controller/Oauth.php中getClient方法，里面有逆向解密authentication值。

[](#不知道header怎么传请查看文档最后一张图如果对参数不明白请查看代码applicationapicontrolleroauthphp中getclient方法里面有逆向解密authentication值)

相关流程截图
------

[](#相关流程截图)

### 流程图

[](#流程图)

[![](https://github.com/Leslin/thinkphp5-restfulapi/raw/master/screenshot/accesstoken.png)](https://github.com/Leslin/thinkphp5-restfulapi/blob/master/screenshot/accesstoken.png)

### 截图

[](#截图)

- 路由设置 route\\route.php

[![](https://github.com/Leslin/thinkphp5-restfulapi/raw/master/screenshot/1route.png)](https://github.com/Leslin/thinkphp5-restfulapi/blob/master/screenshot/1route.png)

- Api类

[![](https://github.com/Leslin/thinkphp5-restfulapi/raw/master/screenshot/1api.png)](https://github.com/Leslin/thinkphp5-restfulapi/blob/master/screenshot/1api.png)

- Oauth类

[![](https://github.com/Leslin/thinkphp5-restfulapi/raw/master/screenshot/1oauth.png)](https://github.com/Leslin/thinkphp5-restfulapi/blob/master/screenshot/1oauth.png)

- v1/Token类

[![](https://github.com/Leslin/thinkphp5-restfulapi/raw/master/screenshot/1token.png)](https://github.com/Leslin/thinkphp5-restfulapi/blob/master/screenshot/1token.png)

### 截图

[](#截图-1)

### 1、获取token传参

[](#1获取token传参)

[![](https://github.com/Leslin/thinkphp5-restfulapi/raw/master/screenshot/1test1.png)](https://github.com/Leslin/thinkphp5-restfulapi/blob/master/screenshot/1test1.png)

### 2、获取token、刷新的token，过期时间，用户信息

[](#2获取token刷新的token过期时间用户信息)

[![](https://github.com/Leslin/thinkphp5-restfulapi/raw/master/screenshot/1test2.png)](https://github.com/Leslin/thinkphp5-restfulapi/blob/master/screenshot/1test2.png)

### 3、传递token进行请求

[](#3传递token进行请求)

- 加密头规则：USERID base64\_encode(appid:token:uid) [![](https://github.com/Leslin/thinkphp5-restfulapi/raw/master/screenshot/test4.png)](https://github.com/Leslin/thinkphp5-restfulapi/blob/master/screenshot/test4.png)

快速创建一个restful控制器
----------------

[](#快速创建一个restful控制器)

cd 到项目根目录

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

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

其他说明
----

[](#其他说明)

交流QQ群号：645233951

版权信息
----

[](#版权信息)

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

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2905d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fb9579424c79e777b2f552f016329bd57a36e7101c2df3b25f71c1b54c9a81e5?d=identicon)[yiyiyihao](/maintainers/yiyiyihao)

---

Top Contributors

[![Leslin](https://avatars.githubusercontent.com/u/15942379?v=4)](https://github.com/Leslin "Leslin (81 commits)")[![alexxd35](https://avatars.githubusercontent.com/u/22424013?v=4)](https://github.com/alexxd35 "alexxd35 (1 commits)")[![github410117](https://avatars.githubusercontent.com/u/15375736?v=4)](https://github.com/github410117 "github410117 (1 commits)")[![helloogq](https://avatars.githubusercontent.com/u/21023122?v=4)](https://github.com/helloogq "helloogq (1 commits)")

---

Tags

frameworkormthinkphp

### Embed Badge

![Health badge](/badges/yihao-company-mqtt-test/health.svg)

```
[![Health](https://phpackages.com/badges/yihao-company-mqtt-test/health.svg)](https://phpackages.com/packages/yihao-company-mqtt-test)
```

###  Alternatives

[topthink/think

the new thinkphp framework

8.0k1.2M13](/packages/topthink-think)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
