guolei19850528 / laravel-device
这是一个基于 Laravel 框架的设备服务扩展,用于集成天津博瑞皓科 (Tjbrhk)设备服务。
v1.0.0
2026-01-05 02:10 UTC
Requires
- php: 8.*
- illuminate/support: 7.*||8.*||9.*||10.*||11.*||12.*
This package is not auto-updated.
Last update: 2026-01-06 00:21:49 UTC
README
这是一个基于 Laravel 框架的设备服务扩展,用于集成天津博瑞皓科 (Tjbrhk)设备服务。
功能特性
- 支持天津博瑞皓科 (Tjbrhk)设备服务API
- 支持多设备配置
- 提供简洁的设备消息发送接口
- 支持自定义响应处理
- 内置请求验证机制
安装
使用 Composer 安装扩展:
composer require guolei19850528/laravel-device
配置
发布配置文件
php artisan vendor:publish --provider="Guolei19850528\Laravel\Device\ServiceProvider"
修改配置文件
在 config/guolei19850528-laravel-device-config.php 文件中配置天津博瑞皓科 设备服务参数:
<?php
return [
'tjbrhk' => [
'your device' => [
'id' => 'your device id', // 设备ID
'token' => 'your device token', // 认证令牌
'version' => '1', // API版本号
'baseUrl' => 'https://speaker.17laimai.cn/', // API基础URL
]
]
];
使用方法
发送设备消息
<?php
use Guolei19850528\Laravel\Device\Tjbrhk\Api;
// 初始化设备API客户端
$deviceApi = new Api(
$deviceId,
$deviceToken,
$version,
$baseUrl
);
// 发送设备消息
$result = $deviceApi->send(
'Hello, this is a test message from Laravel Device extension.'
);
// 自定义响应处理
$result = $deviceApi->send(
'Hello, this is a test message.',
null,
[],
[],
function ($response) {
// 自定义响应处理逻辑
return $response->json()['errcode'] === 0;
}
);
API 文档
类:Guolei19850528\Laravel\Device\Tjbrhk\Api
构造函数
public function __construct(
string|int $id = '',
string $token = '',
string|int $version = '1',
string $baseUrl = 'https://speaker.17laimai.cn/'
)
参数说明:
$id: 天津博瑞皓科 设备ID$token: 设备认证令牌$version: API版本号,默认值为 '1'$baseUrl: API基础URL,默认值为 'https://speaker.17laimai.cn/'
发送消息方法
public function send(
string $message = '',
string $url = '/notify.php',
array|null $urlParameters = [],
array|null $options = [],
\Closure|null $responseHandler = null,
array|null $validatorRules = ['errcode' => 'required|integer|size:0']
): bool
参数说明:
$message: 要发送的消息内容,默认值为空字符串$url: API请求路径,默认值为 '/notify.php'$urlParameters: URL参数数组$options: HTTP请求选项$responseHandler: 响应处理回调函数$validatorRules: 响应验证规则,默认验证errcode字段为0
返回值:
- 发送成功返回
true,失败返回false
许可证
MIT License
作者
- 郭磊
- 邮箱: 174000902@qq.com
- GitHub: https://gitee.com/guolei19850528/laravel-device