PHP Example

4 views
Skip to first unread message

luke.pa...@gmail.com

unread,
Nov 5, 2008, 4:51:24 PM11/5/08
to Zeep Mobile
Here's the PHP code that Brian Hendrickson used to integrate Zeep
Mobile with http://openmicroblogger.
Give it a go and see if you guys can get it working for yourselves.
Thanks Brian!

# Created by Brian Hendrickson (br...@openmicroblogger.com) on
2008-09-22
# Copyright (c) 2008. All rights reserved.
# Released under MIT License

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_KEY' );

# (ex. Sat, 12 Jul 2008 09:04:28 GMT)
$http_date = gmdate( DATE_RFC822 );

$parameters = "usr_id=1234&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);

Damjan

unread,
Nov 30, 2008, 6:41:50 PM11/30/08
to Zeep Mobile
This snippet works. But you have to fix the typo in the $parameters
variable. Instead of usr_id=1234& you should use user_id=1234&

Best,
Damjan

On Nov 5, 10:51 pm, "l...@zeepmobile.com" <luke.pachol...@gmail.com>
wrote:
> Here's the PHP code that Brian Hendrickson used to integrate Zeep
> Mobile withhttp://openmicroblogger.

luke.pa...@gmail.com

unread,
Dec 4, 2008, 4:23:52 PM12/4/08
to Zeep Mobile
Great, thanks Damjan.
I'll fix it and post it to our site.
Reply all
Reply to author
Forward
0 new messages