hedera-web/rest/misc/sms.php

46 lines
979 B
PHP
Raw Normal View History

<?php
use Vn\Lib;
class Sms extends Vn\Web\JsonRequest
{
2016-09-06 14:25:02 +00:00
const PARAMS = [
'to'
,'text'
];
2016-09-06 14:25:02 +00:00
function run ($db)
{
2017-12-13 18:28:54 +00:00
$smsConfig = $db->getObject ('SELECT uri, user, password, title FROM sms_config');
2017-12-13 18:28:54 +00:00
$sClient = new SoapClient ($smsConfig->uri);
$xmlString = $sClient->sendSMS (
2017-12-13 18:28:54 +00:00
$smsConfig->user
,$smsConfig->password
,$smsConfig->title
2016-09-06 14:25:02 +00:00
,$_REQUEST['to']
,$_REQUEST['text']
);
$xmlResponse = new SimpleXMLElement ($xmlString);
2017-12-13 18:28:54 +00:00
$res = $xmlResponse->sms;
2017-12-13 18:28:54 +00:00
$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']
]
);
2017-12-13 18:46:54 +00:00
if ($res->codigo != 0)
2017-12-13 18:28:54 +00:00
throw new Lib\UserException ($res->descripcion);
return TRUE;
}
}