Replace apns sender with new one #196 Closes #196 See merge request jankstudio/resq!254
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use Mosquitto\Client as MosquittoClient;
|
|
use App\Entity\JobOrder;
|
|
use App\Ramcar\MobileOSType;
|
|
|
|
class APNSClient
|
|
{
|
|
// TODO: make this a config entry
|
|
const REDIS_KEY = 'apns_push';
|
|
|
|
// protected $mclient;
|
|
protected $redis;
|
|
|
|
public function __construct(RedisClientProvider $redis_client)
|
|
{
|
|
$this->redis = $redis_client->getRedisClient();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
public function sendReg($push_id, $message)
|
|
{
|
|
$this->push($push_id, $message);
|
|
}
|
|
}
|