server = Env::get('mqtt.mqtt_server'); // change if necessary $this->port = Env::get('mqtt.mqtt_port'); // change if necessary $this->username = Env::get('mqtt.mqtt_username'); // set your username $this->password = Env::get('mqtt.mqtt_password'); // set your password } public function publishs($topic, $content) { $client_id = 'php-' . uniqid(); $this->mqtt = new phpMQTT($this->server, $this->port, $client_id); if($this->mqtt->connect()) { $this->mqtt->publish($topic, $content, 0); }else{ \Think\Log::write('MQTT连接失败: ' . var_export($this->mqtt->connect(), true), 'INFO'); } } }