· 6 years ago · Dec 20, 2019, 02:34 PM
1<?php
2$secretKey = 'SKHTAyCJnf6a94Wz';
3$path = 'https://paygatedirect.com/v2/';
4$requestType = 'webpay';
5$requestUrl = $path . $requestType;
6echo 'Параметры запроса: <br>';
7echo '<pre>';
8print_r($_POST);
9echo '</pre>';
10echo '=================================================';
11
12$bodyRequestArray = array(
13 'currency' => $_POST['currency'],
14 'serviceId' => $_POST['serviceId'],
15 'orderId' => $_POST['orderId'],
16 'amount' => $_POST['amount'],
17 'description' => $_POST['description']
18);
19$body = http_build_query($bodyRequestArray);
20$signature = getSignature($body, $secretKey);
21$ch = curl_init();
22curl_setopt($ch, CURLOPT_URL, $requestUrl);
23curl_setopt($ch, CURLOPT_POST, 1);
24curl_setopt($ch, CURLOPT_POSTFIELDS, $body); //Post Fields
25curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
26$headers = array(
27 'signature:'.$signature
28);
29curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
30$server_output = curl_exec($ch);
31curl_close ($ch);
32function getSignature($body, $secretKey){
33 // create signature
34 $hash = hash_hmac('sha256', $body, $secretKey, false);
35 return base64_encode($hash);
36}
37
38?>
39<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
40<html>
41 <head>
42 <title></title>
43 <meta name="" content="">
44 </head>
45 <body>
46 <h3>Ответ от API</h3>
47 <?php
48 echo $server_output;
49 ?>
50 </body>
51</html>