@Tyusha

Как оформить данный CURL запрос на PHP?

Помогите, пожалуйста, оформить запрос по данному образцу:
curl --location --request POST 'https://mc.api.sberbank.ru:443/prod/tokens/v3/oauth' \
--header 'RqUID: f32925a45cc740b1b4c71473f72e5c2c' \
--header 'Authorization: Basic **************' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=auth://demo/json' \
--cert-type P12 --cert mycert.12:********\
--cacert russian-trusted-cacert.pem


Вот на что меня хватило (кстати правильно ли?):
$ch = curl_init( 'https://mc.api.sberbank.ru:443/prod/tokens/v3/oaut' );

curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
	'RqUID:f32925a45cc740b1b4c71473f72e5c2c'
	'Content-Type:application/x-www-form-urlencoded'
	'Authorization:Basic **************'
) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query(
	array(
		'grant_type' => 'client_credentials',
		'scope' => 'auth://demo/json'
	),
	'', '&')
);

//  Как дальше — не знаю.

$html = curl_exec($ch);
curl_close($ch);	
echo $html;


Подскажите, если не сложно, что означает строчка c russian-trusted-cacert.pem? Это какой-то сертификат Минцифры. Что в этой строчке происходит вообще?
  • Вопрос задан
  • 101 просмотр
Решения вопроса 2
ThunderCat
@ThunderCat Куратор тега PHP
{PHP, MySql, HTML, JS, CSS} developer
Комментировать
@fokit
<?php

$url = 'https://mc.api.sberbank.ru:443/prod/tokens/v3/oauth';
$headers = [
    'RqUID: f32925a45cc740b1b4c71473f72e5c2c',
    'Authorization: Basic **************',
    'Content-Type: application/x-www-form-urlencoded'
];
$data = [
    'grant_type' => 'client_credentials',
    'scope' => 'auth://demo/json'
];
$certPath = 'mycert.12';
$certPass = '********';
$caCertPath = 'russian-trusted-cacert.pem';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSLCERT, $certPath);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $certPass);
curl_setopt($ch, CURLOPT_CAINFO, $caCertPath);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

?>
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы