// +---------------------------------------------------------------------- declare(strict_types=1); namespace addon\iot\controller\backend; use think\facade\View; use ywxapp\controller\BackendBase; use addon\iot\service\Store; /** * 发布消息控制器 */ class Publish extends BackendBase { /** * 发布表单页 */ public function publish() { return View::fetch('admin/publish'); } /** * 执行发布(零外部依赖:写入出站队列,由常驻 Broker 消费后经内部路由投递) */ public function doPublish() { $topic = input('post.topic', ''); $payload = input('post.payload', ''); $qos = (int) input('post.qos', 0); if (!$topic) { $this->result->error('主题不能为空'); } $ok = Store::enqueueManual($topic, $payload, $qos, 0, 'backend'); if ($ok) { $this->result->success('已加入发布队列,Broker 将投递给在线订阅者'); } $this->result->error('发布失败:无法写入出站队列'); } }