I am trying to consume a web service for online payments with PHP, according to the guide are only 4 simple steps. link
Only in step 4 the server returns an empty string.
public function prueba()
{
$xmlOriginal= '<?xml version="1.0" encoding="UTF-8"?><P><business><id_company>SNBX</id_company><id_branch>01SNBXBRNCH</id_branch><user>SNBXUSR01</user><pwd>SECRETO</pwd></business><url><reference>FACTURA999</reference><amount>2500.00</amount><moneda>MXN</moneda><canal>W</canal><omitir_notif_default>1</omitir_notif_default><promociones>C,3,6,9</promociones><st_correo>1</st_correo><fh_vigencia>24/06/2018</fh_vigencia><mail_cliente>[email protected]</mail_cliente><datos_adicionales><data id="1" display="true"><label>Talla</label><value>Grande</value></data><data id="2" display="false"><label>Color</label><value>Azul</value></data></datos_adicionales></url></P>';
$key = '**************************';
$xmlEncriptado= $this->encriptar($xmlOriginal, $key);
$data = '<pgs><data0>SNDBX123</data0><data>'.$xmlEncriptado.'</data></pgs>';
$headers = [
'cache-control' => 'no-cache',
'content-type' => 'application/x-www-form-urlencoded'
];
$url = "https://bc.mitec.com.mx/p/gen";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$ch_info = curl_getinfo($ch);
$ch_error = curl_error($ch);
curl_close($ch);
dd([$ch_error, $ch_info, $response]);
$response = $this->desencriptar($response, $key);
}
protected function encriptar($plaintext, $key128){
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-128-cbc'));
$cipherText = openssl_encrypt ( $plaintext, 'AES-128-CBC', hex2bin($key128), 1, $iv);
return base64_encode($iv.$cipherText);
}
public static function desencriptar($encodedInitialData, $key128){
$encodedInitialData = base64_decode($encodedInitialData);
$iv = substr($encodedInitialData,0,16);
$encodedInitialData = substr($encodedInitialData,16);
$decrypted = openssl_decrypt($encodedInitialData, 'AES-128-CBC', hex2bin($key128), 1, $iv);
return $decrypted;
}
When doing dd()
or var_dump()
of $response
string is empty
dd([$ch_error, $ch_info, $response]);
It is assumed that when decrypting $reponse
I should get an xml with a link like this link