resq/src/Service/APNSClient.php

51 lines
1.1 KiB
PHP

<?php
namespace App\Service;
use Mosquitto\Client as MosquittoClient;
use App\Entity\JobOrder;
use Redis;
class APNSClient
{
const REDIS_KEY = 'apns_push';
// protected $mclient;
protected $redis;
public function __construct($ip_address, $port)
{
$this->redis = new Redis();
$this->redis->connect($ip_address, $port);
}
public function __destruct()
{
// $this->mclient->disconnect();
}
public function push($token, $message)
{
// $this->mclient->publish($channel, $message);
$data = $token . '|' . $message;
$this->redis->lpush(self::REDIS_KEY, $data);
}
public function sendPush($jo, $message)
{
$sessions = $jo->getCustomer()->getMobileSessions();
if (count($sessions) == 0)
{
error_log("no sessions to send mqtt event to");
return;
}
foreach ($sessions as $sess)
{
$push_id = $sess->getDevicePushID();
if ($push_id != null && strlen(trim($push_id)) > 0)
$this->push($push_id, $message);
}
}
}