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_OUTGOING = 'outgoing';
|
||||
const ACTION_SEND_STATUS = 'send_status';
|
||||
const ACTION_TEST = 'test';
|
||||
|
||||
const STATUS_QUEUED = 'queued';
|
||||
const STATUS_FAILED = 'failed';
|
||||
@ -39,13 +40,22 @@ class EnvayaSMS
|
||||
static::$request = new EnvayaSMS_Request();
|
||||
}
|
||||
return static::$request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class EnvayaSMS_Request
|
||||
{
|
||||
private $request_action;
|
||||
|
||||
public $version;
|
||||
public $phone_number;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->version = $_POST['version'];
|
||||
$this->phone_number = $_POST['phone_number'];
|
||||
}
|
||||
|
||||
function get_action()
|
||||
{
|
||||
if (!$this->request_action)
|
||||
@ -65,15 +75,12 @@ class EnvayaSMS_Request
|
||||
return new EnvayaSMS_Action_Outgoing($this);
|
||||
case EnvayaSMS::ACTION_SEND_STATUS:
|
||||
return new EnvayaSMS_Action_SendStatus($this);
|
||||
case EnvayaSMS::ACTION_TEST:
|
||||
return new EnvayaSMS_Action_Test($this);
|
||||
default:
|
||||
return new EnvayaSMS_Action($this);
|
||||
}
|
||||
}
|
||||
|
||||
function get_phone_number()
|
||||
{
|
||||
return @$_POST['phone_number'];
|
||||
}
|
||||
}
|
||||
|
||||
function is_validated($correct_password)
|
||||
{
|
||||
@ -108,11 +115,26 @@ class EnvayaSMS_Request
|
||||
|
||||
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
|
||||
{
|
||||
public $id = ''; // ID generated by server
|
||||
public $id; // ID generated by server
|
||||
public $to; // destination phone number
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_response_xml($messages)
|
||||
{
|
||||
ob_start();
|
||||
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();
|
||||
}
|
||||
return $this->request->get_messages_xml($messages);
|
||||
}
|
||||
}
|
||||
|
||||
class EnvayaSMS_Action_Outgoing extends EnvayaSMS_Action
|
||||
@ -207,20 +212,20 @@ class EnvayaSMS_Action_Outgoing extends EnvayaSMS_Action
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->type = EnvayaSMS::ACTION_OUTGOING;
|
||||
}
|
||||
}
|
||||
|
||||
function get_response_xml($messages)
|
||||
{
|
||||
ob_start();
|
||||
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
echo "<messages>";
|
||||
foreach ($messages as $message)
|
||||
{
|
||||
echo "<sms id='".EnvayaSMS::escape($message->id)."' to='".EnvayaSMS::escape($message->to)."'>".
|
||||
EnvayaSMS::escape($message->message)."</sms>";
|
||||
}
|
||||
echo "</messages>";
|
||||
return ob_get_clean();
|
||||
return $this->request->get_messages_xml($messages);
|
||||
}
|
||||
}
|
||||
|
||||
class EnvayaSMS_Action_Test extends EnvayaSMS_Action
|
||||
{
|
||||
function __construct($request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->type = EnvayaSMS::ACTION_TEST;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ ini_set('display_errors','0');
|
||||
|
||||
$request = EnvayaSMS::get_request();
|
||||
|
||||
$phone_number = $request->get_phone_number();
|
||||
$phone_number = $request->phone_number;
|
||||
|
||||
$password = @$PASSWORDS[$phone_number];
|
||||
|
||||
@ -79,7 +79,9 @@ switch ($action->type)
|
||||
echo "invalid id";
|
||||
}
|
||||
return;
|
||||
|
||||
case EnvayaSMS::ACTION_TEST:
|
||||
echo "OK";
|
||||
return;
|
||||
default:
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
echo "Invalid action";
|
||||
|
Loading…
Reference in New Issue
Block a user