1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
<?php
require_once 'MessagesUtils.php';
$sender_account = '100103';
$recipient_account = '100104';
$recipient_name = 'boutique.com';
$order = 'A012/2012';
$product = '05561';
$url_return = 'http://thy85k.php'; /* utiliser des fichier de return generer dynamiquement a partir d'un template */
$url_cancel = 'http://ply5o92.php'; /* utiliser des fichier de return generer dynamiquement a partir d'un template */;
$amount = '500';
$api_key = '955g477t555d3011zgpkko'; /* c'est un identifiant utilisé pour récuperer la clé publique du marchand dans la base de icosnet */
$token = '8gfpjkjsmmfyerav'; /* c'est un token generer dynamiquement au niveau du marchand pour identifier chaque transaction */
$xmlString = MessagesUtils::buildMerchantRequest($sender_account, $recipient_account, $recipient_name, $order, $product, $url_return, $url_cancel, $amount, $api_key, $token);
/* ---------end build request ------------------ */
//crypt with public key
$fp = fopen("PublicKey.pem", "r");
$pub_key = fread($fp, 8192);
fclose($fp);
$PK = "";
$PK = openssl_get_publickey($pub_key);
$xmlString = urlencode($xmlString);
$xmlString = gzcompress($xmlString);
$xmlencrypted = "";
try {
openssl_public_encrypt($xmlString, $xmlencrypted, $PK);
} catch (Exception $exp) {
var_dump($exp);
}
/* fin de cryptage */
// Infobip's POST URL
$postUrl = "http://localhost/security/cryptography/traitement.php";
// previously formatted XML data becomes value of "XML" POST variable
$fields = "XML=" . $xmlencrypted;
// in this example, POST request was made using PHP's CURL
echo '--------- xmlencrypted marchent--------------------</br>';
var_dump($xmlencrypted);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
// response of the POST request
$result = curl_exec($ch);
$response = '';
if ($result == true) {
$response = ob_get_contents();
}
$xmlResponse = simplexml_load_string($response);
var_dump($xmlResponse);
curl_close($ch);
?> |
Partager