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! |
This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process. FREE! Go There Now!
|
|
|
|
Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools. FREE! Go There Now!
|
|
|
|
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. 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!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
|
|
|
|
In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |