Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
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_SUB_TAG"
=>
"rest|"
.static::TOKEN_NOTIFY_TAG.
"|"
.$clientId.
"|"
.$token.
"|"
.$method,
32
"NOTIFY_MESSAGE"
=> $message,
33
34
"NOTIFY_BUTTONS"
=> Array(
35
array(
'TITLE'
=>
Loc::getMessage
(
"REST_NOTIFY_CONFIRM"
),
'VALUE'
=>
'Y'
,
'TYPE'
=>
'accept'
),
36
array(
'TITLE'
=>
Loc::getMessage
(
"REST_NOTIFY_DECLINE"
),
'VALUE'
=>
'N'
,
'TYPE'
=>
'cancel'
),
37
),
38
);
39
40
$messageFields[
'NOTIFY_TAG'
] = $messageFields[
'NOTIFY_SUB_TAG'
].
'|'
.$userId;
41
42
\CIMNotify::add($messageFields);
43
}
44
45
public
static
function
receive
($module, $tag, $value, $notifyFields)
46
{
47
if
($module ==
'rest'
)
48
{
49
$tagInfo = explode(
"|"
, $tag);
50
51
if
($tagInfo[1] === static::TOKEN_NOTIFY_TAG)
52
{
53
$clientId = $tagInfo[2];
54
$token = $tagInfo[3];
55
$method = $tagInfo[4];
56
57
$tokenInfo = array(
58
'access_token'
=> $token,
59
'parameters'
=> array(
60
'notify_allow'
=> array(
61
$method => $value ==
'Y'
? 1 : -1,
62
),
63
),
64
);
65
66
Auth::updateTokenParameters($tokenInfo);
67
68
foreach
(GetModuleEvents(
'rest'
,
'OnRestAppMethodConfirm'
,
true
) as $event)
69
{
70
ExecuteModuleEventEx($event, array(array(
71
'APP_ID'
=> $clientId,
72
'TOKEN'
=> $token,
73
'METHOD'
=> $method,
74
'CONFIRMED'
=> $value ==
'Y'
,
75
)));
76
}
77
78
\CIMNotify::deleteBySubTag($notifyFields[
"NOTIFY_SUB_TAG"
]);
79
}
80
elseif($tagInfo[1] === static::APP_INSTALL_REQUEST_TAG)
81
{
82
\CIMNotify::DeleteBySubTag(
"REST|APP_INSTALL_REQUEST"
);
83
84
if
($value ==
"Y"
)
85
{
86
if
(isset($notifyFields[
"NOTIFY_BUTTONS"
][0][
"APP_URL"
]) && \
Bitrix
\Main\Loader::includeModule(
"im"
))
87
{
88
$messageFields = array(
89
"TO_USER_ID"
=> $notifyFields[
"RELATION_USER_ID"
],
90
"FROM_USER_ID"
=> $notifyFields[
"AUTHOR_ID"
],
91
"NOTIFY_TYPE"
=> IM_NOTIFY_FROM,
92
"NOTIFY_MODULE"
=>
"rest"
,
93
"NOTIFY_TAG"
=>
"REST|APP_INSTALL_LINK|"
.$notifyFields[
"AUTHOR_ID"
].
"|TO|"
.$notifyFields[
"RELATION_USER_ID"
],
94
"NOTIFY_SUB_TAG"
=>
"REST|APP_INSTALL_LINK|"
.$notifyFields[
"RELATION_USER_ID"
],
95
"NOTIFY_MESSAGE"
=> GetMessage(
"REST_APP_INSTALL_REQUEST"
, array(
"#APP_URL#"
=> $notifyFields[
"NOTIFY_BUTTONS"
][0][
"APP_URL"
],
"#APP_NAME#"
=> $notifyFields[
"NOTIFY_BUTTONS"
][0][
"APP_NAME"
]))
96
);
97
\CIMNotify::Add($messageFields);
98
}
99
}
100
}
101
}
102
}
103
}
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Rest\APAuth\Auth
Definition
auth.php:21
Bitrix\Rest\NotifyIm
Definition
notifyim.php:12
Bitrix\Rest\NotifyIm\__construct
__construct()
Definition
notifyim.php:16
Bitrix\Rest\NotifyIm\APP_INSTALL_REQUEST_TAG
const APP_INSTALL_REQUEST_TAG
Definition
notifyim.php:14
Bitrix\Rest\NotifyIm\receive
static receive($module, $tag, $value, $notifyFields)
Definition
notifyim.php:45
Bitrix\Rest\NotifyIm\send
send($clientId, $userId, $token, $method, $message)
Definition
notifyim.php:24
Bitrix\Rest\NotifyIm\TOKEN_NOTIFY_TAG
const TOKEN_NOTIFY_TAG
Definition
notifyim.php:13
Bitrix\Rest\INotify
Definition
inotify.php:5
Bitrix\Rest
Definition
accessexception.php:2
Bitrix
modules
rest
lib
notifyim.php
Создано системой
1.10.0