Here is an example of how to talk from a middleware PHP application to YateSMSC to send a SMS to a subscriber.
The code is divided in two parts: an utility function that can be used as-is and a sample HTML form.
The library
This is the utility function that hides all the JSON API interaction.
You may save the PHP code below to a file named ysmsc_send.php
<?php
/* ysmsc_send.php
* This file is part of the YATE Project http://YATE.null.ro
*
* JSON over HTTP API simple SMS send function for YateSMSC
*
* Yet Another Telephony Engine – a fully featured software PBX and IVR
* Copyright (C) 2017-2018 Null Team
*
* This software is distributed under multiple licenses;
* see the COPYING file in the main directory for licensing
* information for this specific distribution.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* Submit a SMS to YateSMSC using a JSON/HTTP request, requires php-curl
* @param $url URL of the YateSMSC API
* @param $orig Originator MSISDN or short alphanumeric string
* @param $dest Destination MSISDN
* @param $text Depending of $format: Text of the short message / TPDU / Encoded UD
* @param $tout Optional timeout, defaults to 5 seconds
* @param $format String: “text” / “tpdu” / “encoded_ud”, default “text”
* @param $pid Protocol ID to use when $format is encoded_ud, default 0
* @param $dcs Data Coding Scheme to use when $format is encoded_ud, default 0
* @param $udhi Indication that User Data Header is present in encoded_ud, default false
* @return Error text, null on success
*/
function sendSmsJson($url,$orig,$dest,$text,$tout = 5,$format = “text”,$pid = 0,$dcs = 0,$udhi = false)
{
$url = trim($url);
$orig = trim($orig);
$dest = trim($dest);
if (!$url || “” == $orig || “” == $dest || “” == $text)
return “Missing one or more parameters”;
if (!preg_match(‘/^[+]?[1-9][0-9]+$/’,$dest))
return “Invalid destination number”;
$params = array(
“originator” => $orig,
“destination” => $dest
);
if ($format != “text_ucs2”) {
$params[“$format”] = $text;
} else {
$params[“text”] = $text;
$params[“text.encoding”] = “ucs2”;
}
if ($format == “encoded_ud”) {
$params[“dcs”] = $dcs;
$params[“pid”] = $pid;
$params[“udhi”] = $udhi;
}
if (!preg_match(‘/^[+]?[1-9][0-9]+$/’,$orig))
$params[“orignumtype”] = “alphanumeric”;
else if (strlen($orig) < 5)
$params[“orignumtype”] = “unknown”;
$body = json_encode(array(
“request” => “schedule_sms”,
“node” => “smsc”,
“params” => $params
));
$curl = curl_init($url);
if (false === $curl)
return “cURL initialization failure”;
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$body);
curl_setopt($curl,CURLOPT_HTTPHEADER,array(
“Content-Type: application/json”,
“Accept: application/json,text/x-json”,
“Expect:”
));
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,$tout);
curl_setopt($curl,CURLOPT_TIMEOUT,$tout);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
$body = curl_exec($curl);
if (false === $body)
$body = curl_error($curl);
else {
$info = curl_getinfo($curl,CURLINFO_HTTP_CODE);
if (200 != $info)
$body = “HTTP returned code: $info”;
else {
$info = curl_getinfo($curl,CURLINFO_CONTENT_TYPE);
if (false === strpos($info,”json”))
$body = “Unexpected MIME type: $info”;
else {
$body = json_decode($body,true);
if (isset($body[“scheduled_sms”]))
$body = null;
else if (isset($body[“code”])) {
if (isset($body[“message”]))
$body = “API error ” . $body[“code”] . “: ” . $body[“message”];
else
$body = “API error code ” . $body[“code”];
}
else if (isset($body[“message”]))
$body = “API error: ” . $body[“message”];
else
$body = “Unknown API error”;
}
}
}
curl_close($curl);
return $body;
}
?>
Sample form
This is just a short example on how to actually call the sendSmsJson() function.
You may save the PHP code below to a file named send_sms.php placed in the same directory as ysmsc_send.php on the Web server.
<?php
/* Sample form for sending a SMS to YateSMSC */
require_once(“ysmsc_send.php”);
$url = isset($_POST[“url”]) ? $_POST[“url”] : “”;
$orig = isset($_POST[“orig”]) ? $_POST[“orig”] : “”;
$dest = isset($_POST[“dest”]) ? $_POST[“dest”] : “”;
$text = isset($_POST[“text”]) ? $_POST[“text”] : “”;
$format = isset($_POST[“format”]) ? $_POST[“format”] : “”;
$pid = isset($_POST[“pid”]) ? $_POST[“pid”] : “00”;
$dcs = isset($_POST[“dcs”]) ? $_POST[“dcs”] : “00”;
$udhi = (isset($_POST[“udhi”]) && $_POST[“udhi”]==”on”) ? true : false;
$res = “”;
if (“” != $url && “” != $orig && “” != dest && “” != $text) {
$res = sendSmsJson($url,$orig,$dest,$text,5,$format,hexdec($pid),hexdec($dcs),$udhi);
if ($res)
$res = htmlspecialchars($res);
else
$res = “OK”;
}
?><html>
<head>
<title>Test sending SMS</title>
<script type=”text/javascript”>
function get_selected(id_name)
{
var selector_obj = document.getElementById(id_name);
if (selector_obj==null)
return null;
var sel = selector_obj.options[selector_obj.selectedIndex].value || selector_obj.options[selector_obj.selectedIndex].text;
return sel;
}
function show_tr(id_name,visible)
{
var element = document.getElementById(id_name);
if (element == null)
return;
element.style.display = visible ? “table-row” : “none”;
}
function show_ud_params(visible)
{
show_tr(“tr_dcs”,visible);
show_tr(“tr_pid”,visible);
show_tr(“tr_udhi”,visible);
}
</script>
</head>
<body bgcolor=”#e0e0e0″>
<h1>Test sending SMS</h1>
<form method=”POST”>
<table border=”0″ bgcolor=”#c0c0c0″>
<tr><th>API URL:</th><td colspan=”2″><input type=”text” name=”url” size=”64″ value=”<?php print “$url”; ?>” /></td></tr>
<tr><th>Originator:</th><td colspan=”2″><input type=”text” name=”orig” size=”16″ value=”<?php print “$orig”; ?>” />
(number or short alphanumeric)</td></tr>
<tr><th>Destination:</th><td><input type=”text” name=”dest” size=”16″ value=”<?php print “$dest”; ?>” />
(number only)</td></tr>
<tr><th>Format:</th><td><select name=”format” id=”format” onchange=”show_ud_params(‘encoded_ud’==get_selected(‘format’));”>
<option value=”text” <?php if ($format==”text”) print “SELECTED”;?>>Text (GSM7bit)</option>
<option value=”text_ucs2″ <?php if ($format==”text_ucs2″) print “SELECTED”;?>>Text (UCS2)</option>
<option value=”tpdu” <?php if ($format==”tpdu”) print “SELECTED”;?>>TPDU (hex)</option>
<option value=”encoded_ud” <?php if ($format==”encoded_ud”) print “SELECTED”;?>>Enc. UD (hex)</option></select>
</td><td align=”right”><input type=”submit” /></td></tr>
<tr id=”tr_pid” <?php if ($format!=’encoded_ud’) print “style=’display:none;'” ?> ><th>PID:</th><td><input type=”text” name=”pid” size=”2″ value=”<?php print “$pid”; ?>”/> (1 octet – hexadecimal)</td></tr>
<tr id=”tr_dcs” <?php if ($format!=’encoded_ud’) print “style=’display:none;'” ?> ><th>DCS:</th><td><input type=”text” name=”dcs” size=”2″ value=”<?php print “$dcs”; ?>”/> (1 octet – hexadecimal)</td></tr>
<tr id=”tr_udhi” <?php if ($format!=’encoded_ud’) print “style=’display:none;'” ?> ><th>UDHI:</th><td><input type=”checkbox” name=”udhi” <?php if ($udhi) print “CHECKED”; ?>/> </td></tr>
<tr><th>SMS:</th><td colspan=”2″><textarea name=”text” rows=”30″ cols=”64″><?php print “$text”; ?></textarea></td></tr>
<tr><th>Result:</th><td colspan=”2″><?php print “$res”; ?></td></tr>
</table>
</form>
</body>
</html>
The result
Point your browser to the send_sms.php on the server and you should see the form.
Fill the fields and click on Submit. Please note that an alphanumeric originator can be at most 11 characters long as it needs to fit in 10 octets after GSM-7 packing.

If the result is OK the short message was queued in the SMSC.
JSON Request
Here is the JSON API communication as logged by YateSMSC:
—— 2017-06-21 17:22:08, ip=xxx.xxx.xxx.xxx
Json: {“request”:”schedule_sms”,”node”:”smsc”,”params”:{“originator”:”Operator”,”destination”:”+88270053″,”text”:”Hello\r\n there!”,”orignumtype”:”alphanumeric”}}}
JsonOut: {“code”:0,”scheduled_sms”:1}
SMSC CDR
And here is how the SMS looks like in the YateSMSC’s CDR:
Time Typ Node Billing ID Prot Address or GT Caller Called Durat Directn IMSI
————– — —- ————- —- ——————— ——– ——– —– ——– —————
1498054928.666 msg SMSC 1496685302-48 HTTP xxx.xxx.xxx.xxx:38268 Operator 88270053 0.011 incoming
1498054929.492 msg SMSC 1496685302-48 MAP 882xxxxxxx Operator 88270053 5.301 outgoing 00101xxxxxxxxxx