Skip to content

Instantly share code, notes, and snippets.

@glebus
Last active December 17, 2015 19:38
Show Gist options
  • Save glebus/5661426 to your computer and use it in GitHub Desktop.
Save glebus/5661426 to your computer and use it in GitHub Desktop.
<?php
// Application credentials
DEFINE('APPLICATION_ID', 0); // Set your application ID (integer)
DEFINE('AUTH_KEY', ""); // Set your auth key (string)
DEFINE('AUTH_SECRET', ""); // Set your auth secret (string)
// User credentials
DEFINE('USER_LOGIN', ""); // Set your user login (string)
DEFINE('USER_PASSWORD', ""); // Set your user password (string)
// Quickblox endpoints
DEFINE('QB_API_ENDPOINT', "https://api.quickblox.com");
DEFINE('QB_PATH_SESSION', "session.json");
// Generate signature
$nonce = rand();
$timestamp = time();
$signature_string = "application_id=" . APPLICATION_ID . "&auth_key=" . AUTH_KEY . "&nonce=" . $nonce . "&timestamp=" . $timestamp . "&user[login]=" . USER_LOGIN . "&user[password]=" . USER_PASSWORD;
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// echo $signature_string . "\n";
// Build post body
$post_body = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature,
'user[login]' => USER_LOGIN,
'user[password]' => USER_PASSWORD
));
// echo $post_body . "\n";
// Configure cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT . '/' . QB_PATH_SESSION); // Full path is - https://api.quickblox.com/session.json
curl_setopt($curl, CURLOPT_POST, true); // Use POST
curl_setopt($curl, CURLOPT_HTTPHEADER, array('QuickBlox-REST-API-Version: 0.1.0')); // Setup HTTP header
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
// Execute request and read responce
$responce = curl_exec($curl);
// Check errors
if ($responce) {
echo $responce . "\n";
} else {
$error = curl_error($curl). '(' .curl_errno($curl). ')';
echo $error . "\n";
}
// Close connection
curl_close($curl);
?>
@glebus
Copy link
Author

glebus commented May 28, 2013

$ php5 quickblox_session.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment