1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
yandexcert.php
См. документацию.
1
<?php
2
namespace
Bitrix\Sale\PaySystem;
3
4
use Bitrix\Main\Config\Option;
5
use Bitrix\Main\Localization\Loc;
6
use Bitrix\Sale\Internals\PersonTypeTable;
7
use Bitrix\Sale\Internals\YandexSettingsTable;
8
9
Loc::loadMessages(__FILE__);
10
11
class
YandexCert
12
{
13
static
public
$pkey
=
null
;
14
static
public
$csr
=
null
;
15
static
public
$sign
=
null
;
16
static
public
$cn
=
''
;
17
static
public
$errors
=
array
();
18
23
static
public
function
generate
(
$shopId
,
$companyName
)
24
{
25
$yandexCsr = self::loadFromOptions(
$shopId
);
26
if
($yandexCsr ===
''
)
27
{
28
self::$cn =
"/business/"
.$companyName;
29
30
$config
=
array
(
31
"digest_alg"
=>
"sha1"
,
32
"private_key_bits"
=> 2048,
33
"private_key_type"
=> OPENSSL_KEYTYPE_RSA,
34
);
35
36
$dnFull =
array
(
37
"countryName"
=>
"RU"
,
38
"stateOrProvinceName"
=>
"Russia"
,
39
"localityName"
=>
"Moscow"
,
40
"commonName"
=> self::$cn,
41
);
42
43
$res
= openssl_pkey_new(
$config
);
44
$csr_origin = openssl_csr_new($dnFull,
$res
);
45
if
($csr_origin ===
false
)
46
return
;
47
$csr_full =
""
;
48
openssl_pkey_export(
$res
, self::$pkey);
49
openssl_csr_export($csr_origin, self::$csr);
50
51
openssl_csr_export($csr_origin, $csr_full,
false
);
52
preg_match(
'"Signature Algorithm\: (.*)-----BEGIN"ims'
, $csr_full,
$sign
);
53
$sign
= str_replace(
"\t"
,
""
,
$sign
);
54
if
(
$sign
)
55
{
56
$sign
=
$sign
[1];
57
$a
= explode(
"\n"
,
$sign
);
58
unset(
$a
[0]);
59
$sign
= str_replace(
" "
,
""
, trim(join(
"\n"
,
$a
)));
60
}
61
self::$sign =
$sign
;
62
63
$dbRes
= YandexSettingsTable::getById(
$shopId
);
64
if
(
$dbRes
->fetch())
65
YandexSettingsTable::update(
$shopId
,
array
(
'SIGN'
=> self::$sign,
'CSR'
=> self::$csr,
'PKEY'
=> self::$pkey,
'CERT'
=>
''
));
66
else
67
YandexSettingsTable::add(
array
(
'SHOP_ID'
=>
$shopId
,
'SIGN'
=> self::$sign,
'CSR'
=> self::$csr,
'PKEY'
=> self::$pkey));
68
}
69
}
70
76
static
public
function
clear
(
$shopId
, $all =
false
)
77
{
78
if
($all)
79
$settings
=
array
(
'CERT'
=>
''
,
'SIGN'
=>
''
,
'CSR'
=>
''
,
'PKEY'
=>
''
);
80
else
81
$settings
=
array
(
'CERT'
=>
''
);
82
83
YandexSettingsTable::update(
$shopId
,
$settings
);
84
}
85
90
static
public
function
getCn
(
$shopId
)
91
{
92
$yandexCsr =
self::getValue
(
'CSR'
,
$shopId
);
93
94
$subjects = openssl_csr_get_subject($yandexCsr);
95
if
(!isset($subjects[
'CN'
]) || empty($subjects[
'CN'
]))
96
return
''
;
97
98
return
$subjects[
'CN'
];
99
}
100
105
static
private
function
loadFromOptions(
$shopId
)
106
{
107
$dbRes
= PersonTypeTable::getList(
array
(
'select'
=>
array
(
'ID'
,
'PT_SITE_ID'
=>
'PERSON_TYPE_SITE.SITE_ID'
)));
108
while
(
$data
=
$dbRes
->fetch())
109
{
110
$csr
= Option::get(
'yandexmoney.ycms'
,
'KASSA_MWS_CSR'
,
''
,
$data
[
'PT_SITE_ID'
]);
111
if
(
$csr
===
''
)
112
continue
;
113
114
$csr
= Option::get(
'yandexmoney.ycms'
,
'KASSA_MWS_CSR'
,
''
,
$data
[
'PT_SITE_ID'
]);
115
$pkey
= Option::get(
'yandexmoney.ycms'
,
'KASSA_MWS_PKEY'
,
''
,
$data
[
'PT_SITE_ID'
]);
116
$sign
= Option::get(
'yandexmoney.ycms'
,
'KASSA_MWS_SIGN'
,
''
,
$data
[
'PT_SITE_ID'
]);
117
$cert = Option::get(
'yandexmoney.ycms'
,
'KASSA_MWS_CERT'
,
''
,
$data
[
'PT_SITE_ID'
]);
118
119
$dbRes
= YandexSettingsTable::getById(
$shopId
);
120
if
(!
$dbRes
->fetch())
121
{
122
YandexSettingsTable::add(
array
(
'SHOP_ID'
=>
$shopId
,
'CSR'
=>
$csr
,
'PKEY'
=>
$pkey
,
'SIGN'
=>
$sign
,
'CERT'
=> $cert));
123
return
$csr
;
124
}
125
}
126
127
return
''
;
128
}
129
135
static
public
function
isLoaded
(
$shopId
)
136
{
137
$cert =
self::getValue
(
'CERT'
,
$shopId
);
138
return
!empty($cert);
139
}
140
145
static
public
function
setCert
($file,
$shopId
)
146
{
147
if
(!empty($file[
'name'
]))
148
{
149
if
(mb_substr($file[
'name'
], -4) !=
'.cer'
)
150
self::$errors[] = Loc::getMessage(
'YANDEX_CERT_ERR_EXT'
);
151
elseif
($file[
'error'
] != UPLOAD_ERR_OK)
152
self::$errors[] = Loc::getMessage(
'YANDEX_CERT_ERR_LOAD'
);
153
elseif
(filesize($file[
'tmp_name'
]) > 2048)
154
self::$errors[] = Loc::getMessage(
'YANDEX_CERT_ERR_SIZE'
);
155
}
156
else
157
{
158
self::$errors[] = Loc::getMessage(
'YANDEX_CERT_ERR_LOAD'
);
159
}
160
161
if
(empty(self::$errors))
162
{
163
$cert = file_get_contents($file[
'tmp_name'
]);
164
$cert_info = openssl_x509_parse($cert);
165
if
(isset($cert_info[
'subject'
][
'CN'
]))
166
{
167
if
($cert_info[
'subject'
][
'CN'
] != self::getCn(
$shopId
))
168
{
169
self::$errors[] = Loc::getMessage(
'YANDEX_CERT_ERR_CN'
);
170
}
171
else
172
{
173
$pkey
= static::getValue(
'PKEY'
,
$shopId
);
174
if
(openssl_x509_check_private_key($cert,
$pkey
))
175
{
176
YandexSettingsTable::update(
$shopId
,
array
(
'CERT'
=> $cert));
177
}
178
else
179
{
180
self::$errors[] = Loc::getMessage(
'YANDEX_CERT_ERR_ACCORDING_PKEY_TO_CERT'
);
181
}
182
}
183
}
184
else
185
{
186
self::$errors[] = Loc::getMessage(
'YANDEX_CERT_ERR_NULL'
);
187
}
188
}
189
}
190
195
static
public
function
getSign
(
$shopId
)
196
{
197
return
self::getValue
(
'SIGN'
,
$shopId
);
198
}
199
204
static
public
function
getCert
(
$shopId
)
205
{
206
return
self::getValue
(
'CERT'
,
$shopId
);
207
}
208
213
static
public
function
getCsr
(
$shopId
)
214
{
215
global
$APPLICATION
;
216
$APPLICATION
->RestartBuffer();
217
218
header(
'Content-Description: File Transfer'
);
219
header(
'Content-Type: application/octet-stream'
);
220
header(
'Content-Disposition: attachment; filename=csr_for_yamoney.csr'
);
221
header(
'Content-Transfer-Encoding: binary'
);
222
header(
'Expires: 0'
);
223
header(
'Cache-Control: must-revalidate, post-check=0, pre-check=0'
);
224
header(
'Pragma: public'
);
225
echo
self::getValue
(
'CSR'
,
$shopId
);
226
die
();
227
}
228
234
static
public
function
getValue
($field,
$shopId
)
235
{
236
$dbRes
= YandexSettingsTable::getList(
array
(
'filter'
=>
array
(
'SHOP_ID'
=>
$shopId
)));
237
if
(
$data
=
$dbRes
->fetch())
238
return
$data
[$field];
239
240
return
''
;
241
}
242
}
$APPLICATION
global $APPLICATION
Определения
include.php:80
Bitrix\Sale\PaySystem\YandexCert
Определения
yandexcert.php:12
Bitrix\Sale\PaySystem\YandexCert\getCsr
static getCsr($shopId)
Определения
yandexcert.php:213
Bitrix\Sale\PaySystem\YandexCert\$cn
static $cn
Определения
yandexcert.php:16
Bitrix\Sale\PaySystem\YandexCert\getCert
static getCert($shopId)
Определения
yandexcert.php:204
Bitrix\Sale\PaySystem\YandexCert\getCn
static getCn($shopId)
Определения
yandexcert.php:90
Bitrix\Sale\PaySystem\YandexCert\setCert
static setCert($file, $shopId)
Определения
yandexcert.php:145
Bitrix\Sale\PaySystem\YandexCert\generate
static generate($shopId, $companyName)
Определения
yandexcert.php:23
Bitrix\Sale\PaySystem\YandexCert\clear
static clear($shopId, $all=false)
Определения
yandexcert.php:76
Bitrix\Sale\PaySystem\YandexCert\getValue
static getValue($field, $shopId)
Определения
yandexcert.php:234
Bitrix\Sale\PaySystem\YandexCert\$pkey
static $pkey
Определения
yandexcert.php:13
Bitrix\Sale\PaySystem\YandexCert\$csr
static $csr
Определения
yandexcert.php:14
Bitrix\Sale\PaySystem\YandexCert\$errors
static $errors
Определения
yandexcert.php:17
Bitrix\Sale\PaySystem\YandexCert\$sign
static $sign
Определения
yandexcert.php:15
Bitrix\Sale\PaySystem\YandexCert\getSign
static getSign($shopId)
Определения
yandexcert.php:195
Bitrix\Sale\PaySystem\YandexCert\isLoaded
static isLoaded($shopId)
Определения
yandexcert.php:135
$data
$data['IS_AVAILABLE']
Определения
.description.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
$res
$res
Определения
filter_act.php:7
$sign
$sign
Определения
payment.php:69
$settings
$settings
Определения
product_settings.php:43
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$config
$config
Определения
quickway.php:69
die
die
Определения
quickway.php:367
$companyName
$companyName
Определения
refund.php:15
$shopId
$shopId
Определения
refund.php:14
$a
else $a
Определения
template.php:137
$dbRes
$dbRes
Определения
yandex_detail.php:168
bitrix
modules
sale
lib
paysystem
yandexcert.php
Создано системой
1.14.0