From 8133c86dc5ce0a60e9f61fe219c38fc16ca91494 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 14 Aug 2020 14:48:14 +0800 Subject: [PATCH] debug mqttclient --- app/Service/MqttServiceInterface.php | 9 --------- app/Service/MqttSpeakerService.php | 19 ++++++++----------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/app/Service/MqttServiceInterface.php b/app/Service/MqttServiceInterface.php index 127b3cc..3148be2 100644 --- a/app/Service/MqttServiceInterface.php +++ b/app/Service/MqttServiceInterface.php @@ -10,15 +10,6 @@ interface MqttServiceInterface */ public function speakToStore($orderId, $isMain = true); - /** - * MQTT发布消息 - * @param $message - * @param $topic - * @param $toClientId - * @return mixed - */ - public function pubToMqtt($message, $topic, $toClientId); - /** * @param string|number $message 消息内容 * @param string $topic 发布消息到主题,主题名 diff --git a/app/Service/MqttSpeakerService.php b/app/Service/MqttSpeakerService.php index 4eaf580..080e0c1 100644 --- a/app/Service/MqttSpeakerService.php +++ b/app/Service/MqttSpeakerService.php @@ -17,7 +17,7 @@ class MqttSpeakerService implements MqttServiceInterface */ public function speakToStore($orderId, $isMain = true) { - + var_dump('speaker-orderid', $orderId); // 获取订单 $orders = Order::query()->select(['id','order_num','money', 'pay_type', 'store_id', 'type']); if ($isMain) { @@ -26,26 +26,22 @@ class MqttSpeakerService implements MqttServiceInterface $orders = $orders->where(['id' => $orderId])->get()->toArray(); } + var_dump('speaker-orders', $orders); + if(empty($orders)) return; // 循环发送 foreach ($orders as $k => &$order) { - $order['template'] = "懒族生活支付到账".floatval($order['money'])."元"; + $order['template'] = "懒族支付到账".floatval($order['money'])."元"; // 获取终端ID $order['to_client_id'] = Store::query()->where(['id' => $order['store_id']])->value('loudspeaker_imei'); + var_dump('speaker-$order', $order); // 发布订阅消息 - $this->pubToMqtt($order['template'], self::TOPIC, $order['to_client_id']); + $res = $this->publish($order['template'], self::TOPIC, $order['to_client_id']); + var_dump('speaker-$res', $res); } } - /** - * @inheritDoc - */ - public function pubToMqtt($message, $topic, $toClientId) - { - $this->publish($message, $topic, $toClientId); - } - /** * @inheritDoc */ @@ -60,6 +56,7 @@ class MqttSpeakerService implements MqttServiceInterface $client = new MQTTClient(env('MQTT_HOST'), env('MQTT_PORT')); $client->setAuthentication(env('MQTT_NAME'), env('MQTT_PASS')); + $client->setDebug(true); if (env('MQTT_CERT')) { $client->setEncryption(env('MQTT_CERT'));