Файл: _rootinc/qtelecom.inc.php
Строк: 57
<?
class QTELECOM
{
public $url = null;
public $user = null;
public $password = null;
public $error = null;
public function init($url,$user,$password)
{
$this->url=$url;
$this->user=$user;
$this->password=$password;
}
private function send($request)
{
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, $this->url);
curl_setopt($fp, CURL_HTTP_VERSION_1_1, 1);
curl_setopt($fp, CURLOPT_POST, 1);
curl_setopt($fp, CURLOPT_POSTFIELDS, $request);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($fp, CURLOPT_RETURNTRANSFER,1);
curl_setopt($fp, CURLOPT_TIMEOUT, 120);
$result = curl_exec($fp);
if (@curl_errno($fp)) {
$this->error = "cURL Error ".@curl_errno($fp).": ".@curl_error($fp);
return false;
}
curl_close($fp);
return xmlToArrayL($result);
}
public function sendSMS($mobile, $sender, $smsmsg)
{
$request = <<<EOF
<?xml version="1.0" encoding="UTF-8" ?>
<xml_request name="sms_send">
<xml_user lgn="$this->user" pwd="$this->password"/>
<sms number="$mobile" source_number="$sender">$smsmsg</sms>
</xml_request>
EOF;
$result = $this->send($request);
if ($result[xml_result][push_attr][res] == "0") {
return $result[xml_result][push_attr][push_id];
} else if ($result[xml_result][push_attr][res]) {
$this->error = "sendSMS: Code ".$result[xml_result][push_attr][res]." (".$result[xml_result][push_attr][description].")";
return false;
} else if ($result[xml_result_attr][res]) {
$this->error = "sendSMS: Code ".$result[xml_result_attr][res]." (".$result[xml_result_attr][description].")";
return false;
} else {
$this->error = "sendSMS: no result or cant parse result";
return false;
}
}
public function getSMSStatus($id)
{
$request = <<<EOF
<?xml version="1.0" encoding="UTF-8" ?>
<xml_request name="sms_status2">
<xml_user lgn="$this->user" pwd="$this->password"/>
<sms push_id="$id"/>
</xml_request>
EOF;
$result = $this->send($request);
if ($result[xml_result][sms_attr][status] and $result[xml_result][sms_attr][status] != "-1") {
$date = $result[xml_result][sms_attr][delivery_date];
$time = $result[xml_result][sms_attr][delivery_time];
$status = $result[xml_result][sms_attr][status];
if ($date) { $date = fromMyDate($date); } else { $date = "0000-00-00";}
if (!$time) { $time = "00:00:00"; }
if ($status == "-1004") { $status = "Ошибка доставки"; }
else if ($status == "1") { $status = "В очереди"; }
else if ($status == "2") { $status = "Отправлено"; }
else if ($status == "4") { $status = "Доставлено"; }
else { $status = $result[xml_result][sms_attr][description]; }
$res[date] = $date." ".$time;
$res[status] = $status;
return $res;
} else if ($result[xml_result_attr][res]) {
$this->error = "getSMSStatus: Code ".$result[xml_result_attr][res]." (".$result[xml_result_attr][description].")";
return false;
} else {
$this->error = "getSMSStatus: no result or cant parse result";
return false;
}
}
}
?>