<?php
function get_key(){
$param = array(
'grant_type' => 'client_credentials',
'client_id' => 'bc5dc48863ff967b0ad30b20c37f9c65',
'client_secret' => '92153e52d943bd75c0fe74b3faaf1b02');
$vars = http_build_query($param);
print_r($vars);
$options = array(
'http' => array(
'method' => 'POST', // метод передачи данных
'header' => 'Content-type: application/x-www-form-urlencoded', // заголовок
'content' => $vars, // переменные
)
);
$context = stream_context_create($options);
$result = file_get_contents('https://api.sendpulse.com/oauth/access_token', false, $context);
$result = $result. "";
$array = explode('"', $result);
return $array[3];
}
function set_User($nameUser, $key, $email) {
//$param1 = array(
//'email' => $email
//);
//$serarr = serialize($param1);
//echo $serarr;
$param = array(
'access_token' => $key,
'id'=> '823257',
'name' => $nameUser
);
$vars = http_build_query($param);
$options = array(
'http' => array(
'method' => 'PUT',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $vars,
)
);
$context = stream_context_create($options);
return $result = file_get_contents('https://api.sendpulse.com/addressbooks/{id}', false,
$context);
}
$key = get_key();
echo '<br>';
print_r(set_User($_POST['name'], $key, $_POST['email']));
?>
require '../../vendor/autoload.php';
use Sendpulse\RestApi\ApiClient;
use Sendpulse\RestApi\Storage\FileStorage;
define( 'API_USER_ID', $_GET['client-id'] );
define( 'API_SECRET', $_GET['secret-id'] );
define( 'TOKEN_STORAGE', 'file' );
$SPApiProxy = new ApiClient( API_USER_ID, API_SECRET, new FileStorage() );
$emails = array(
array(
'email' => $_GET['email'],
'variables' => array(
'Phone' => $_GET['phone'],
'Name' => $_GET['name'],
)
),
);
$bookID = $_GET['bookID'];
$result = $SPApiProxy->addEmails($bookID,$emails);
$json_result = json_encode($result);
$json_beautified = str_replace(array("{", "}", ","), array("{<br /> ", "<br />}", ",<br /> "), $json_result);
print_r($json_beautified);