"Ongeldig telefoonnummer.", "45002" => "Ongeldig bericht.", "45003" => "Ongeldige shortcode.", "45004" => "Ongeldig mo_messageid.", "45005" => "Het mo record is niet gevonden.", "45006" => "Ongeldig tarief.", "45007" => "Ongeldige gebruikersnaam in combinatie met shortkey.", "45013" => "Tarief is hoger dan ingestelde prijs.", "45019" => "Onbekende member.", "45020" => "Het maximum aantal berichten is bereikt.", "45022" => "Ongeldige URL (push url).", "45023" => "Wapomschrijving te lang.", "45024" => "URL te lang (van het pushbericht).", "45030" => "Het veld handle is leeg.", "45031" => "Ongeldige handle.", "002 jobid missing" => "Ongeldig jobid nummer", "003 shortcode missing"=> "Ongeldige shortcode", "004 shortkey missing"=> "Keyword ontbreekt", "005 message missing"=> "Bericht ontbreekt", "006 message too long"=> "Bericht te lang", "007 invalid task"=> "Verkeerde taak", "020 invalid combination of shortcode ,shortkey, username"=> "Verkeerde combinatie van shortcode, shortkey en username", "021 username missing"=> "usernaam ontbreekt", "023 handle missing"=> "Handle ontbreekt", "024 invalid handle"=> "Verkeerde handle", "030 maximum number of jobs reached for today"=> "Het maximaal aantl jobs is bereikt", "050 no records found"=> "Geen records gevonden", ); /* Function to call when an unexpected response is received from TargetSMS Uncomment one of the lines or write your own error logging */ function errorlog ($dataToSend, $response) { $message = false; foreach ($_REQUEST as $k=>$v) { $message .= "[MO] $k=$v\n"; } foreach ($dataToSend as $k=>$v) { $message .= "[MT] $k=$v\n"; } $message .= "\nError $response: ".$this->errors[$response]; if ($this->notify) { mail ($this->notify, "SMS Handler for ".$_REQUEST["MO_ShortKey"], $message); } } /* This function removes all characters that aren't supported by SMS messages from a string. */ function tidy ($input) { return preg_replace("/[^a-z \d\+\%\#\(\)\*\+\,\.\-\/\:\;\<\=\>\?\_£¥§ÄÅÜäèéìñòöùü\]]/i", "", $input); } /* Call this function to send a subscription MT --- NOTE: You have to use MTNonSubscription() for answering incoming --- ON, OFF or OK messages, as they are send WITH an MO message ID. Subscription MT's can only be sent to active members of a subscription SMS service No MO message ID is needed, as these can be initiated without a MO message. Please note that you can send only the maximum number of messages you entered when you created the keyword. If you send more, an error 45005 will be returned. $tariff: tariff to use in cents $text: text to send $keyword: keyword of the service (when left empty, $_REQUEST["MO_ShortKey"] will be used) $shortcode: shortcode of the service (when left empty, $_REQUEST["ShortCode"] will be used) $phonenumber: recipient phone number (when left empty, $_REQUEST["SendTo"] will be used) */ function MTSubscription ($tariff, $text, $keyword=false, $shortcode=false, $phonenumber=false) { $text = $this->tidy ($text); if (!$keyword) { $keyword = $_REQUEST["MO_ShortKey"]; } if (!$shortcode) { $shortcode = $_REQUEST["ShortCode"]; } if (!$phonenumber) { $phonenumber = $_REQUEST["SendTo"]; } $dataToSend = array( "username" => TSMS_USER, "handle" => TSMS_HANDLE, "shortkey" => $keyword, "shortcode" => $shortcode, "sendto" => $phonenumber, "mtype" => 2, "message" => $text, "tariff" => $tariff ); $post = new httpRequest ("http://api.targetsms.nl/ps_handler/sendmessagev2.asp", $dataToSend); if( substr($post->response,0,5) =="45000") { return true; } else { $this->errorlog ($dataToSend, $post->response); return true; } } /* Call this function to send a non-subscription MT Non-subscription MT messages can only be sent when initiated by a MO message. Hence, the MO message ID is mandatory. Please note that you can send only the maximum number of messages you entered when you created the keyword. If you send more, an error 45005 will be returned. $tariff: tariff to use in cents $text: text to send Note that shortcode, keyword and phonenumber can't be specified. This function is only useful in an MO handler, which means that all details are already in $_REQUEST */ function MTNonSubscription ($tariff, $text) { global $tm_username, $tm_handle; $text = $this->tidy ($text); $dataToSend = array( "username" => $tm_username, "handle" => $tm_handle, "shortkey" => $_REQUEST["MO_ShortKey"], "shortcode" => $_REQUEST["ShortCode"], "sendto" => $_REQUEST["SendTo"], "mo_messageid" => $_REQUEST["MO_MessageId"], "message" => $text, "tariff" => $tariff, "mtype" => $_REQUEST['mtype'] ); $post = new httpRequest ("http://api.targetsms.nl/ps_handler/sendmessagev2.asp", $dataToSend); if ( substr($post->response,0,5) =="45000") { return true; } else { $this->errorlog ($dataToSend, $post->response ); return true; } } /* Call this function to send a job to all members. If no SendTime is submitted, the message will be send right away */ function JOBSubscription ($text) { global $tm_username, $tm_handle; $text = $this->tidy ($text); if(!$_REQUEST['SendTime']){ $_REQUEST['SendTime'] = date("Y-m-d H:i:s"); } list($date,$time) = explode(" ",$_REQUEST['SendTime']); list($year,$month,$day) = explode("-",$date); list($hour,$minute,$seconde) = explode(":",$time); $dataToSend = array( "username" => $tm_username, "handle" => $tm_handle, "shortkey" => $_REQUEST["MO_ShortKey"], "shortcode" => $_REQUEST["ShortCode"], "year" => $year, "month" => $month, "day" => $day, "hour" => $hour, "min" => $minute, "message" => $text ); var_dump($dataToSend); $post = new httpRequest ("http://api.targetsms.nl/ps_handler/tools/newvalidatejobs.asp", $dataToSend); if ($post->response=="000 OK") { return true; } else { $this->errorlog ($dataToSend, $post->response); return true; } } /* IP check: checks if your script is called by TargetSMS */ function ipcheck() { if (($_SERVER["REMOTE_ADDR"]!="195.140.234.120") && (substr($_SERVER["REMOTE_ADDR"],0,11)!="89.184.168.")) { die ("Access denied for ".$_SERVER["REMOTE_ADDR"]); } } /* Destructor */ function bye() { echo "45000"; die(); } /* Constructor */ function TargetSMS ($username, $handle, $notify=false) { $this->username = $username; $this->handle = $handle; $this->notify = $notify; } } ?>