function arInStr($array)
{
ksort($array);
$string = "";
foreach ($array as $key => $val)
{
if (is_array($val))
{
$string .= $key . "=" . arInStr($val);
}
else
{
$string .= $key . "=" . $val;
}
}
return $string;
}
function postUrl($url, $type = "GET", $params = array(), $timeout = 15, $image = false, $decode = true)
{
if ($ch = curl_init())
{
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
if ($type == "POST")
{
curl_setopt($ch, CURLOPT_POST, true);
if ($image)
{
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
elseif ($decode)
{
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
else
{
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
curl_close($ch);
// Еще разок, если API завис
if (isset($data['error_code']) && $data['error_code'] == 5000)
{
$data = getUrl($url, $type, $params, $timeout, $image, $decode);
}
return $data;
}
else
{
return "{}";
}
}
function getOk($access_token,
$application_secret_key,
$params,
$timeout = 15,
$image = false,
$decode = true,
$siG = true,
$url = 'https://api.ok.ru/fb.do')
{
if ($siG != false)
{
$sig = md5(arInStr($params) . md5("{$access_token}{$application_secret_key}"));
$params["sig"] = $sig;
$params["access_token"] = $access_token;
$result = json_decode(postUrl("https://api.ok.ru/fb.do", "POST", $params, $timeout, $image, $decode), true);
}
else
{
$result = json_decode(postUrl($url, "POST", $params, $timeout, $image, $decode), true);
}
return $result;
}
$params = array(
"application_key" => $application_key,
"application_id" => $application_id,
"application_secret_key" => $secret_session_key,
"format" => "json",
"uid" => $groupId,
"method" => "group.getMembers",
);
$res = getOk($access_token, $application_secret_key, $params, 15, false);