mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
Change SMS provider
Co-authored-by: Celestine <34442450+rem-pai@users.noreply.github.com>
This commit is contained in:
parent
aed731a59f
commit
92c9320eae
2 changed files with 23 additions and 11 deletions
|
@ -1,18 +1,31 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Util;
|
namespace openvk\Web\Util;
|
||||||
use Zadarma_API\{Api as ZApi, ApiException as ZException};
|
|
||||||
|
|
||||||
class Sms
|
class Sms
|
||||||
{
|
{
|
||||||
function send(string $to, string $message): bool
|
static function send(string $to, string $message): bool
|
||||||
{
|
{
|
||||||
$conf = (object) OPENVK_ROOT_CONF["openvk"]["credentials"]["zadarma"];
|
$conf = (object) OPENVK_ROOT_CONF["openvk"]["credentials"]["smsc"];
|
||||||
if(!$conf->enable) return false;
|
if(!$conf->enable)
|
||||||
|
return false;
|
||||||
|
|
||||||
try {
|
$args = http_build_query([
|
||||||
$api = new ZApi($conf->key, $conf->secret, false);
|
"login" => $conf->client,
|
||||||
$res = $api->sendSms($to, $message, $conf->callerId);
|
"psw" => $conf->secret,
|
||||||
} catch(ZException $e) {
|
"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;
|
||||||
|
|
||||||
|
$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);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,9 @@ openvk:
|
||||||
fartscroll: false
|
fartscroll: false
|
||||||
testLabel: false
|
testLabel: false
|
||||||
credentials:
|
credentials:
|
||||||
zadarma:
|
smsc:
|
||||||
enable: false
|
enable: false
|
||||||
callerId: ""
|
client: ""
|
||||||
key: ""
|
|
||||||
secret: ""
|
secret: ""
|
||||||
eventDB:
|
eventDB:
|
||||||
enable: false # Better enable this
|
enable: false # Better enable this
|
||||||
|
|
Loading…
Reference in a new issue