ocolin/uisp
Composer 安装命令:
composer require ocolin/uisp
包简介
Basic PHP UISP REST client
README 文档
README
This UISP plugin is a lightweight PHP HTTP client specifically for Ubiquiti's UISP server.
It is designed so you don't have to worry about setting up or paying attention to any of the HTTP mechanism. All you need is to provide the endpoint, the method, and the data.
TOC
Requirements
- PHP >= 8.3
- guzzlehttp/guzzle ^7.10
- ocolin/globaltypes ^2.0
Installation
composer require ocolin/uisp
Configuration
Environment Variable Configuration
This plugin was designed to use environment variables for ease of use. You can use .env.example as a template for the variable names:
| Variable | Description | Example |
|---|---|---|
| UISP_API_TOKEN | Authentication token | 24a1a5eg-dfa9-5679-a51f-b9eg43c65862 |
| UISP_API_URL | Server URI | https://myserver.com/nms/api/v2.1/ |
Instantiation Configuration
The Client constructor can also take an array of optional information including the server URI and authentication token. Here are the optional configuration settings that can be used:
| Name | Description | Default |
|---|---|---|
| base_uri | URI to API server | UISP_API_URL env var |
| token | Authentication token for API server | UISP_API_TOKEN env var |
| timeout | HTTP timeout | 20 seconds |
| connect_timeout | Timeout for connection | 20 seconds |
| verify | Verify SSL connection | false |
Usage
Concepts
Here are the arguments you need when making an API call:
- endpoint - Copy/paste the end point from your API docs. Any variables in the endpoint will be replaced with variables of the same name in your parameters.
- method - You specify an HTTP methods. This is either done by choosing the method function name, or specifying the method name depending on which function call is used.
- params - These are the variables that are used in the HTTP body. Not used for GET or DELETE.
- query - Path and query parameters. Any property names that match variable tokens in your path will be removed and inserted into your path name. See GET example below.
Below you can find examples for each scenario.
Output
Most methods will output an object with 4 properties:
| Property | Desdcription | Type |
|---|---|---|
| status | HTTP status numeric code | int |
| statusMessage | HTTP text status | string |
| headers | HTTP response headers | string[] |
| body | API response data | mixed |
The exception to this is the data() function which returns ONLY the HTTP body (See example below).
Instantiation
Using Environment Variables
// Manually creating for demonstration $_ENV['UISP_API_TOKEN'] = 'myauthtoken'; $_ENV['UISP_API_URL'] = 'https://myserver.com/nms/api/v2.1/'; $client = new Ocolin\UISP\Client();
Setting Options parameters
$options = [ 'base_uri' => 'https://myserver.com/nms/api/v2.1/', 'token' => 'myauthtoken', 'timeout' => 60 ]; $client = new Ocolin\UISP\Client( options: $options );
Method Calls
GET
Get data.
// {id} will be replaced with 6c2f7697-8c5c-43df-9873-d8819d76a2d2 $output = $client->get( endpoint: '/devices/{id}', query: [ 'id' => '6c2f7697-8c5c-43df-9873-d8819d76a2d2'] );
POST
Create data.
$output = $client->post( endpoint: '/sites', params: [ 'name' => 'My New Site' ] );
PUT
Update data.
$output = $client->put( endpoint: '/sites/{id}', params: $site_object, // Object of a site from UISP query: [ 'isComposeRequest' => 'true', 'id' => '6c2f7697-8c5c-43df-9873-d8819d76a2d2' ] );
PATCH
Update data.
$output = $client->patch( endpoint: '/sites/{id}', params: $site_object, // Object of a site from UISP query: [ 'isComposeRequest' => 'true', 'id' => '6c2f7697-8c5c-43df-9873-d8819d76a2d2' ] );
DELETE
Delete data.
$output = $client->delete( endpoint: '/devices/{id}', query: [ 'id' => '6c2f7697-8c5c-43df-9873-d8819d76a2d2'] );
REQUEST
Request is a more generic function where you specify the method rather than calling the specific method function.
$output = $client->request( endpoint: '/devices/{id}', query: [ 'id' => '6c2f7697-8c5c-43df-9873-d8819d76a2d2'], method: 'GET' );
DATA
Data is much like the request() function, but it only returns the data. This is for situations where you don't need any of the other data and can assume problems based solely on the response body.
// Output is mixed data type $output = $client->data( endpoint: '/devices/{id}', query: [ 'id' => '6c2f7697-8c5c-43df-9873-d8819d76a2d2'], method: 'GET' );
Fluent Interface
Another means of making API calls is using the Fluent/Chaining interface. Instead of providing an endpoint string, you can build an endpoint with functions.
The last function of your call will be the HTTP method which will take the same arguments as running it directly, only without the endpoint string.
Any endpoint segments using dashes can be specified using camel case.
Example
$output = $client->airlink()->proxy()->airlink-be()->get();
Variable path parameters can be provided using the param() function. Notice the camel case to replicate "mac-table-refresh".
$output = $client->deviced->param(123)->macTableRefresh()->get();
ocolin/uisp 适用场景与选型建议
ocolin/uisp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ocolin/uisp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ocolin/uisp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-30