47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
define("API_KEY", "e2b95293d1b8a09a39dfd9f9010d9e93"); // ключ API
|
||
|
|
define("API_URL", "https://voice.mobilgroup.ru/api/voice-password/send/"); // ключ API
|
||
|
|
|
||
|
|
define("SECRET_STR_FOR_SMS","okimsiofj9892384928jce9_!<?kdfc9999");
|
||
|
|
|
||
|
|
function ok_code($s) {
|
||
|
|
$code = hexdec(substr(md5($s.SECRET_STR_FOR_SMS.mt_rand(1000,9999)), 7, 5));
|
||
|
|
if (strlen($code) > 4) {
|
||
|
|
return substr($code, 0, 4);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $code;
|
||
|
|
}
|
||
|
|
|
||
|
|
function sendCode($phone, $code) {
|
||
|
|
$data = '{"number":"' . $phone . '","voice": { "code": "' . $code . '" }}';
|
||
|
|
|
||
|
|
$ch = curl_init();
|
||
|
|
curl_setopt($ch, CURLOPT_URL, API_URL);
|
||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||
|
|
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
||
|
|
curl_setopt($ch, CURLOPT_POST, TRUE);
|
||
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||
|
|
"Content-Type: application/json",
|
||
|
|
"Authorization: " .API_KEY
|
||
|
|
));
|
||
|
|
|
||
|
|
$outData = curl_exec($ch);
|
||
|
|
curl_close($ch);
|
||
|
|
|
||
|
|
$jsonResult = json_decode($outData, true);
|
||
|
|
|
||
|
|
$res = array();
|
||
|
|
$res[0] = $outData;
|
||
|
|
|
||
|
|
if ($jsonResult['result'] == "ok") {
|
||
|
|
$res[1] = 1;
|
||
|
|
} else {
|
||
|
|
$res[1] = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $res;
|
||
|
|
}
|