- clickatell.php
- 2009 year 11 month 24 day Tuesday 03:03:32 MDT
- #! /opt/csw/php5/bin/php
- <?php
- /*
- * Send SMS notifications using the Clickatell HTTP API Interface
- *
- * Description of command line parameters: see further down...
- *
- * Clickatell HTTP API Documentation:
- * http://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf
- * -> http://docs.google.com/viewer?url=http://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf
- */
- // "Enhance" the implode() function to work with associative arrays (eg. array("user" => "john"))
- function implode_assoc($array, $inner_glue = '=', $outer_glue = '&') {
- foreach( $array as $key => $item )
- $output[] = $key . $inner_glue . $item;
- }
- // Parse command line parameters
- if (
- ($args == FALSE)
- ){
- echo "Error! Command line arguments could not be parsed!
- * The script requires the following command line parameters:
- * # -t ['to' SMS Recipient Number - \$CONTACTPAGER\$] #
- * # -u [Clickatell Username] #
- * # -p [Clickatell Password] #
- * # -i [Clickatell API ID] #
- * -@ [Scheduled Delivery Time; When should the message be sent?; Formats: Unix timestamp (1233133393) or UTC date format (2009-01-30T14:00:00Z)]
- * -f ['from' Source Address A valid international format number between 1 and 16 characters long, or an 11 character alphanumeric string.]
- * -b [Clickatell Callback type; see 5.2.4 Callback URL (callback); 0 = off, 3 = intermediate & final status]
- * -c [Max. number of concatted msgs to send out. By default (1), only 1 160char msg is send. If set to 2 or 3, 2x or 3x (160-7) char are allowed]
- * -q [Required SMS Features; see 5.2.8 Required features (req_feat); needs to incl. 16 if using Alpha From]
- * -x [Max. Credits; how many credits is ONE SMS message allowed to consum?; should be set to 3, to allow every possible SMS]
- * Parameters listed with # are REQUIRED; others are optional.
- * The script reads the SMS text from STDIN, ie. invoke it like so:
- * printf 'Hello\\nWorld!' | " . $_SERVER['SCRIPT_NAME'] . " -u JohnDoe -p FooBar -i 9876543 ...
- * Clickatell HTTP API Documentation:
- * http://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf
- * -> http://docs.google.com/viewer?url=http://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf
- ";
- }
- echo "Welcome - Going to send an SMS....\n";
- // "Fetch" parameters from the $args array
- // "Sanitize" the number of the recipient - ie. drop any non-digit char
- // Set "FROM"
- // SMS Concatenation
- // Maximum number of SMS to send, which makes up 1 msg at the
- // receiver. Allows to send SMS messages which are longer than
- // 160char
- // See 5.2.6 Concatenation (concat)
- // Callback Value
- // See 5.2.4 Callback URL (callback)
- //
- // Callback Message status types returned Message status code returned
- // value
- // 0 No message status returned.
- // 1 Returns only intermediate statuses. 002, 003, 011
- // 2 Returns only final statuses of a message. 004, 005, 006, 007, 008, 010, 012
- // 3 Returns both intermediate and final statuses of a msg. All except 001
- // Required Features
- // See 5.2.8 Required features (req_feat)
- //
- // Hex Decimal Feature Description
- // 0x0001 1 FEAT_TEXT Text set by default.
- // 0x0002 2 FEAT_8BIT 8-bit messaging set by default.
- // 0x0004 4 FEAT_UDH UDH (Binary) - set by default.
- // 0x0008 8 FEAT_UCS2 UCS2 / Unicode set by default.
- // 0x0010 16 FEAT_ALPHA Alpha source address (from parameter).
- // 0x0020 32 FEAT_NUMER Numeric source address (from parameter).
- // 0x0200 512 FEAT_FLASH Flash messaging.
- // 0x2000 8192 FEAT_DELIVACK Delivery acknowledgments.
- // 0x4000 16384 FEAT_CONCAT Concatenation set by default.
- // Maximum Credits
- // This parameter overrides the maximum charge associated with message delivery,
- // 5.2.7 Maximum credits (max_credits)
- // Scheduled Time
- // The purpose of this parameter is to allow you to specify when you want a message to be delivered.
- // See 5.2.16 Scheduled Time
- // Formats:
- // 1) Unix timestamp:
- // scheduled_time:1233133393
- // 2) UTC date format:
- // scheduled_time:2009-01-30T14:00:00Z
- // Read the to-be sent message from stdin.
- // Convert UTF-8 chars -> iso-8859-1
- // Only allow $concat_count * (160-7) chars in $text
- } else {
- }
- // URL to prepend to all outgoing calls
- // auth call
- $cmd = "auth";
- $cmd_parms = array("user" => CLICKATELL_USER, "password" => CLICKATELL_PASS, "api_id" => CLICKATELL_API_ID);
- // do auth call
- // split our response. return string is on first line of the data returned
- // Did we get an "OK"? If so, continue with sending the message.
- if ($sess[0] == "OK") {
- $cmd = "sendmsg";
- "to" => TO,
- "text" => $text
- );
- // echo 'url: ' . $url . "\n";
- // exit(42);
- // do sendmsg call
- if ($send[0] == "ID") {
- echo "success
- message ID: ". $send[1] . "\n";
- } else {
- }
- } else {
- }
- // We cannot reach this spot!
- echo "ERROR! Impossible program location!";
- // EOF //
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.