The signature to create the order has been wrong

Build the content#

String payload = timestamp + “\n” + nonce + “\n” + body + “\n”;

Sign the content#

String signature = hex(hmac(“sha512”, payload, secretKey)).toUpperCase()

My question, I plan to use php to create an order, but the signature keeps prompting an error.

{“status”:“FAIL”,“code”:“400002”,“errorMessage”:“Signature for this request is not valid.”}

// Generate nonce string
$chars = ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$nonce = ‘’;
for($i=1; $i <= 32; $i++)
{
$pos = mt_rand(0, strlen($chars) - 1);
$char = $chars[$pos];
$nonce .= $char;
}
$ch = curl_init();
$timestamp = round(microtime(true) * 1000);
// Request body
$request = array(
“merchantTradeNo” => “12485634875fJhdd56”,
“totalFee” => 15,
“productDetail” => “productDetail”,
“currency” => “BUSD”,
“returnUrl” => “”,
“tradeType” => “WEB”,
“productType” => “productType”,
“productName” => “ProductName”
);
$json_request = json_encode($request);
$payload = $timestamp."\n".$nonce."\n".$json_request."\n";
$signature = strtoupper(hash_hmac(‘SHA512’,$payload,$binance_pay_secret));
$headers = array();
$headers = “Content-Type: application/json”;
$headers = “BinancePay-Timestamp: $timestamp”;
$headers = “BinancePay-Nonce: $nonce”;
$headers = “BinancePay-Certificate-SN: $binance_pay”;
$headers = “BinancePay-Signature: $signature”;

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, “https://bpay.binanceapi.com/binancepay/openapi/order”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$result = curl_exec($ch);
if (curl_errno($ch)) { echo ‘Error:’ . curl_error($ch); }
curl_close ($ch);

Thanks for your feedback, we will look into it.

how did you solved this?

@dino How did u solve it? pleaseeee

how did you solve the issue?
I am facing the signature mismatch issue,

<?php 
require_once 'config.php';
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$nonce = '';
for($i=1; $i <= 32; $i++)
{
	$pos = mt_rand(0, strlen($chars) - 1);
	$char = $chars[$pos];
	$nonce .= $char;
}
$ch = curl_init();
$timestamp = round(microtime(true) * 1000);
// Request body
$request = array(
	"merchantTradeNo" => "12485634875fJhdd56",
	"totalFee" => 15,
	"productDetail" => "productDetail",
	"currency" => "BUSD",
	"returnUrl" => "",
	"tradeType" => "WEB",
	"productType" => "productType",
	"productName" => "ProductName"
);

$json_request = json_encode($request);
$payload = $timestamp."\n".$nonce."\n".$json_request."\n"; 
$signature = strtoupper(hash_hmac('SHA512',$payload,$your_secret));

$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "BinancePay-Timestamp: $timestamp";
$headers[] = "BinancePay-Nonce: $nonce";
$headers[] = "BinancePay-Certificate-SN: $your_key";
$headers[] = "BinancePay-Signature: $signature";
 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "https://bpay.binanceapi.com/binancepay/openapi/order");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$result = curl_exec($ch); 
if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); }

curl_close ($ch); 

Exactly same issue did you solved it ?

did u solve it?

i have the same issue, how did you solved it?

Did anyone solved this problem? Im having signature invalid error please help

Have you tried this PHP signature example?

Hi @dino, you are suggesting source code which is outdated today January 2024.

Do you have sample source codes in different languages for the latest version of Binance Pay API v3?