hedera-web/rest/misc/sms.php

46 lines
979 B
PHP

<?php
use Vn\Lib;
class Sms extends Vn\Web\JsonRequest
{
const PARAMS = [
'to'
,'text'
];
function run ($db)
{
$smsConfig = $db->getObject ('SELECT uri, user, password, title FROM sms_config');
$sClient = new SoapClient ($smsConfig->uri);
$xmlString = $sClient->sendSMS (
$smsConfig->user
,$smsConfig->password
,$smsConfig->title
,$_REQUEST['to']
,$_REQUEST['text']
);
$xmlResponse = new SimpleXMLElement ($xmlString);
$res = $xmlResponse->sms;
$db->query (
'INSERT INTO vn2008.sms (Id_trabajador, `text`, `to`, `from`, sent, response, Id_Cliente)
VALUES (account.userGetId(), #, #, #, #, #, #)',
[
$_REQUEST['text']
,$_REQUEST['to']
,$_REQUEST['to']
,$res->codigo
,$res->descripcion
,empty ($_REQUEST['customer']) ? NULL : $_REQUEST['customer']
]
);
if ($sms->codigo != 0)
throw new Lib\UserException ($res->descripcion);
return TRUE;
}
}