コード例 #1
1
ファイル: mobile.php プロジェクト: rasuldev/torino
 public static function getUserDevices($userId)
 {
     $arResult = array();
     if (CModule::IncludeModule("pull")) {
         $dbres = CPullPush::GetList(array(), array("USER_ID" => $userId));
         while ($arDb = $dbres->Fetch()) {
             if ($arDb["DEVICE_TYPE"] == "APPLE") {
                 CModule::IncludeModule("mobileapp");
                 CMobile::Init();
                 /*					if(CMobile::$isDev)
                 						$protocol = 1;
                 					else */
                 $protocol = 2;
             } else {
                 $protocol = 3;
             }
             $arResult[] = $arDb["DEVICE_TOKEN"] . ":" . $protocol . ":BitrixAdmin";
         }
     }
     return $arResult;
 }
コード例 #2
1
ファイル: logout.php プロジェクト: Satariall/izurit
<?php

if (!Defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
$data = array("logout_status" => "success");
if ($_REQUEST["uuid"]) {
    if (CModule::IncludeModule("pull")) {
        $dbres = CPullPush::GetList(array(), array("=DEVICE_ID" => $_REQUEST["uuid"]));
        while ($arToken = $dbres->Fetch()) {
            CPullPush::Delete($arToken["ID"]);
            $data["token_status"] = "deleted";
        }
    }
}
$USER->Logout();
コード例 #3
1
ファイル: save_device_token.php プロジェクト: rasuldev/torino
<?php

if (!Defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
$data = array("status" => "failed");
$data = $_POST;
if ($USER->IsAuthorized() && $_REQUEST["device_token"]) {
    $token = $_REQUEST["device_token"];
    $uuid = $_REQUEST["uuid"];
    $data = array("register_token" => "fail", "token" => $token, "user_id" => $USER->GetID());
    if (CModule::IncludeModule("pull")) {
        $dbres = CPullPush::GetList(array(), array("DEVICE_ID" => $uuid));
        $arToken = $dbres->Fetch();
        $arFields = array("USER_ID" => $USER->GetID(), "DEVICE_NAME" => $_REQUEST["device_name"], "DEVICE_TYPE" => $_REQUEST["device_type"], "DEVICE_ID" => $_REQUEST["uuid"], "DEVICE_TOKEN" => $token);
        if ($arToken["ID"]) {
            $res = CPullPush::Update($arToken["ID"], $arFields);
            $data["register_token"] = "updated";
        } else {
            $res = CPullPush::Add($arFields);
            if ($res) {
                $data["register_token"] = "created";
            }
        }
    }
}
コード例 #4
0
ファイル: pull_push.php プロジェクト: vim84/b-markt
 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;
 }
コード例 #5
0
 public function SendMessage($arMessages = array(), $sandbox = false)
 {
     if (empty($arMessages)) {
         return false;
     }
     $arUsers = array();
     $arTmpMessages = array();
     foreach ($arMessages as $message) {
         if (!$message["USER_ID"]) {
             continue;
         }
         $arUsers[] = $message["USER_ID"];
         if (!array_key_exists("USER_" . $message["USER_ID"], $arTmpMessages)) {
             $arTmpMessages["USER_" . $message["USER_ID"]] = array();
         }
         $arTmpMessages["USER_" . $message["USER_ID"]][] = $message;
     }
     $arUsers = array_unique($arUsers);
     $dbDevices = CPullPush::GetList(array("DEVICE_TYPE" => "ASC"), array("USER_ID" => $arUsers));
     $arServicesIDs = array_keys(self::$arPushServices);
     $arPushMessages = array();
     while ($arDevice = $dbDevices->Fetch()) {
         if (in_array($arDevice["DEVICE_TYPE"], $arServicesIDs)) {
             $arPushMessages[$arDevice["DEVICE_TYPE"]][$arDevice["DEVICE_TOKEN"]] = $arTmpMessages["USER_" . $arDevice["USER_ID"]];
         }
     }
     if (empty($arPushMessages)) {
         return false;
     }
     $batch = "";
     foreach ($arServicesIDs as $serviceID) {
         if ($arPushMessages[$serviceID]) {
             if (class_exists(self::$arPushServices[$serviceID]["CLASS"])) {
                 $obPush = new self::$arPushServices[$serviceID]["CLASS"]();
             }
             if (method_exists($obPush, "setConnectTimeout")) {
                 $obPush->setConnectTimeout(10);
             }
             if (method_exists($obPush, "GetBatch")) {
                 $batch .= $obPush->GetBatch($arPushMessages[$serviceID]);
             }
         }
     }
     $this->SendBatch($batch);
     return true;
 }