1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
googlemessage.php
См. документацию.
1<?php
2
3namespace Bitrix\Pull\Push\Message;
4
6{
8 public function __construct($sDeviceToken = null)
9 {
10 if (isset($sDeviceToken))
11 {
12 $this->addRecipient($sDeviceToken);
13 }
14 }
15
20 public function getBatch()
21 {
22 $data = $this->getPayload();
23 $batch = "Content-type: application/json\r\n";
24 $batch .= "Content-length: " . strlen($data) . "\r\n";
25 $batch .= "\r\n";
26 $batch .= $data;
27
28 return base64_encode($batch);
29 }
30
31 public function getPayload(): string
32 {
33 $data = [
34 "data" => [
35 'contentTitle' => $this->title,
36 "contentText" => $this->text,
37 "badge" => $this->badge,
38 "messageParams" => $this->customProperties,
39 "category" => $this->getCategory(),
40 "sound" => $this->getSound(),
41 ],
42 "time_to_live" => $this->expiryValue,
43 "priority" => "high",
44 "registration_ids" => $this->deviceTokens
45 ];
46
47 return $this->strippedPayload($data);
48 }
49
50 public function strippedPayload($data): string {
51 $jsonPayload = json_encode($data, JSON_UNESCAPED_UNICODE);
52 $payloadLength = strlen($jsonPayload);
53 if ($payloadLength > self::DEFAULT_PAYLOAD_MAXIMUM_SIZE)
54 {
55
57 $useSenderText = false;
58 if(array_key_exists("senderMessage", $this->customProperties))
59 {
60 $useSenderText = true;
61 $text = $this->customProperties["senderMessage"];
62 }
63 $maxTextLength = $nTextLen = strlen($text) - ($payloadLength - self::DEFAULT_PAYLOAD_MAXIMUM_SIZE);
64 if ($maxTextLength <= 0)
65 {
66 return false;
67 }
68 while (strlen($text = mb_substr($text, 0, --$nTextLen)) > $maxTextLength) ;
69 if($useSenderText)
70 {
71 $this->setCustomProperty("senderMessage", $text);
72 }
73 else
74 {
75 $this->setText($text);
76 }
77
78
79 return $this->getPayload();
80 }
81
82 return $jsonPayload;
83 }
84
85}
addRecipient($sDeviceToken)
Определения basemessage.php:21
setCustomProperty($sName, $mValue)
Определения basemessage.php:83
__construct($sDeviceToken=null)
Определения googlemessage.php:8
$data['IS_AVAILABLE']
Определения .description.php:13
$text
Определения template_pdf.php:79