Примеры по работе с API на разных языках
Отправка запроса
<?php
$url = "https://api.crystalpay.io/v3/method/list/";
$data = array(
"auth_login" => "example",
"auth_secret" => "example"
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
$response = curl_exec($ch);
if ($response === false) {
echo 'cURL Error: ' . curl_error($ch);
} else {
echo 'Response: ' . $response;
}
curl_close($ch);
<?php
require 'vendor/autoload.php'; // Убедитесь, что GuzzleHttp установлен через Composer
use GuzzleHttp\Client;
$client = new Client();
$url = "https://api.crystalpay.io/v3/method/list/";
$data = array(
"auth_login" => "example",
"auth_secret" => "example"
);
try {
$response = $client->post($url, [
'json' => $data
]);
$body = $response->getBody();
echo 'Response: ' . $body;
} catch (\GuzzleHttp\Exception\RequestException $e) {
echo 'Guzzle Error: ' . $e->getMessage();
}
import requests
url = "https://api.crystalpay.io/v3/method/list/"
headers = {
"Content-Type": "application/json"
}
data = {
"auth_login": "example",
"auth_secret": "example"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const axios = require('axios');
const url = 'https://api.crystalpay.io/v3/method/list/';
const data = {
auth_login: 'example',
auth_secret: 'example'
};
axios.post(url, data, {
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
Генерация подписи signature
signature
<?php
$id = "example_id";
$salt = "example_salt";
$signature = sha1($id . ":" . $salt );
echo "Signature: $signature";
import hashlib
id_value = "example_id"
salt = "example_salt"
hash_string = f"{id_value}:{salt}"
signature = hashlib.sha1(hash_string.encode()).hexdigest()
print(f"Signature: {signature}")
const crypto = require('crypto');
const id = 'example_id';
const salt = 'example_salt';
const signature = crypto.createHash('sha1').update(`${id}:${salt}`).digest('hex');
console.log(`Signature: ${signature}`);
Обратите внимание!
Данные примеры генерации подписи signature актуальны только для формата: {id}:{salt}.
В случае, если указано иное, необходимо скорректировать код под другой формат.
Last updated