1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
notifyim.php
См. документацию.
1
<?php
2
namespace
Bitrix\Rest;
3
4
use Bitrix\Main\Loader;
5
use Bitrix\Main\Localization\Loc;
6
use Bitrix\Main\SystemException;
7
use Bitrix\Rest\OAuth\Auth;
8
9
Loc::loadMessages(__FILE__);
10
11
class
NotifyIm
implements
INotify
12
{
13
const
TOKEN_NOTIFY_TAG
=
'REST_CONFIRM'
;
14
const
APP_INSTALL_REQUEST_TAG
=
'APP_INSTALL_REQUEST'
;
15
16
public
function
__construct
()
17
{
18
if
(!Loader::includeModule(
'im'
))
19
{
20
throw
new
SystemException
(
'Module not installed: im'
);
21
}
22
}
23
24
public
function
send
(
$clientId
,
$userId
, $token,
$method
,
$message
)
25
{
26
$messageFields
=
array
(
27
"TO_USER_ID"
=>
$userId
,
28
"FROM_USER_ID"
=>
''
,
29
"NOTIFY_TYPE"
=>
IM_NOTIFY_CONFIRM
,
30
"NOTIFY_MODULE"
=>
"rest"
,
31
"NOTIFY_EVENT"
=>
"admin_notification"
,
32
"NOTIFY_SUB_TAG"
=>
"rest|"
.static::TOKEN_NOTIFY_TAG.
"|"
.
$clientId
.
"|"
.$token.
"|"
.
$method
,
33
"NOTIFY_MESSAGE"
=>
$message
,
34
35
"NOTIFY_BUTTONS"
=> Array(
36
array
(
'TITLE'
=> Loc::getMessage(
"REST_NOTIFY_CONFIRM"
),
'VALUE'
=>
'Y'
,
'TYPE'
=>
'accept'
),
37
array
(
'TITLE'
=> Loc::getMessage(
"REST_NOTIFY_DECLINE"
),
'VALUE'
=>
'N'
,
'TYPE'
=>
'cancel'
),
38
),
39
);
40
41
$messageFields
[
'NOTIFY_TAG'
] =
$messageFields
[
'NOTIFY_SUB_TAG'
].
'|'
.
$userId
;
42
43
\CIMNotify::add(
$messageFields
);
44
}
45
46
public
static
function
receive
($module, $tag, $value, $notifyFields)
47
{
48
if
($module ==
'rest'
)
49
{
50
$tagInfo = explode(
"|"
, $tag);
51
52
if
($tagInfo[1] === static::TOKEN_NOTIFY_TAG)
53
{
54
$clientId
= $tagInfo[2];
55
$token = $tagInfo[3];
56
$method
= $tagInfo[4];
57
58
$tokenInfo =
array
(
59
'access_token'
=> $token,
60
'parameters'
=>
array
(
61
'notify_allow'
=>
array
(
62
$method
=> $value ==
'Y'
? 1 : -1,
63
),
64
),
65
);
66
67
Auth::updateTokenParameters($tokenInfo);
68
69
foreach
(
GetModuleEvents
(
'rest'
,
'OnRestAppMethodConfirm'
,
true
) as
$event
)
70
{
71
ExecuteModuleEventEx
(
$event
,
array
(
array
(
72
'APP_ID'
=>
$clientId
,
73
'TOKEN'
=> $token,
74
'METHOD'
=>
$method
,
75
'CONFIRMED'
=> $value ==
'Y'
,
76
)));
77
}
78
79
\CIMNotify::deleteBySubTag($notifyFields[
"NOTIFY_SUB_TAG"
]);
80
}
81
elseif
($tagInfo[1] === static::APP_INSTALL_REQUEST_TAG)
82
{
83
\CIMNotify::DeleteBySubTag(
"REST|APP_INSTALL_REQUEST"
);
84
85
if
($value ==
"Y"
)
86
{
87
if
(isset($notifyFields[
"NOTIFY_BUTTONS"
][0][
"APP_URL"
]) && \
Bitrix
\
Main
\Loader::includeModule(
"im"
))
88
{
89
$messageFields
=
array
(
90
"TO_USER_ID"
=> $notifyFields[
"RELATION_USER_ID"
],
91
"FROM_USER_ID"
=> $notifyFields[
"AUTHOR_ID"
],
92
"NOTIFY_TYPE"
=>
IM_NOTIFY_FROM
,
93
"NOTIFY_MODULE"
=>
"rest"
,
94
"NOTIFY_EVENT"
=>
"admin_notification"
,
95
"NOTIFY_TAG"
=>
"REST|APP_INSTALL_LINK|"
.$notifyFields[
"AUTHOR_ID"
].
"|TO|"
.$notifyFields[
"RELATION_USER_ID"
],
96
"NOTIFY_SUB_TAG"
=>
"REST|APP_INSTALL_LINK|"
.$notifyFields[
"RELATION_USER_ID"
],
97
"NOTIFY_MESSAGE"
=>
GetMessage
(
"REST_APP_INSTALL_REQUEST"
,
array
(
"#APP_URL#"
=> $notifyFields[
"NOTIFY_BUTTONS"
][0][
"APP_URL"
],
"#APP_NAME#"
=> $notifyFields[
"NOTIFY_BUTTONS"
][0][
"APP_NAME"
]))
98
);
99
\CIMNotify::Add(
$messageFields
);
100
}
101
}
102
}
103
}
104
}
105
}
$messageFields
$messageFields
Определения
callback_ednaru.php:22
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Main\SystemException
Определения
SystemException.php:9
Bitrix\Rest\NotifyIm
Определения
notifyim.php:12
Bitrix\Rest\NotifyIm\__construct
__construct()
Определения
notifyim.php:16
Bitrix\Rest\NotifyIm\APP_INSTALL_REQUEST_TAG
const APP_INSTALL_REQUEST_TAG
Определения
notifyim.php:14
Bitrix\Rest\NotifyIm\receive
static receive($module, $tag, $value, $notifyFields)
Определения
notifyim.php:46
Bitrix\Rest\NotifyIm\send
send($clientId, $userId, $token, $method, $message)
Определения
notifyim.php:24
Bitrix\Rest\NotifyIm\TOKEN_NOTIFY_TAG
const TOKEN_NOTIFY_TAG
Определения
notifyim.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
IM_NOTIFY_CONFIRM
const IM_NOTIFY_CONFIRM
Определения
include.php:36
IM_NOTIFY_FROM
const IM_NOTIFY_FROM
Определения
include.php:37
Bitrix\Rest\INotify
Определения
inotify.php:5
ExecuteModuleEventEx
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения
tools.php:5214
GetModuleEvents
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения
tools.php:5177
GetMessage
GetMessage($name, $aReplace=null)
Определения
tools.php:3397
Bitrix\Main
Bitrix
$message
$message
Определения
payment.php:8
$event
$event
Определения
prolog_after.php:141
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$method
$method
Определения
index.php:27
$clientId
$clientId
Определения
seo_client.php:18
bitrix
modules
rest
lib
notifyim.php
Создано системой
1.14.0