🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 1.2 升级指南 1.2 版本主要修改了 Client 的构造函数参数和 Protocol 的命名空间。 ## Protocol 新增一层`Protocol`,使用`V3`和`V5`来区分 MQTT 协议等级。 同时将`Simps\MQTT\Types`也移动到了`Protocol`下,修改为`Simps\MQTT\Protocol\Types`。 ### 1.1 ```php Simps\MQTT\Protocol::pack(array $array) Simps\MQTT\ProtocolV5::pack(array $array) Simps\MQTT\ProtocolInterface::MQTT_PROTOCOL_LEVEL_3_1; Simps\MQTT\Types::CONNECT; ``` ### 1.2 ```php Simps\MQTT\Protocol\V3::pack(array $array) Simps\MQTT\Protocol\V5::pack(array $array) Simps\MQTT\Protocol\ProtocolInterface::MQTT_PROTOCOL_LEVEL_3_1; Simps\MQTT\Protocol\Types::CONNECT; ``` ## Client Client 之前是直接传递数组参数的,现在改为对象的方式。 ### 1.1 ```php use Simps\MQTT\Client; $config = [ 'host' => '127.0.0.1', 'port' => 1883, 'user_name' => '', 'password' => '', 'client_id' => Client::genClientID(), 'keep_alive' => 10, ]; $swooleConfig = [ 'open_mqtt_protocol' => true, 'package_max_length' => 2 * 1024 * 1024, 'connect_timeout' => 1.0, 'write_timeout' => 3.0, 'read_timeout' => 0.5, ]; $client = new Client($config, $swooleConfig); ``` ### 1.2 ```php use Simps\MQTT\Client; use Simps\MQTT\Config\ClientConfig; $config = new ClientConfig(); $config->setUserName('') ->setPassword('') ->setClientId(Client::genClientID()) ->setKeepAlive(10); $swooleConfig = [ 'open_mqtt_protocol' => true, 'package_max_length' => 2 * 1024 * 1024, 'connect_timeout' => 1.0, 'write_timeout' => 3.0, 'read_timeout' => 0.5, ]; $config->setSwooleConfig($swooleConfig); $client = new Client('127.0.0.1', 1883, $config); // 也可以这样设置 $config = new ClientConfig([ 'userName' => '', 'password' => '', 'clientId' => '', 'keepAlive' => 10, 'protocolName' => 'MQTT', 'protocolLevel' => 4, 'properties' => [], 'delay' => 3000, // 3s 'swooleConfig' => [] ]); $client = new Client('127.0.0.1', 1883, $config); ```