56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use Mosquitto\Client as MosquittoClient;
|
|
use App\Entity\JobOrder;
|
|
use App\Ramcar\MobileOSType;
|
|
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)
|
|
{
|
|
// check if mobile session is using an ios device
|
|
if ($sess->getOSType() != MobileOSType::IOS)
|
|
continue;
|
|
|
|
$push_id = $sess->getDevicePushID();
|
|
if ($push_id != null && strlen(trim($push_id)) > 0)
|
|
$this->push($push_id, $message);
|
|
}
|
|
}
|
|
}
|