Я пытаюсь опубликовать в API, используя CURL.Когда я var_dump на curl_exec, я получаю сообщение "Malformed JSON".Я думаю, что мой JSON выглядит довольно хорошо, и он должен работать.Есть идеи, почему это не так?Вот
Результат моего JSON выглядит следующим образом:
{"AmountDebit": 10, "Currency": "EUR", "Invoice": "testinvoice 123", "Услуги ": {" список каналов ": [{" Action ":" Оплатить», "Имя": "идеал", "Параметры": [{ "Имя": "Эмитент", "Значение": "ABNANL2A"}]}]}}
мой код:
<?php
$postArray = array(
"Currency" => "EUR",
"AmountDebit" => 10.00,
"Invoice" => "testinvoice 123",
"Services" => array(
"ServiceList" => array(
array(
"Action" => "Pay",
"Name" => "ideal",
"Parameters" => array(
array(
"Name" => "issuer",
"Value" => "ABNANL2A"
)
)
)
)
)
);
ksort($postArray);
$post = json_encode($postArray);
echo $post . '<br><br>';
$md5 = md5($post, true);
$post = base64_encode($md5);
echo '<b>MD5 from json</b> ' . $md5 . '<br><br>';
echo '<b>base64 from MD5</b> ' . $post . '<br><br>';
$websiteKey = '-';
$uri = strtolower(urlencode('https://testcheckout.buckaroo.nl/json/transaction'));
$nonce = 'nonce_' . rand(0000000, 9999999);
$time = time();
$hmac = $websiteKey . 'POST' . $uri . $time . $nonce . $post;
$s = hash_hmac('sha256', $hmac, '-', true);
$hmac = base64_encode($s);
$url= 'https://testcheckout.buckaroo.nl/json/transaction';
echo 'Authorization: hmac ' .$websiteKey.':'.$hmac .':'.$nonce . ':'.$time;
$headers = array();
$headers[] = 'Authorization: hmac ' .$websiteKey.':'.$hmac .':'.$nonce . ':'.$time;
$headers[] = 'Content-Type: application/json';
$headers[] = 'Content-Length: ' . strlen(json_encode($postArray));
print_r($headers);
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl,CURLOPT_POSTFIELDS, json_encode($postArray));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
var_dump($result);
curl_close($curl);
?>