Created
August 19, 2013 02:59
-
-
Save braddown/6265456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* SMS Forwarder | |
* | |
* Sends the message received to a provided number using the sender's number as the caller ID | |
* | |
* URL example | |
* "http://burstsms.com/plugins/forward.php?apikey=YOUR-API-KEY&apisecret=YOUR-API-SECRET&to=MOBILE-NUMBER" | |
*/ | |
date_default_timezone_set('UTC'); | |
// Environment specific variables | |
if (($_SERVER['HTTP_HOST'] == 'main.burst')) { //dev | |
$baseUrl = 'http://main.burst/api-wrapper'; | |
} else { // prod | |
$baseUrl = 'http://burstsms.com/api-wrapper'; | |
} | |
// Params | |
$msisdn = ltrim(@$_GET['to'], '+'); | |
$apiKey = @$_GET['apikey']; | |
$apiSecret = @$_GET['apisecret']; | |
// Check mobile number | |
if (!$msisdn || !ctype_digit($msisdn)) { | |
die('No to param'); | |
} | |
// Check API key looks sane | |
if (!$apiKey) { | |
die('No apikey param'); | |
} | |
// Check API secret looks sane | |
if (!$apiSecret) { | |
die('No apisecret param'); | |
} | |
// Forward message | |
if (trim($_GET['response']) !== '') { | |
echo "Sending to {$msisdn}: {$_GET['response']}"; | |
$queryStr = http_build_query(array( | |
'apikey' => $apiKey, | |
'apisecret' => $apiSecret, | |
'mobile' => $msisdn, | |
'message' => $_GET['response'], | |
'caller_id' => $_GET['mobile'] | |
)); | |
$sendMessageUrl = "{$baseUrl}/messages.single?{$queryStr}"; | |
$response = file_get_contents($sendMessageUrl); | |
// $responseXml = @simplexml_load_string($response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment