2020-06-07 19:04:43 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Util;
|
|
|
|
|
|
|
|
class Sms
|
|
|
|
{
|
2021-01-07 19:25:09 +03:00
|
|
|
static function send(string $to, string $message): bool
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
2021-01-07 19:25:09 +03:00
|
|
|
$conf = (object) OPENVK_ROOT_CONF["openvk"]["credentials"]["smsc"];
|
|
|
|
if(!$conf->enable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$args = http_build_query([
|
|
|
|
"login" => $conf->client,
|
|
|
|
"psw" => $conf->secret,
|
|
|
|
"phones" => $to,
|
|
|
|
"mes" => $message,
|
|
|
|
"flash" => 1,
|
|
|
|
"translit" => 2,
|
|
|
|
"fmt" => 2,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response = file_get_contents("https://smsc.ru/sys/send.php?$args");
|
|
|
|
if(!$response)
|
|
|
|
return false;
|
2020-06-07 19:04:43 +03:00
|
|
|
|
2021-01-07 19:25:09 +03:00
|
|
|
$response = new \SimpleXMLElement($response);
|
|
|
|
if(isset($response->error_code)) {
|
|
|
|
trigger_error("Could not send SMS to $to: $response->error (Exception $response->error_code)", E_USER_WARNING);
|
2020-06-07 19:04:43 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|