public function SendMessage($arMessages = array()) { if (empty($arMessages)) { return false; } $uniqueHashes = array(); $arTmpMessages = array(); foreach ($arMessages as $message) { if (!$message["USER_ID"]) { continue; } $uniqueHashes[] = CPullPush::getUniqueHash($message["USER_ID"], $message["APP_ID"]); $uniqueHashes[] = CPullPush::getUniqueHash($message["USER_ID"], $message["APP_ID"] . "_bxdev"); if (!array_key_exists("USER_" . $message["USER_ID"], $arTmpMessages)) { $arTmpMessages["USER_" . $message["USER_ID"]] = array(); } $arTmpMessages["USER_" . $message["USER_ID"]][] = htmlspecialcharsback($message); } $filter = array("UNIQUE_HASH" => array_unique($uniqueHashes)); $dbDevices = CPullPush::GetList(array("DEVICE_TYPE" => "ASC"), $filter); $arServicesIDs = array_keys(self::$pushServices); $arPushMessages = array(); while ($arDevice = $dbDevices->Fetch()) { if (in_array($arDevice["DEVICE_TYPE"], $arServicesIDs)) { $tmpMessage = $arTmpMessages["USER_" . $arDevice["USER_ID"]]; $mode = "PRODUCTION"; if (strpos($arDevice["APP_ID"], "_bxdev") > 0) { $mode = "SANDBOX"; } $arPushMessages[$arDevice["DEVICE_TYPE"]][$arDevice["DEVICE_TOKEN"]] = array("messages" => $tmpMessage, "mode" => $mode); } } if (empty($arPushMessages)) { return false; } $batch = ""; /** * @var CPushService $obPush */ foreach ($arServicesIDs as $serviceID) { if ($arPushMessages[$serviceID]) { if (class_exists(self::$pushServices[$serviceID]["CLASS"])) { $obPush = new self::$pushServices[$serviceID]["CLASS"](); if (method_exists($obPush, "getBatch")) { $batch .= $obPush->getBatch($arPushMessages[$serviceID]); } } } } $this->sendBatch($batch); return true; }