Zeep Mobile - Cool SMS gateway, that's free! Recently I had to build a web app that utilized SMS messages to cell phones .. The client was on a shoestring budget and needed an a gateway that wasn't going to cost anything to get up and running. Luckily, he found ZeepMobile.
It's a really cool system, and simple API if you understand how to use cURL in PHP. Setup is a snap .. You enter a unique name for your app, which is used for mobile users to send messages to your server end point, and then you get your API key and secret code. Oh, you also setup your mobile urls for sending and receiving messages .. This is for security, so Zeep verifies that the messages are from the right server etc.
In order for a user to receive messages from your app, they have to register their phone number through the zeep panel, which is very streamlined and no hassle. (one less data transaction to build)
Here's a code snippet to send a message using the Zeep API:
// ADD TO YOUR CONFIG FILE
define('ZEEPSECRECTKEY', 'yoursecret');
define('ZEEPAPIKEY', 'yourapikey');
define('ZEEP_ENDPOINT', 'https://api.zeepmobile.com/messaging/2008-07-14/send_message');// SEND MESSAGE ZEEP API CODE
// LETS SAY YOU GET THE MSG FROM A POST FIELD
$messageText = strip_tags(trim($_POST['messageText']));
$httpDate = gmdate('D, d M Y H:i:s \G\M\T');
$postData = 'user_id=' . $yourUsersUniqueID . '&body=' . urlencode($messageTextEncoded);
$canonicalString = ZEEPAPIKEY . $httpDate . $postData;
$hashSig = base64_encode(hash_hmac('sha1', $canonicalString, ZEEPSECRECTKEY, TRUE));
$headers = array();
$headers[] = "Authorization: Zeep " . ZEEPAPIKEY . ":" . $hashSig;
$headers[] = "Date: $httpDate";$c = curl_init(ZEEP_ENDPOINT);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
curl_setopt($c, CURLOPT_POSTFIELDS, $postData);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($c);
curl_close($c);if($result == 'OK') {
// SUCCESS!
} else {
// FAILED - ECHO TO SEE ERROR
}
Pretty simple indeed .. Now let's say you want to receive a message from a mobile user...
$event = trim($_POST['event']);
switch ($event) {
case 'SUBSCRIPTION_UPDATE':
$userId = intval($_POST['uid']);
$phoneNumber = mysql_escape_string(trim($_POST['min']));// DO SOMETHING
break;
case 'MO':
$userId = intval($_POST['uid']);
$msg = mysql_escape_string(trim($_POST['body']));// DO SOMETHING
break;
}
This is very simple, too .. Zeep POSTS data to your 'mobile in' URL that you specify in your settings panel.
The first type of message is SUBSCRIPTION_UPDATE. Zeep sends this message out to let you know that a user has officially activated a phone number for use with your app. I'd recommend storing the phone number in a db for later reference. The second type of message is MO, which stands for 'mobile originated' .. And you guessed it, it's a message. It simply contains the users ID and the message.
Hopefully you can see that the Zeep api is simple to use. A coder can build pretty awesome 'web to SMS to web' apps fast with Zeep. If you've built an app using Zeep, post a comment with a link!
Teft
The PHP snippets are under the MIT license .. You are free to use and modify the code anywhere you'd like!
2 Responses for "Zeep Mobile is Cool! And some PHP snippets :)"
Hey, thanks for the writeup Teft! Can we use your code snippets on our site?
Yeah absolutely! Just give me a link back
Leave a reply