Приклади імплементації

Приклад реалізації протоколу ip2sms на php

<?php
function post_request($url, $login, $pwd)
{
$params = array('http' =>
array(
'method' => 'POST',
'header' => array('Authorization: Basic ' . base64_encode($login.":".$pwd),'Content-Type: text/xml'),
'content' => '<message><service id="single" source="<ALPHANAME>"/>
<to>+380631111111</to><body content-type="text/plain">Hello, this is ip2sms message</body></message>'
));

#var_dump ($params);

$ctx = stream_context_create($params);
$fp=@fopen($url, 'rb', FALSE, $ctx);
if ($fp) {
$response = @stream_get_contents($fp);
return $response;
}else{
return FALSE;
}
}
$login = '<username>';
$password = '<password>';

$answ = post_request('https://api.omnicell.com.ua/ip2sms/',$login,$password);
echo $answ;
exit;
?>

Приклад реалізації протоколу ip2sms на python

import urllib2
import base64

send_url = "https://api.omnicell.com.ua/ip2sms/"
login = '<login>'
password = '<password>'


alphaname = '<your alphaname>'
msisdn = '<Phone number>'
message_text='<Message text>'

request_template = """<?xml version="1.0" ?>
<message>
    <service id="single" source="{}" type="SMS"/>
    <to>{}</to>
    <body content-type="text/plain">{}</body>
</message>""".format(alphaname, msisdn, message_text)



request = urllib2.Request(send_url, data=request_template)

request.add_header("Content-Type", "text/xml")
auth_string = base64.encodestring('%s:%s' % (login, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % auth_string)

u = urllib2.urlopen(request)
request_result = u.read()

print request_template
print request_result