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
|
<?php
$mailrecup=$_GET['mail'];
class SuiteApi
{
private
$_username,
$_secret,
$_suiteApiUrl;
public function __construct($username, $secret, $suiteApiUrl = 'https://api.emarsys.net/api/v2/')
{
$this->_username = $username;
$this->_secret = $secret;
$this->_suiteApiUrl = $suiteApiUrl;
}
public function send($requestType, $endPoint, $requestBody = '')
{
if (!in_array($requestType, array('GET', 'POST', 'PUT', 'DELETE'))) {
throw new Exception('Send first parameter must be "GET", "POST", "PUT" or "DELETE"');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
switch ($requestType)
{
case 'GET':
curl_setopt($ch, CURLOPT_HTTPGET, 1);
break;
case 'POST':
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
break;
case 'PUT':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
break;
case 'DELETE':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
break;
}
curl_setopt($ch, CURLOPT_HEADER, true);
$requestUri = $this->_suiteApiUrl . $endPoint;
curl_setopt($ch, CURLOPT_URL, $requestUri);
$nonce = '';
$timestamp = gmdate("c");
$passwordDigest = base64_encode(sha1($nonce . $timestamp . $this->_secret, false));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-WSSE: UsernameToken " .
"Username=\"$this->_username\", " .
"PasswordDigest=\"$passwordDigest\", " .
"Nonce=\"$nonce\", " .
"Created=\"$timestamp\"",
"Content-type: application/json;charset=\"utf-8\"",
)
);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
$demo = new SuiteApi('login', 'mdp');
echo $demo->send('POST', 'contact/getdata', '{ "keyId": "3",
"keyValues": ["'.$mailrecup.'"],
"fields": [1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]}') . "\n\n";
?> |
Partager