Skip to content

Instantly share code, notes, and snippets.

@flukeout
Created November 19, 2009 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save flukeout/239102 to your computer and use it in GitHub Desktop.
Save flukeout/239102 to your computer and use it in GitHub Desktop.
Zeep Mobile - Sending a message - PHP
<?php
//To be safe I added this
header("Content-type: text/plain");
define( API_URL, 'https://api.zeepmobile.com/messaging/2008-07-14/
send_message' );
define( API_KEY, 'YOUR-API-KEY' );
define( SECRET_ACCESS_KEY, 'YOUR_SECRET_ACCESS_KEY' );
# (ex. Sat, 12 Jul 2008 09:04:28 GMT)
$http_date = gmdate( DATE_RFC822 );
$parameters = "user_id=12345&body=".urlencode('Art thou not Romeo, and
a Montague?');
# => "user_id=1234&body=Art+thou+not+Romeo%2C+and+a+Montague%3F"
$canonical_string = API_KEY . $http_date . $parameters;
# => "YOUR_API_KEYSat, 12 Jul 2008 09:04:55 GMTuser_id=1234&body=Art+thou+not+Romeo%2C+and+a+Montague%3F"
$b64_mac = base64_encode(hash_hmac("sha1", $canonical_string, SECRET_ACCESS_KEY, TRUE));
$authentication = "Zeep " . API_KEY . ":$b64_mac";
$header = array(
"Authorization: ".$authentication,
"Date: ".$http_date,
"Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strval(strlen($parameters))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_URL );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters );
$response = curl_exec($ch);
curl_close($ch);
//Here is the PHP code to spit out the data I want based on the
parameters passed through the SMS
if ($_POST['event'] == 'SUBSCRIPTION_UPDATE') {
echo 'Welcome to my app.';
} elseif ($_POST['event'] == 'MO') {
if ($_POST['body'] == 'hello') {
echo 'Fine and you?';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment