chore: 重写初始提交(清空历史,整理后全量提交)

This commit is contained in:
ywxapp
2026-08-16 16:54:14 +08:00
commit 6c1a106bc1
1808 changed files with 238144 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\mqttbroker\controller\api;
use think\facade\Db;
use ywxapp\controller\ApiController;
use addon\mqttbroker\model\Message;
/**
* Mqtt 类
*
* @author ywxapp <admin@ywxapp.cn>
*/
class Mqtt extends ApiController
{
protected $noNeedLogin = ['*'];
protected $noNeedVerify = ['*'];
/**
* 获取 Broker 运行状态
* GET /mqttbroker/api/status
*/
public function status()
{
$data = [
'online' => Db::name('mqttbroker_connection')->where('status', 1)->count(),
'total' => Db::name('mqttbroker_connection')->count(),
'messages' => Message::count(),
'topics' => Db::name('mqttbroker_topic')->count(),
];
$this->result->success($data);
}
/**
* 发布消息
* POST /mqttbroker/api/publish {topic, payload, qos}
*
* 零外部依赖:写入出站队列(DB),由常驻 Broker 进程消费后经内部路由投递,
* 不再依赖 workerman/mqtt 客户端连接本地 Broker。
*/
public function publish()
{
$topic = input('topic', '');
$payload = input('payload', '');
$qos = (int) input('qos', 0);
if (!$topic) {
$this->result->error('topic required');
}
$ok = \addon\mqttbroker\service\Store::enqueueManual($topic, $payload, $qos, 0, 'api');
if ($ok) {
$this->result->success('已加入发布队列,Broker 将投递给在线订阅者');
} else {
$this->result->error('发布失败:无法写入出站队列(请检查数据库)');
}
}
}