国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

有webman結(jié)合workerman/mqtt的插件嗎

wekyun

有webman結(jié)合workerman/mqtt的插件嗎

705 1 0
1個回答

不敗少龍

我是這樣寫的

<?php

namespace process;

use support\Redis;
use Workerman\Mqtt\Client;

class Mqtt
{
    public function onWorkerStart()
    {
        //訂閱主題
        $mqtt = new Client('mqtt://127.0.0.1:1883');
        $mqtt->onConnect = function($mqtt){
            $topic_array=json_decode(Redis::get('topic'),true);
            if ($topic_array){
                $mqtt->subscribe($topic_array);
            }
        };
        $mqtt->onMessage = function($topic, $content){
            if (is_string($content)){
                if (json_decode($content)){
                    $content=json_decode($content,true);
                }
            }
            //消費主題類
            $classname = "app\\service\\mqtt\\MqttConsumption";
            if (str_contains($topic, "/")){
                //包含斜杠是設(shè)備主題
                call_user_func_array([$classname,'Device'],[$topic,$content]);
            }else{
                call_user_func_array([$classname,$topic],[$content]);
            }
        };
        $mqtt->connect();
    }
}
  • 暫無評論
年代過于久遠(yuǎn),無法發(fā)表回答
??