mirror of
https://github.com/cwinfo/envayasms.git
synced 2024-12-04 20:45:32 +00:00
update php server library and example
This commit is contained in:
parent
bf14f23fe5
commit
03d5f556d7
@ -11,6 +11,7 @@ class EnvayaSMS
|
|||||||
const ACTION_INCOMING = 'incoming';
|
const ACTION_INCOMING = 'incoming';
|
||||||
const ACTION_OUTGOING = 'outgoing';
|
const ACTION_OUTGOING = 'outgoing';
|
||||||
const ACTION_SEND_STATUS = 'send_status';
|
const ACTION_SEND_STATUS = 'send_status';
|
||||||
|
const ACTION_TEST = 'test';
|
||||||
|
|
||||||
const STATUS_QUEUED = 'queued';
|
const STATUS_QUEUED = 'queued';
|
||||||
const STATUS_FAILED = 'failed';
|
const STATUS_FAILED = 'failed';
|
||||||
@ -39,13 +40,22 @@ class EnvayaSMS
|
|||||||
static::$request = new EnvayaSMS_Request();
|
static::$request = new EnvayaSMS_Request();
|
||||||
}
|
}
|
||||||
return static::$request;
|
return static::$request;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnvayaSMS_Request
|
class EnvayaSMS_Request
|
||||||
{
|
{
|
||||||
private $request_action;
|
private $request_action;
|
||||||
|
|
||||||
|
public $version;
|
||||||
|
public $phone_number;
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->version = $_POST['version'];
|
||||||
|
$this->phone_number = $_POST['phone_number'];
|
||||||
|
}
|
||||||
|
|
||||||
function get_action()
|
function get_action()
|
||||||
{
|
{
|
||||||
if (!$this->request_action)
|
if (!$this->request_action)
|
||||||
@ -65,15 +75,12 @@ class EnvayaSMS_Request
|
|||||||
return new EnvayaSMS_Action_Outgoing($this);
|
return new EnvayaSMS_Action_Outgoing($this);
|
||||||
case EnvayaSMS::ACTION_SEND_STATUS:
|
case EnvayaSMS::ACTION_SEND_STATUS:
|
||||||
return new EnvayaSMS_Action_SendStatus($this);
|
return new EnvayaSMS_Action_SendStatus($this);
|
||||||
|
case EnvayaSMS::ACTION_TEST:
|
||||||
|
return new EnvayaSMS_Action_Test($this);
|
||||||
default:
|
default:
|
||||||
return new EnvayaSMS_Action($this);
|
return new EnvayaSMS_Action($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_phone_number()
|
|
||||||
{
|
|
||||||
return @$_POST['phone_number'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_validated($correct_password)
|
function is_validated($correct_password)
|
||||||
{
|
{
|
||||||
@ -108,11 +115,26 @@ class EnvayaSMS_Request
|
|||||||
|
|
||||||
return base64_encode(sha1($input, true));
|
return base64_encode(sha1($input, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function get_messages_xml($messages)
|
||||||
|
{
|
||||||
|
ob_start();
|
||||||
|
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
|
echo "<messages>";
|
||||||
|
foreach ($messages as $message)
|
||||||
|
{
|
||||||
|
$id = isset($message->id) ? " id='".EnvayaSMS::escape($message->id)."'" : "";
|
||||||
|
$to = isset($message->to) ? " to='".EnvayaSMS::escape($message->to)."'" : "";
|
||||||
|
echo "<sms$id$to>".EnvayaSMS::escape($message->message)."</sms>";
|
||||||
|
}
|
||||||
|
echo "</messages>";
|
||||||
|
return ob_get_clean();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnvayaSMS_OutgoingMessage
|
class EnvayaSMS_OutgoingMessage
|
||||||
{
|
{
|
||||||
public $id = ''; // ID generated by server
|
public $id; // ID generated by server
|
||||||
public $to; // destination phone number
|
public $to; // destination phone number
|
||||||
public $message; // content of SMS message
|
public $message; // content of SMS message
|
||||||
}
|
}
|
||||||
@ -128,15 +150,6 @@ class EnvayaSMS_Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnvayaSMS_Action_Test extends EnvayaSMS_Action
|
|
||||||
{
|
|
||||||
function __construct($request)
|
|
||||||
{
|
|
||||||
parent::__construct($request);
|
|
||||||
$this->type = EnvayaSMS::ACTION_TEST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class EnvayaSMS_MMS_Part
|
class EnvayaSMS_MMS_Part
|
||||||
{
|
{
|
||||||
public $form_name; // name of form field with MMS part content
|
public $form_name; // name of form field with MMS part content
|
||||||
@ -185,20 +198,12 @@ class EnvayaSMS_Action_Incoming extends EnvayaSMS_Action
|
|||||||
$this->mms_parts[] = new EnvayaSMS_MMS_Part($mms_part);
|
$this->mms_parts[] = new EnvayaSMS_MMS_Part($mms_part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_response_xml($messages)
|
function get_response_xml($messages)
|
||||||
{
|
{
|
||||||
ob_start();
|
return $this->request->get_messages_xml($messages);
|
||||||
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
|
}
|
||||||
echo "<messages>";
|
|
||||||
foreach ($messages as $message)
|
|
||||||
{
|
|
||||||
echo "<sms id='".EnvayaSMS::escape($message->id)."'>".EnvayaSMS::escape($message->message)."</sms>";
|
|
||||||
}
|
|
||||||
echo "</messages>";
|
|
||||||
return ob_get_clean();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnvayaSMS_Action_Outgoing extends EnvayaSMS_Action
|
class EnvayaSMS_Action_Outgoing extends EnvayaSMS_Action
|
||||||
@ -207,20 +212,20 @@ class EnvayaSMS_Action_Outgoing extends EnvayaSMS_Action
|
|||||||
{
|
{
|
||||||
parent::__construct($request);
|
parent::__construct($request);
|
||||||
$this->type = EnvayaSMS::ACTION_OUTGOING;
|
$this->type = EnvayaSMS::ACTION_OUTGOING;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_response_xml($messages)
|
function get_response_xml($messages)
|
||||||
{
|
{
|
||||||
ob_start();
|
return $this->request->get_messages_xml($messages);
|
||||||
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
|
}
|
||||||
echo "<messages>";
|
}
|
||||||
foreach ($messages as $message)
|
|
||||||
{
|
class EnvayaSMS_Action_Test extends EnvayaSMS_Action
|
||||||
echo "<sms id='".EnvayaSMS::escape($message->id)."' to='".EnvayaSMS::escape($message->to)."'>".
|
{
|
||||||
EnvayaSMS::escape($message->message)."</sms>";
|
function __construct($request)
|
||||||
}
|
{
|
||||||
echo "</messages>";
|
parent::__construct($request);
|
||||||
return ob_get_clean();
|
$this->type = EnvayaSMS::ACTION_TEST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ ini_set('display_errors','0');
|
|||||||
|
|
||||||
$request = EnvayaSMS::get_request();
|
$request = EnvayaSMS::get_request();
|
||||||
|
|
||||||
$phone_number = $request->get_phone_number();
|
$phone_number = $request->phone_number;
|
||||||
|
|
||||||
$password = @$PASSWORDS[$phone_number];
|
$password = @$PASSWORDS[$phone_number];
|
||||||
|
|
||||||
@ -79,7 +79,9 @@ switch ($action->type)
|
|||||||
echo "invalid id";
|
echo "invalid id";
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
case EnvayaSMS::ACTION_TEST:
|
||||||
|
echo "OK";
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
header("HTTP/1.1 404 Not Found");
|
header("HTTP/1.1 404 Not Found");
|
||||||
echo "Invalid action";
|
echo "Invalid action";
|
||||||
|
Loading…
Reference in New Issue
Block a user