Пример запроса в ExpertSender на языке PHP

function createXML($apikey, $listID, $email, $username, $usercity, $userphone)
{
// $listID - https://service111.esv2.com/Lists/List
// смотри в "Подисчики"->"Списки рассылок"
//
$request ='<ApiRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">';
$request .='<ApiKey>'.$apikey.'</ApiKey>';
$request .='<Data xsi:type="Subscriber">';
$request .='<Mode>AddAndUpdate</Mode>';
$request .='<Force>true</Force>';
$request .='<ListId>'.$listID.'</ListId>';
$request .='<Email>'.$email.'</Email>';
$request .='<Firstname>'.$username.'</Firstname>';
$request .='<Properties>';
$request .='<Property>';
$request .='<Id>2</Id>';
$request .='<Value xsi:type="xs:string">'.$usercity.'</Value>';
$request .='</Property>';
$request .='<Property>';
$request .='<Id>3</Id>';
$request .='<Value xsi:type="xs:string">'.$userphone.'</Value>';
$request .='</Property>';
$request .='</Properties>';
$request .='</Data>';
$request .='</ApiRequest>';
return $request;
}
function sendData($url, $data)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//выполняем запрос
$content = curl_exec($curl);
//получаем ответ сервера
$info = curl_getinfo($curl);
curl_close($curl);
//Проверка возвращаемого ответа с помощью регулярки (2** - OK)
if ($info['http_code']=='200' || $info['http_code']=='204' || $info['http_code']=='201'){
//Возвращаем приветствие при удачной подписке
return 1;
} else {
//иначе возвращаем ошибку.
// 'Произошла ошибка - код ошибки: '.$info['http_code'].'. Попробуйте еще раз.';
return 0;
}
}
$url_api = "https://api612.esv2.com/v2/Api/Subscribers";
$apikey='117711SC2qf11i1174pT';
$listID = '111';
$email = 'yourmail@domain.zone';
$username = 'Vladimir';
$usercity = 'City';
$userphone = '100500';
$xmlstring = createXML($apikey, $listID, $email, $username, $usercity, $userphone);
$what_happen = sendData($url_api, $xmlstring);
print_r($what_happen);
function createXML($apikey, $listID, $email, $username, $usercity, $userphone) { // $listID - https://service111.esv2.com/Lists/List // смотри в "Подисчики"->"Списки рассылок" // $request ='<ApiRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">'; $request .='<ApiKey>'.$apikey.'</ApiKey>'; $request .='<Data xsi:type="Subscriber">'; $request .='<Mode>AddAndUpdate</Mode>'; $request .='<Force>true</Force>'; $request .='<ListId>'.$listID.'</ListId>'; $request .='<Email>'.$email.'</Email>'; $request .='<Firstname>'.$username.'</Firstname>'; $request .='<Properties>'; $request .='<Property>'; $request .='<Id>2</Id>'; $request .='<Value xsi:type="xs:string">'.$usercity.'</Value>'; $request .='</Property>'; $request .='<Property>'; $request .='<Id>3</Id>'; $request .='<Value xsi:type="xs:string">'.$userphone.'</Value>'; $request .='</Property>'; $request .='</Properties>'; $request .='</Data>'; $request .='</ApiRequest>'; return $request; } function sendData($url, $data) { $curl = curl_init(); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //выполняем запрос $content = curl_exec($curl); //получаем ответ сервера $info = curl_getinfo($curl); curl_close($curl); //Проверка возвращаемого ответа с помощью регулярки (2** - OK) if ($info['http_code']=='200' || $info['http_code']=='204' || $info['http_code']=='201'){ //Возвращаем приветствие при удачной подписке return 1; } else { //иначе возвращаем ошибку. // 'Произошла ошибка - код ошибки: '.$info['http_code'].'. Попробуйте еще раз.'; return 0; } } $url_api = "https://api612.esv2.com/v2/Api/Subscribers"; $apikey='117711SC2qf11i1174pT'; $listID = '111'; $email = 'yourmail@domain.zone'; $username = 'Vladimir'; $usercity = 'City'; $userphone = '100500'; $xmlstring = createXML($apikey, $listID, $email, $username, $usercity, $userphone); $what_happen = sendData($url_api, $xmlstring); print_r($what_happen);
function createXML($apikey, $listID, $email, $username, $usercity, $userphone)
{
    // $listID - https://service111.esv2.com/Lists/List
    // смотри в "Подисчики"->"Списки рассылок"
    // 
    $request ='<ApiRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">';
    $request .='<ApiKey>'.$apikey.'</ApiKey>';
    $request .='<Data xsi:type="Subscriber">';
    $request .='<Mode>AddAndUpdate</Mode>';
    $request .='<Force>true</Force>';
    $request .='<ListId>'.$listID.'</ListId>'; 
    $request .='<Email>'.$email.'</Email>';
    $request .='<Firstname>'.$username.'</Firstname>';
    $request .='<Properties>';
    $request .='<Property>';
    $request .='<Id>2</Id>';
    $request .='<Value xsi:type="xs:string">'.$usercity.'</Value>';
    $request .='</Property>';
    $request .='<Property>';
    $request .='<Id>3</Id>';
    $request .='<Value xsi:type="xs:string">'.$userphone.'</Value>';
    $request .='</Property>';
    $request .='</Properties>';
    $request .='</Data>';
    $request .='</ApiRequest>';
    return $request;
}

function sendData($url, $data)
{

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    //выполняем запрос
    $content = curl_exec($curl);
    //получаем ответ сервера
    $info = curl_getinfo($curl);
    curl_close($curl);
    //Проверка возвращаемого ответа с помощью регулярки (2** - OK)
    if ($info['http_code']=='200' || $info['http_code']=='204' || $info['http_code']=='201'){
        //Возвращаем приветствие при удачной подписке
        return 1;
        } else  {
        //иначе возвращаем ошибку.
        // 'Произошла ошибка - код ошибки: '.$info['http_code'].'. Попробуйте еще раз.';
        return 0;
    }
}

$url_api = "https://api612.esv2.com/v2/Api/Subscribers";
$apikey='117711SC2qf11i1174pT';
$listID = '111'; 
$email = 'yourmail@domain.zone';
$username = 'Vladimir';
$usercity = 'City';
$userphone = '100500';

$xmlstring = createXML($apikey, $listID, $email, $username, $usercity, $userphone);
$what_happen = sendData($url_api, $xmlstring);
print_r($what_happen);

Простой пример функции на языке php к сервису ExpertSender

Вам также может понравиться

About the Author: Vladimir Kusakin

Hi. I am web developer. For the past 9 years, I've been developing applications for the web using mostly PHP and Python. About me

2 комментария

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *