Authorization failed при использовании API для отправки СМС
Добавлено: 26 дек 2012, 22:42
function BuildUrlParamsWithSignature($params, $password)
{
ksort($params);
$url = '';
if (!is_array($params))
return $url;
foreach($params as $key => $value)
{
$url .= $key . "=" . urlencode($value) . "&";
}
$signature = md5($url . "&password=".urlencode($password));
$url .= "signature=" . $signature;
return $url;
}
$link = "http://api.comtube.ru/scripts/api/sms.php";
$params = array
(
'action' => 'send',
'charset' => 'utf-8',
'message' => $text,
'number' => $number,
'report_to' => 'asdf@yandex.ru',
'senderid' => $number2,
'type' => 'json',
'username' => $login,
);
$params['signature'] = BuildUrlParamsWithSignature($params, $pass);
$url = $link.'?';
$params_url = array();
foreach ($params as $key => $value)
{
$params_url[] = $key.'='.$value;
}
$url .= implode("&", $params_url);
//print $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
{
ksort($params);
$url = '';
if (!is_array($params))
return $url;
foreach($params as $key => $value)
{
$url .= $key . "=" . urlencode($value) . "&";
}
$signature = md5($url . "&password=".urlencode($password));
$url .= "signature=" . $signature;
return $url;
}
$link = "http://api.comtube.ru/scripts/api/sms.php";
$params = array
(
'action' => 'send',
'charset' => 'utf-8',
'message' => $text,
'number' => $number,
'report_to' => 'asdf@yandex.ru',
'senderid' => $number2,
'type' => 'json',
'username' => $login,
);
$params['signature'] = BuildUrlParamsWithSignature($params, $pass);
$url = $link.'?';
$params_url = array();
foreach ($params as $key => $value)
{
$params_url[] = $key.'='.$value;
}
$url .= implode("&", $params_url);
//print $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);