This script allows you to send SMS (also long SMS), EMS, RTTTL-Ringtones, Logos (GIF, JPG, PNG) with automatic image resizing, EMS Pictures with copy protection and autosave feature, Nokia Operator Logos, Nokia Multipart messages and so on. Pictures and Ringtones can be HEX-included or specified to be downloaded from a HTTP-source. You can setup the 2-way service within minutes on TrueSenses.com. Requires NO additional libraries programs or databases.
By : simmcomm
<html>
<head>
<title>TrueSenses Response</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
/*
************************************************************************************
* 2-way mobile messaging script, (c) 2003 TrueSenses.com - http://www.truesenses.com
*
* -> This script allows you to operate a 2-way SMS service and send ringtones, logos
* -> and much more directly from your site.
*
* -> This script does not need any other execution rights like executing sub-
* -> programs and should therefore run on almost every server supporting PHP.
*
* -> For outgoing SMS you will need to have a TrueSenses.com account.
* -> For incoming SMS you will need to activate the keyword service for as low as
* -> CHF 5.- (Swiss Francs) per keyword and month including unlimited incoming SMS.
*
* You will need to configure $truesenses_account,$truesenses_password and
* $truesenses_origin
*
* This script is pre-configured to act on incoming SMS messages sent by the
* TrueSenses.com SMS-Gateway. It will compare the incoming keyword and send back
* the requested content.
*
* If you ONLY want to use this script to send messages (without 2-way service),
* simply modify the MAIN program code to discard the incoming parameters provided
* by the gateway: $NUMBER (origin number, international format) and $MESSAGE
*
* The following message-modes are supported:
*
* - SMS
* - EMS
* - EMS Images
* - NOKIA Ringtones
* - NOKIA Logos
* - NOKIA Multipart messages (Picture Message with text)
*
*
* In order to install the 2-way SMS script follow these steps:
*
*
* 1. Open an account on TrueSenses.com
* 2. Configure this script with your Account/Password and upload it to your server
* 3. Buy some outgoing SMS credits
* 4. Go to Configuration / Keyword services and add a keyword
* 4.1 Click on the keyword and activate PUSH to forward incoming SMS to this script
* example: http://www.[yoursitename].com/truesenses_2way.php
* method: select POST method - dont forget to click on "Activated"
* 4.2 Activate the keyword by clicking "Activate keyword"
* 5. Your service is now up and running
*
* Send the following SMS to +41-79 381 60 10 or the number given by TrueSenses.com
*
* yourkeyword SMS
* -> You will receive a SMS back to your phone.
*
* yourkeyword SMSFLASH
* -> You will receive a flashing class 0 SMS back to your phone.
*
* yourkeyword NOKIARINGTONE
* -> You will receive a ringtone for your NOKIA phone, downloaded from HTTP-Source.
*
* yourkeyword NOKIARINGTONEHEX
* -> You will receive a ringtone for your NOKIA phone, included as hex-encoded.
*
* yourkeyword NOKIALOGO
* -> You will receive an operator logo for your NOKIA phone, downloaded from HTTP-
* -> source. IMPORTANT: configure the mnc and mmc settings first according to the
* -> destination provider. Otherwise the logo will not show up.
*
* yourkeyword NOKIAMULTIPART
* -> You will receive a picture message with a text for your NOKIA phone, downloaded
* -> from a HTTP-source.
*
* yourkeyword EMSLOGO
* -> You will receive a picture message for your NON-Nokia phone like SonyEricsson
* -> and all other vendors who support the EMS-standard on their phones. The image
* -> is by default copy protected and cannot be sent to another phone. You can de-
* -> activate this by setting protected = "NO".
*
************************************************************************************
*/
$truesenses_account = "YourAccountName"; // TrueSenses.com Account-Name
$truesenses_password = "YourPassword"; // Account-Password
$truesenses_origin = "TrueSenses"; // Message-Origin, 11 alpha chars or numeric number
$debug = 0; // debug-output 0 = off, 1 = on
//
// open a http-channel, transmit data and return received buffer
function sendToHost($host,$method,$path,$data,$useragent,$poststr)
{
global $debug;
if (empty($method)) { // default GET
$method = 'GET';
}
$method = strtoupper($method);
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
if ($debug == 1) {
echo("Could not open connection<br>$errstr ($errno)<br>\n");
}
} else {
if ($method == 'GET')
$path .= '?' . $data;
fputs($fp, "$method $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
if ($method == 'POST') {
fputs($fp, "Content-Length: " . strlen($data) . "\r\n");
} else {
if (strlen($poststr)>0) { // if something to POST on GET method
fputs($fp, "Content-Length: " . strlen($poststr) . "\r\n");
}
}
if (strlen($useragent)>0) {
fputs($fp, "User-Agent: $useragent\r\n");
} else {
fputs($fp, "User-Agent: TrueSensesPHP\r\n");
}
fputs($fp, "Connection: close\r\n");
fputs($fp, "\r\n");
if ($method == 'POST') {
fputs($fp, $data);
} else { // GET method
if (strlen($poststr)>0) { // if something to POST on GET method
fputs($fp, $poststr);
}
}
$buf = "";
$line = "";
$chr = "0";
$contentsize = "0";
// echo("reading response\n");
while ((!feof($fp)) && (strlen($buf)<=100000) && ($chr < 500)) { // read max 100000 bytes or 500 lines
$chr = $chr + 1;
$line = fgets($fp, 10000); // read one line
$buf .= $line; // append to buffer
}
// sometimes contentsize was not received ...had to replace with part below
/*
$contpos = strpos(strtoupper($buf), "CONTENT-LENGTH:");
if ($contpos > 0) { // determine content size
if ($debug == 1) {
echo("decoding content-length<br>\n");
}
$contentsize = substr($buf, ($contpos + 16), 20);
while (strpos($contentsize, "\n") > 0) {
$contentsize = substr($contentsize, 0, strpos($contentsize, "\n") -1);
}
while (strpos($contentsize, "\r") > 0) {
$contentsize = substr($contentsize, 0, strpos($contentsize, "\r") -1);
}
if ($debug == 1) {
echo("contentsize::$contentsize::<br>\n");
}
} else {
if ($debug == 1) {
echo("NO contentsize found in ::$buf::<br>\n");
}
return "ERROR";
}
*/
// replaced above part with this one
$contpos = strpos(strtoupper($buf), "CONTENT-TYPE");
if ($contpos > 0) {
// echo("FOUND contenttype in ::$buf::<br>\n");
$buf = substr($buf, $contpos, strlen($buf) - $contpos);
// echo("new buffer::$buf::<br>\n");
// $buf = substr($buf, strpos($buf, "\n") + 1, strlen($buf) - strpos($buf, "\n"));
$buf = substr($buf, 27, strlen($buf) - (27 + 1)); // assumes Content-Type: text/html (27 chars)
} else {
if ($debug == 1) {
echo("NO contenttype found in ::$buf::<br>\n");
}
return "ERROR";
}
// delete everything else than the content from the buffer
// $buf = substr($buf, (strlen($buf) - $contentsize), $contentsize - 1);
// echo("buffer::$buf::<br>\n");
// echo("after response\n");
fclose($fp);
return $buf; // return the buffer
}
} // sendToHost
//
// compose the XML-message ans transfer it to sendToHost
function sendXML($destination, $origin, $middle)
{
global $truesenses_account;
global $truesenses_password;
$poststring = "<?xml version=\"1.0\"?>\n";
$poststring .= "<Message>\n";
$poststring .= "<Destination>\n";
$poststring .= "<GSM number=\"$destination\" />\n";
$poststring .= "</Destination>\n";
$poststring .= "<ORIGINATOR value=\"$origin\" />\n";
$poststring .= $middle; // insert middle part here
$poststring .= "</Message>\n";
$sendresp = sendToHost('www.truesenses.com','get','/cgi-bin/smsgateway.cgi', "FUNCTION=EXTERN_XMLUPLOAD&ACCOUNT=$truesenses_account&PASSWORD=$truesenses_password", "", "$poststring");
return $sendresp; // return response
} // sendXML
// MAIN program
// Look if incoming message contains a space (keyword detected)
//
// Incoming message will contain the full message (no keyword required) if you
// are hosting a dedicated access number on TrueSenses
//
$pos = strpos ($MESSAGE, " ");
if ($pos === false) { // no space in message detected, keyword is message
$KEYWORD = "$MESSAGE";
$MSGONLY = "$MESSAGE";
} else { // space detected, extract keyword
$KEYWORD = substr($MESSAGE, 0, $pos);
$MSGONLY = substr($MESSAGE, ($pos + 1), (strlen($MESSAGE) - ($pos)));
}
if ($debug == 1) {
echo("Keyword::$KEYWORD:: Msgonly::$MSGONLY:: Fullmessage::$MESSAGE::<br>\n");
}
if (strcmp(strtoupper($MSGONLY), "SMS") == 0) {
// sends a normal SMS
$xmlmsg = "<SMS encoded=\"YES\">\n";
// add the following line if you want to send long-SMS (spawning over multiple SMS)
// $xmlmsg .= "<long />\n";
$xmlmsg .= "<CONTENT>";
$xmlmsg .= urlencode("Your keyword was $KEYWORD and your message was $MSGONLY"); // hex-encode the content
$xmlmsg .= "</CONTENT>\n";
$xmlmsg .= "</SMS>\n";
$rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);
if ($debug == 1) {
echo("RESPONSE::$rcbuf::\n");
}
} // SMS reply
if (strcmp(strtoupper($MSGONLY), "SMSFLASH") == 0) {
// sends a flasing SMS
$xmlmsg = "<SMS encoded=\"YES\">\n";
$xmlmsg .= "<flashing />\n"; // set msgclass 0 flag
// add the following line if you want to send long-SMS (spawning over multiple SMS)
// $xmlmsg .= "<long />\n";
$xmlmsg .= "<CONTENT>";
$xmlmsg .= urlencode("Your keyword was $KEYWORD and your message was $MSGONLY"); // hex-encode the content
$xmlmsg .= "</CONTENT>\n";
$xmlmsg .= "</SMS>\n";
$rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);
if ($debug == 1) {
echo("RESPONSE::$rcbuf::\n");
}
} // SMS reply
if (strcmp(strtoupper($MSGONLY), "NOKIARINGTONE") == 0) {
// sends a nokiaringtone - input must be in RTTTL format
//
// assemble XML message
$http_location = "http://www.simmcomm.ch/ringtone.txt"; // location of the ringtone
$xmlmsg = "<NOKIARINGTONE>\n";
$xmlmsg .= "<RINGTONE source=\"HTTP\" type=\"RTTTL\">$http_location</RINGTONE>\n";
$xmlmsg .= "</NOKIARINGTONE>\n";
$rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);
if ($debug == 1) {
echo("RESPONSE::$rcbuf::\n");
}
} // NOKIARINGTONE
if (strcmp(strtoupper($MSGONLY), "NOKIARINGTONEHEX") == 0) {
// sends a nokiaringtone as hex include - input must be in RTTTL format
//
// assemble XML message
$http_location = urlencode("KnightRider:d=4,o=5,b=125:16e,16p,16f,16e,16e,16p,16e,16e,16f,16e,16e,16e,16d#,16e,16e,16e,16e,16p,16f,16e,16e,16p,16f,16e,16f,16e,16e,16e,16d#,16e,16e,16e,16d,16p,16e,16d,16d,16p,16e,16d,16e,16d,16d,16d,16c,16d,16d,16d,16d,16p,16e,16d,16d,16p,16e,16d,16e,16d,16d,16d,16c,16d,16d,16d"); // free demo ringtone from the internet
$xmlmsg = "<NOKIARINGTONE>\n";
$xmlmsg .= "<RINGTONE source=\"BINARY\" type=\"RTTTL\">$http_location</RINGTONE>\n";
$xmlmsg .= "</NOKIARINGTONE>\n";
$rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);
if ($debug == 1) {
echo("RESPONSE::$rcbuf::\n");
}
} // NOKIARINGTONEHEX
if (strcmp(strtoupper($MSGONLY), "NOKIALOGO") == 0) {
// sends a nokialogo - input must be in GIF, JPG or PNG
//
// parameters:
// mcc = MobileCountryCode for destination (example 228 - switzerland)
// mnc = MobileNetworkCode for destination (example 01 - swisscom, 02 sunrise, 03 orange)
// assemble XML message
$http_type = "GIF";
$http_location = "http://www.simmcomm.ch/nokialogo.gif"; // location of the logo
$destination_mcc = "228"; // mandatory: MobileCountryCode for destination
$destination_mnc = "01"; // mandatory: MobileNetworkCode for destination
$xmlmsg = "<NOKIALOGO mcc=\"$destination_mcc\" mnc=\"$destination_mnc\">\n";
$xmlmsg .= "<IMAGE source=\"HTTP\" type=\"$http_type\">$http_location</IMAGE>\n";
$xmlmsg .= "</NOKIALOGO>\n";
$rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);
if ($debug == 1) {
echo("RESPONSE::$rcbuf::\n");
}
} // NOKIALOGO
if (strcmp(strtoupper($MSGONLY), "NOKIAMULTIPART") == 0) {
// sends a nokiamultipart message (picturemessage) - input must be in GIF, JPG or PNG
//
// options:
// - specify <CONTENT> tag if you want to send some text with your image
// assemble XML message
$http_type = "GIF";
$http_location = "http://www.simmcomm.ch/nokialogo.gif"; // location of the logo
$xmlmsg = "<NOKIAMULTIPART encoded=\"YES\">\n";
$xmlmsg .= "<IMAGE source=\"HTTP\" type=\"$http_type\">$http_location</IMAGE>\n";
$xmlmsg .= "<CONTENT>";
$xmlmsg .= urlencode("Your logo"); // hex-encode the content
$xmlmsg .="</CONTENT>\n";
$xmlmsg .= "</NOKIAMULTIPART>\n";
$rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);
if ($debug == 1) {
echo("RESPONSE::$rcbuf::\n");
}
} // NOKIAMULTIPART
if (strcmp(strtoupper($MSGONLY), "EMSLOGO") == 0) {
// sends a logo to NON-nokia, EMS-capable phones like SonyEricsson
//
// parameters:
// autosave = YES/NO (automatically ask user to save image)
// protected = YES/NO (disallow re-distribution of image)
// width = x (width of image, do not provide parameter for autosizing)
// height = y (height of image, do not provide parameter for autosizing)
// assemble XML message
$http_type = "GIF";
$http_location = "http://www.simmcomm.ch/nokialogo.gif"; // location of the logo
$xmlmsg = "<EMS>\n";
// no newline after <content> tag as it would convert to text-enter %0A in ems and would consume space
$xmlmsg .= "<CONTENT><IMAGE source=\"HTTP\" type=\"$http_type\" autosave=\"YES\" protected=\"NO\">$http_location</IMAGE></CONTENT>\n";
$xmlmsg .= "</EMS>\n";
$rcbuf = sendXML($NUMBER, $truesenses_origin, $xmlmsg);
if ($debug == 1) {
echo("RESPONSE::$rcbuf::\n");
}
} // EMSLOGO
// send confirmation to TrueSenses.com that we have received the incoming sms
echo("OK<br>\n");
?>
</body>
</html>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
<a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts. FREE! Go There Now!
|
|
|
|
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
|
|
|
|
Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |