Created
August 31, 2011 05:53
-
-
Save fetus-hina/1182904 to your computer and use it in GitHub Desktop.
Ameba blog X-WSSE
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 | |
date_default_timezone_set('Asia/Tokyo'); | |
require_once('Zend/Http/Client.php'); | |
define('AMEBA_URL', 'http://atomblog.ameba.jp/servlet/_atom/blog'); | |
request('USERNAME', 'PASSWORD'); | |
function request($user_name, $password) { | |
$client = new Zend_Http_Client(); | |
$client->setUri(AMEBA_URL); | |
$client->setHeaders('X-WSSE', createWsse($user_name, $password)); | |
$resp = $client->request(Zend_Http_Client::GET); | |
if(!$resp->isSuccessful()) { | |
echo "Failed...\n"; | |
echo "<request> -----\n"; | |
echo $client->getLastRequest() . "\n"; | |
echo "<response> ----\n"; | |
echo $resp->asString("\n") . "\n"; | |
echo "---------------\n"; | |
return false; | |
} | |
echo "OK!\n"; | |
echo "<response> ----\n"; | |
echo $resp->asString("\n") . "\n"; | |
echo "---------------\n"; | |
return true; | |
} | |
function createWsse($user_name, $password) { | |
$nonce = bin2hex(file_get_contents('/dev/urandom', false, null, 0, 20)); | |
$created = gmdate('Y-m-d\TH:i:s\Z', time()); | |
$digest = hash('sha1', $nonce . $created . hash('md5', $password), true); | |
$wsse = | |
sprintf( | |
'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', | |
$user_name, | |
base64_encode($digest), | |
base64_encode($nonce), | |
$created); | |
return $wsse; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment