2016-09-01 11:42:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Vn\Lib;
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
class Sms extends Vn\Web\JsonRequest {
|
2016-09-06 14:25:02 +00:00
|
|
|
const PARAMS = [
|
2017-12-19 09:08:11 +00:00
|
|
|
'destination'
|
|
|
|
,'message'
|
|
|
|
];
|
|
|
|
|
|
|
|
const OK_STATES = [
|
|
|
|
0, // Ok
|
2017-12-19 09:24:21 +00:00
|
|
|
200 // Processing
|
2016-09-06 14:25:02 +00:00
|
|
|
];
|
2016-09-01 11:42:11 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function run($db) {
|
|
|
|
$smsConfig = $db->getObject('SELECT uri, user, password, title FROM vn.smsConfig');
|
2016-09-01 11:42:11 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$sClient = new SoapClient($smsConfig->uri);
|
|
|
|
$xmlString = $sClient->sendSMS(
|
2017-12-13 18:28:54 +00:00
|
|
|
$smsConfig->user
|
|
|
|
,$smsConfig->password
|
|
|
|
,$smsConfig->title
|
2017-12-19 09:08:11 +00:00
|
|
|
,$_REQUEST['destination']
|
|
|
|
,$_REQUEST['message']
|
2016-09-01 11:42:11 +00:00
|
|
|
);
|
2018-05-23 10:14:20 +00:00
|
|
|
$xmlResponse = new SimpleXMLElement($xmlString);
|
2017-12-13 18:28:54 +00:00
|
|
|
$res = $xmlResponse->sms;
|
2016-09-01 11:42:11 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$db->query(
|
2017-12-19 09:08:11 +00:00
|
|
|
'INSERT INTO vn.sms SET
|
2020-10-23 10:10:41 +00:00
|
|
|
`senderFk` = account.myUser_getId(),
|
2017-12-19 09:08:11 +00:00
|
|
|
`destinationFk` = #,
|
|
|
|
`destination` = #,
|
|
|
|
`message` = #,
|
|
|
|
`statusCode` = #,
|
|
|
|
`status` = #',
|
2017-12-13 18:28:54 +00:00
|
|
|
[
|
2018-05-23 10:14:20 +00:00
|
|
|
empty($_REQUEST['destinationId']) ? NULL : $_REQUEST['destinationId']
|
2017-12-19 09:08:11 +00:00
|
|
|
,$_REQUEST['destination']
|
|
|
|
,$_REQUEST['message']
|
2017-12-13 18:28:54 +00:00
|
|
|
,$res->codigo
|
|
|
|
,$res->descripcion
|
|
|
|
]
|
|
|
|
);
|
2016-09-01 11:42:11 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (!in_array((int) $res->codigo, self::OK_STATES))
|
|
|
|
throw new Lib\UserException($res->descripcion);
|
2016-09-01 11:42:11 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|