Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

738
Views
Binance Pay: error "La firma para esta solicitud no es válida" con PHP cURL

Estoy usando PHP cURL para conectarme a la API de Binance Pay. Obtuve el siguiente error:

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

Aquí está mi código:

 // 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);

En cuanto a la documentación, todo parece estar bien, pero no lo está, por lo que hay algo mal. ¿Alguna idea? ¡Gracias!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

En python (y muy probablemente también en PHP), la codificación json modifica ligeramente la solicitud json al agregar espacios y/o comillas de escape. La API de Binance Pay requiere que la cadena json sea exactamente como está en la documentación. Es decir, sin espacios extra.

over 4 years ago · Santiago Trujillo Report

0

Olvidaste agregar esto

 curl_setopt($ch, CURLOPT_POSTFIELDS, $json_request);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!