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 75 76 77 78 79 80 81 82 83 84 85 86 87
| <?PHP
$ID_WEBSITE = ""; // Veuillez renseigner l'identifiant de votre site web
$SECURE_KEY = ""; // Veuillez renseigner votre clé secrète
$URL_AC = "http://www.preprod.monsite.com/index.php";
/*
*
* Emission d'une demande
*
*/
echo "<br><br>== API Notification ==<br>";
$descNotification = array(
'query' => 'pushCommandeSHA1',
'order_ref' => 'REF_12345',
'email' => 'admin@email.fr',
'lastname' => 'nom_clien',
'firstname' => 'prenom_client',
'order_date' => '2016-02-23 12:44:21', // Format YYYY-MM-JJ HH:MM:SS
'delay' => '0', // 0=Immediatement / n jours compris entre 1 et 30 jours
'PRODUCTS' => array(
0=>array(
'id_product'=> '123',
'name_product'=>'produits_test',
'url_product'=>'http://google.fr',
'url_image_product'=>'http://google.fr/logo.png',
),
1=>array(
'id_product'=> 'reference_voyage_ouigo',
'name_product'=>'Oui Go',
),
),
'sign'=>''
);
$descNotification['sign']=SHA1($descNotification['query'].$descNotification['order_ref'].$descNotification['email'].$descNotification['lastname'].$descNotification['firstname'].$descNotification['order_date'].$descNotification['delay'].$SECURE_KEY);
$encryptedNotification=http_build_query(
array(
'idWebsite' => $ID_WEBSITE,
'message' => AC_encode_base64(json_encode($descNotification))
)
);
$postNotification = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $encryptedNotification
)
);
$contextNotification = stream_context_create($postNotification);
$resultNotification = file_get_contents($URL_AC.'?action=act_api_notification_sha1&type=json', false, $contextNotification);
echo $resultNotification,"<br><br>\n";
$resultNotification = json_decode(AC_decode_base64($resultNotification),true);
echo "==RETURN==[";
echo $resultNotification['return'];
echo "]<br><br>\n";
echo $resultNotification['debug'];
if($resultNotification['return'] == 1) {
echo "==> OK <br>";
// Tout c'est bien passé
} else {
echo "==> ERROR <br>";
// Il y a eu un problème, il faut analyser le code retour.
}
///////////////////////////////////
////////// LIBRAIRIES /////////////
///////////////////////////////////
function AC_encode_base64($sData){
$sBase64 = base64_encode($sData);
return strtr($sBase64, '+/', '-_');
}
function AC_decode_base64($sData){
$sBase64 = strtr($sData, '-_', '+/');
return base64_decode($sBase64);
}
?> |