4
0
mirror of https://github.com/cwinfo/envayasms.git synced 2025-07-03 13:47:44 +00:00

add foreground service to keep App in memory (otherwise rate-limiting won't work) and provide notification

This commit is contained in:
Jesse Young
2011-09-19 18:51:45 -07:00
parent a793a5f2e3
commit 9a574b3ab4
10 changed files with 268 additions and 22 deletions

View File

@ -16,10 +16,16 @@ class KalSMS
const STATUS_FAILED = 'failed';
const STATUS_SENT = 'sent';
const MESSAGE_TYPE_SMS = 'sms';
const MESSAGE_TYPE_MMS = 'mms';
static function new_from_request()
{
$version = @$_POST['version'];
$version = @$_POST['version'];
// If API version changes, could return different KalSMS instance
// to support multiple phone versions
return new KalSMS();
}
@ -96,9 +102,9 @@ class KalSMS
class KalSMS_OutgoingMessage
{
public $id = '';
public $to;
public $message;
public $id = ''; // ID generated by server
public $to; // destination phone number
public $message; // content of SMS message
}
class KalSMS_Action
@ -121,10 +127,37 @@ class KalSMS_Action_Test extends KalSMS_Action
}
}
class KalSMS_MMS_Part
{
public $form_name; // name of form field with MMS part content
public $cid; // MMS Content-ID
public $type; // Content type
public $filename; // Original filename of MMS part on sender phone
public $tmp_name; // Temporary file where MMS part content is stored
public $size; // Content length
public $error; // see http://www.php.net/manual/en/features.file-upload.errors.php
function __construct($args)
{
$this->form_name = $args['name'];
$this->cid = $args['cid'];
$this->type = $args['type'];
$this->filename = $args['filename'];
$file = $_FILES[$this->form_name];
$this->tmp_name = $file['tmp_name'];
$this->size = $file['size'];
$this->error = $file['error'];
}
}
class KalSMS_Action_Incoming extends KalSMS_Action
{
public $from;
public $message;
public $from; // Sender phone number
public $message; // The message body of the SMS, or the content of the text/plain part of the MMS.
public $message_type; // KalSMS::MESSAGE_TYPE_MMS or KalSMS::MESSAGE_TYPE_SMS
public $mms_parts; // array of KalSMS_MMS_Part instances
function __construct($kalsms)
{
@ -132,6 +165,16 @@ class KalSMS_Action_Incoming extends KalSMS_Action
$this->type = KalSMS::ACTION_INCOMING;
$this->from = $_POST['from'];
$this->message = $_POST['message'];
$this->message_type = $_POST['message_type'];
if ($this->message_type == KalSMS::MESSAGE_TYPE_MMS)
{
$this->mms_parts = array();
foreach (json_decode($_POST['mms_parts'], true) as $mms_part)
{
$this->mms_parts[] = new KalSMS_MMS_Part($mms_part);
}
}
}
function get_response_xml($messages)
@ -173,9 +216,9 @@ class KalSMS_Action_Outgoing extends KalSMS_Action
class KalSMS_Action_SendStatus extends KalSMS_Action
{
public $status;
public $id;
public $status; // KalSMS::STATUS_* values
public $id; // server ID previously used in KalSMS_OutgoingMessage
function __construct($type)
{
$this->type = KalSMS::ACTION_SEND_STATUS;