Good day,
when using API to create order, i have a errors:
"errorMessage" => "Signature for this request is not valid."
{"status":"FAIL","code":"400002","errorMessage":"Signature for this request is not valid."}
my code
// Generate nonce string
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$nonce = '';
for($i=1; $i <= 32; $i++)
{
$pos = mt_rand(0, strlen($chars) - 1);
$char = $chars[$pos];
$nonce .= $char;
}
//dump($nonce);
$ch = curl_init();
$timestamp = round((microtime(true)) * 1000);
//dump($timestamp1);
$params = [
"env" => [
"terminalType" => "WEB"
],
"orderTags" => [
"ifProfitSharing" => true
],
"merchantTradeNo" => $donate->id,
"orderAmount" => $donate->amount,
"currency" => "USDT",
"description" => "Donate",
"goodsDetails" => [
[
"goodsType" => "02",
"goodsCategory" => "6000",
"referenceGoodsId" => $donate->id,
"goodsName" => "Donate",
"goodsDetail" => "Donate"
]
]
];
$json_request = json_encode($params);
$payload = $timestamp.PHP_EOL.$nonce.PHP_EOL.$json_request.PHP_EOL;
//dump($payload);
$binancePayKey = config('binance_pay.binance_api_key');
$binancePaySecret = config('binance_pay.binance_secret_key');
$signature = strtoupper(hash_hmac('SHA512',$payload,$binancePaySecret));
//dump($signature);
$headers = [];
$headers[] = "Content-Type: application/json";
$headers[] = "BinancePay-Timestamp: $timestamp";
$headers[] = "BinancePay-Nonce: $nonce";
$headers[] = "BinancePay-Certificate-SN: $binancePayKey";
$headers[] = "BinancePay-Signature: $signature";
//dump(config('binance_pay.binance_api_url'));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, config('binance_pay.binance_api_url'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_request);
$result = curl_exec($ch);
if (curl_errno($ch)) { dd( 'Error:' . curl_error($ch)); }
curl_close ($ch);