|
|
@ -17,7 +17,7 @@ class MqttSpeakerService implements MqttServiceInterface |
|
|
*/ |
|
|
*/ |
|
|
public function speakToStore($orderId, $isMain = true) |
|
|
public function speakToStore($orderId, $isMain = true) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
var_dump('speaker-orderid', $orderId); |
|
|
// 获取订单
|
|
|
// 获取订单
|
|
|
$orders = Order::query()->select(['id','order_num','money', 'pay_type', 'store_id', 'type']); |
|
|
$orders = Order::query()->select(['id','order_num','money', 'pay_type', 'store_id', 'type']); |
|
|
if ($isMain) { |
|
|
if ($isMain) { |
|
|
@ -26,26 +26,22 @@ class MqttSpeakerService implements MqttServiceInterface |
|
|
$orders = $orders->where(['id' => $orderId])->get()->toArray(); |
|
|
$orders = $orders->where(['id' => $orderId])->get()->toArray(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var_dump('speaker-orders', $orders); |
|
|
|
|
|
|
|
|
if(empty($orders)) return; |
|
|
if(empty($orders)) return; |
|
|
|
|
|
|
|
|
// 循环发送
|
|
|
// 循环发送
|
|
|
foreach ($orders as $k => &$order) { |
|
|
foreach ($orders as $k => &$order) { |
|
|
$order['template'] = "懒族生活支付到账".floatval($order['money'])."元"; |
|
|
|
|
|
|
|
|
$order['template'] = "懒族支付到账".floatval($order['money'])."元"; |
|
|
// 获取终端ID
|
|
|
// 获取终端ID
|
|
|
$order['to_client_id'] = Store::query()->where(['id' => $order['store_id']])->value('loudspeaker_imei'); |
|
|
$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 |
|
|
* @inheritDoc |
|
|
*/ |
|
|
*/ |
|
|
@ -60,6 +56,7 @@ class MqttSpeakerService implements MqttServiceInterface |
|
|
|
|
|
|
|
|
$client = new MQTTClient(env('MQTT_HOST'), env('MQTT_PORT')); |
|
|
$client = new MQTTClient(env('MQTT_HOST'), env('MQTT_PORT')); |
|
|
$client->setAuthentication(env('MQTT_NAME'), env('MQTT_PASS')); |
|
|
$client->setAuthentication(env('MQTT_NAME'), env('MQTT_PASS')); |
|
|
|
|
|
$client->setDebug(true); |
|
|
|
|
|
|
|
|
if (env('MQTT_CERT')) { |
|
|
if (env('MQTT_CERT')) { |
|
|
$client->setEncryption(env('MQTT_CERT')); |
|
|
$client->setEncryption(env('MQTT_CERT')); |
|
|
|