Файл: _rootinc/smsplan.inc.php
Строк: 44
<?
class SMSPLAN
{
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;
}
public function send($script,$request)
{
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, $this->url.$script);
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 $result;
}
public function sendSMS($mobile, $sender, $smsmsg)
{
if (!$sender) { $sender = "default"; }
$smsmsg = iconv("utf-8", "windows-1251", $smsmsg);
$result = $this->send("send.php","user=$this->user&password=$this->password&text=$smsmsg&to=$mobile&sender=$sender");
$result = xml2array($result);
if ($result[messages][0][id]) {
return $result[messages][0][id];
} else if ($result[error]) {
$this->error = "sendSMS: ".$result[error];
return false;
} else {
$this->error = "sendSMS: no result or cant parse result";
return false;
}
}
public function getSMSStatus($id)
{
$result = $this->send("status.php","user=$this->user&password=$this->password&mids=$id");
$result = iconv("windows-1251", "utf-8", $result);
$result = toarray($result,"result",1);
if ($result[message][0][attributes][id] == $id) {
$res[date] = $result[message][0][attributes][update];
$res[status] = $result[message][0][value];
return $res;
} else {
$this->error = "getSMSStatus: no result or cant parse result";
return false;
}
}
}
?>