<?php
function getHMACsms(){
$key = 'тут закрытый ключ';
$return = array();
date_default_timezone_set('UTC');
$timestamp = calc_timestamp();
$code = rand(1000,9999);
$phone = str_replace(array('(',')','-','+'),array('','','',''), $_POST['calc-phone']);
$mac_data = tomacdata($_POST['calc-surname']).
tomacdata($_POST['calc-name']).
tomacdata($_POST['calc-lastname']).
tomacdata($phone).
tomacdata($timestamp).
tomacdata($code);
$return['HMAC'] = hash_hmac("sha1",$mac_data,hex2bin($key));
$return['TIMESTAMP'] = $timestamp;
$ch = curl_init("https://sms.ru/sms/send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
"api_id" => "тут ключ апи sms.ru",
"to" => $phone,
"text" => "Код согласия с условиями и обязательствами " . $code . ". сайт.рф"
));
$body = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$json["body"] = $body;
if($httpcode == 200 && $body == 100){
return $return;
}else{
return false;
}
}
function tomacdata($oFld)
{
$str="";
if ($oFld == "") {
$str = "-";
} else {
$str = strlen($oFld).$oFld;
}
return $str;
}
function calc_timestamp() {
return date("YmdHis");
}