Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
client.php
1
<?php
2
namespace
Bitrix\Sale\Exchange\Integration\OAuth
;
3
4
5
use
Bitrix\Main\Web\HttpClient
;
6
use
Bitrix\Main\Web\Json
;
7
8
class
Client
9
{
10
private
$httpClient;
11
protected
$accessTokenUrl
;
12
protected
$clientId
;
13
protected
$clientSecret
;
14
15
public
function
__construct
(array $options = [])
16
{
17
foreach
($options as $option => $value)
18
{
19
if
(property_exists(self::class, $option))
20
{
21
$this->{$option} = $value;
22
}
23
}
24
25
$this->httpClient =
new
HttpClient
();
26
$this->httpClient->setHeader(
"User-Agent"
,
"Bitrix IntegrationB24"
);
27
$this->httpClient->setCharset(
"UTF-8"
);
28
}
29
30
public
function
getAccessTokenUrl
(array $params)
31
{
32
$url = $this->
getBaseAccessTokenUrl
();
33
if
($this->
getAccessTokenMethod
() === HttpClient::HTTP_GET)
34
{
35
$query = http_build_query($params,
null
,
"&"
);
36
return
$url.
"?"
.$query;
37
}
38
39
return
$url;
40
}
41
48
public
function
getAccessToken
($grant, array $options = [])
49
{
50
$params = [
51
"grant_type"
=> $grant,
52
"client_id"
=> $this->
getClientId
(),
53
"client_secret"
=> $this->
getClientSecret
(),
54
];
55
56
$params = array_merge($params, $options);
57
$success = $this->httpClient->query($this->
getAccessTokenMethod
(), $this->
getAccessTokenUrl
($params));
58
59
$response = [];
60
if
($success)
61
{
62
try
63
{
64
$response = Json::decode($this->httpClient->getResult());
65
}
66
catch
(\
Bitrix
\Main\
ArgumentException
$exception)
67
{
68
69
}
70
}
71
72
return
$response;
73
}
74
75
protected
function
getAccessTokenMethod
()
76
{
77
return
HttpClient::HTTP_GET;
78
}
79
80
protected
function
getBaseAccessTokenUrl
()
81
{
82
return
$this->accessTokenUrl
;
83
}
84
85
protected
function
getClientId
()
86
{
87
return
$this->clientId
;
88
}
89
90
protected
function
getClientSecret
()
91
{
92
return
$this->clientSecret
;
93
}
94
}
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\Web\HttpClient
Definition
httpclient.php:24
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Sale\Exchange\Integration\OAuth\Client
Definition
client.php:9
Bitrix\Sale\Exchange\Integration\OAuth\Client\$accessTokenUrl
$accessTokenUrl
Definition
client.php:11
Bitrix\Sale\Exchange\Integration\OAuth\Client\getClientSecret
getClientSecret()
Definition
client.php:90
Bitrix\Sale\Exchange\Integration\OAuth\Client\$clientSecret
$clientSecret
Definition
client.php:13
Bitrix\Sale\Exchange\Integration\OAuth\Client\__construct
__construct(array $options=[])
Definition
client.php:15
Bitrix\Sale\Exchange\Integration\OAuth\Client\getBaseAccessTokenUrl
getBaseAccessTokenUrl()
Definition
client.php:80
Bitrix\Sale\Exchange\Integration\OAuth\Client\getAccessToken
getAccessToken($grant, array $options=[])
Definition
client.php:48
Bitrix\Sale\Exchange\Integration\OAuth\Client\getAccessTokenMethod
getAccessTokenMethod()
Definition
client.php:75
Bitrix\Sale\Exchange\Integration\OAuth\Client\$clientId
$clientId
Definition
client.php:12
Bitrix\Sale\Exchange\Integration\OAuth\Client\getAccessTokenUrl
getAccessTokenUrl(array $params)
Definition
client.php:30
Bitrix\Sale\Exchange\Integration\OAuth\Client\getClientId
getClientId()
Definition
client.php:85
Bitrix\Sale\Exchange\Integration\OAuth
Definition
bitrix24.php:4
Bitrix
modules
sale
lib
exchange
integration
oauth
client.php
Создано системой
1.10.0