• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

275
Views
Obtener un "parámetro ilegal" al intentar llamar a la API de pago de alipay en Sandbox

Entonces, lo que estoy tratando de hacer es hacer algunas llamadas API con AliPays https://global.alipay.com/docs/ac/ams/api API

Seguí la guía de integración y creé las claves privadas/públicas necesarias y el ID de cliente. También seguí la guía de generación de firmas aquí: https://global.alipay.com/docs/ac/ams/digital_signature#gNWs0

También copié parte del código de iTest, las herramientas de desarrollo de alipay, por lo que en realidad la función signWithSHA256RSA es de alipay.

Sé que mi clave privada debería funcionar porque pude probar con éxito la misma solicitud con las herramientas de desarrollo de alipay.

 // generate ISO 8601 date $oDateTime = new \DateTime(); $sDate = $oDateTime->format('c'); $privatekey = '<private_key_removed>'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'https://open-eu.alipay.com/ams/api/v1/payments/pay'); $reqBody = json_encode(array('productCode' => 'IN_STORE_PAYMENT')); $headers = array(); $headers[] = "Content-Type:application/json; charset=UTF-8"; $headers[] = "Request-Time:".$sDate; $headers[] = "client-id:<client_id_removed>"; $headers[] = "Signature:". "algorithm=RSA256,keyVersion=1,signature=".signWithSHA256RSA($sDate, $reqBody, $privatekey); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $reqBody); $rspContent = curl_exec($curl); function signWithSHA256RSA($timeString, $reqBody, $privateKey){ $priKey = "-----BEGIN RSA PRIVATE KEY-----\n". wordwrap($privateKey, 64, "\n", true). "\n-----END RSA PRIVATE KEY-----"; $signContent = "POST /ams/api/v1/payments/pay"."\n<client_id_removed>".".".$timeString. ".".$reqBody; openssl_sign($signContent, $signValue, $priKey, OPENSSL_ALGO_SHA256); return base64_encode($signValue); }

El código de error que me sale es:

 {"result": { "resultCode":"PARAM_ILLEGAL", "resultMessage":"illegal parameter:OpenapiV2签名字段异常: algorithm=RSA256,keyVersion=1,signature=<signature_removed>", "resultStatus":"F"} }
about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

Error a través de Google Translate: '签名字段异常' -> 'Excepción de campo de firma'

  1. Validar la firma. Reemplace $privateKey y $publicKey de sus secretos.
 $data = 'POST ...'; $keyPair = openssl_pkey_new( [ 'private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA, ] ); openssl_pkey_export($keyPair, $privateKey); $details = openssl_pkey_get_details($keyPair); $publicKey = $details['key']; openssl_sign($data, $signature, $privateKey, OPENSSL_ALGO_SHA256); var_dump($signature); //verify signature $isValidSignature = openssl_verify( $data, $signature, $publicKey, 'sha256WithRSAEncryption' ); var_dump($isValidSignature);
  1. En la documentación, dice generatedSignature=base64UrlEncode(sha256withrsa(<Content_To_Be_Signed>), <privateKey>))

y proporcionó un ejemplo de Java

return URLEncoder.encode(new String(Base64.encodeBase64(signed), "UTF-8"), "UTF-8");

el equivalente de php es

urlencode(base64_encode($signature))

about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error