Files

104 lines
2.8 KiB
PHP

<?php
namespace Packages\SMSSender;
class SMSSender
{
private $userName = null;
private $password = null;
private $webService = null;
private $fromNumber = null;
private static $panel = null;
private function __construct()
{
}
public static function instance()
{
if (static::$panel === null) {
static::$panel = new self();
}
return static::$panel;
}
public function setUserName($userName)
{
$this->userName = $userName;
return $this;
}
public function setPassword($password)
{
$this->password = $password;
return $this;
}
public function setWebService($webService)
{
$this->webService = $webService;
return $this;
}
public function getUserName()
{
return ($this->userName) ? $this->userName : env('SMS_USERNAME', '');
}
public function getPassword()
{
return ($this->password) ? $this->password : env('SMS_PASSWORD', '');
}
public function getFromNumber()
{
return ($this->fromNumber) ? $this->fromNumber : env('SMS_FROM_NUMBER', '');
}
public function getWebService()
{
return ($this->webService) ? $this->webService : env('SMS_WEBSERVICE', '');
}
public function patternSend($cellNumber, $pattern_code, $input_data)
{
if (is_string($cellNumber)) {
$cellNumber = [$cellNumber];
}
try {
$user = $this->getUserName();
$pass = $this->getPassword();
$fromNum = $this->getFromNumber();
$client = new \SoapClient($this->getWebService());
$client->sendPatternSms($fromNum, $cellNumber, $user, $pass, $pattern_code, $input_data);
} catch (\SoapFault $sf) {
print $sf->faultcode . "\n";
print $sf->faultstring . "\n";
return ['code' => $sf->faultcode, 'message' => $sf->faultstring];
}
}
public function send($cellNumber, $messageContent)
{
if (is_string($cellNumber)) {
$cellNumber = [$cellNumber];
}
ini_set("soap.wsdl_cache_enabled", "0");
try {
$user = $this->getUserName();
$pass = $this->getPassword();
$fromNum = $this->getFromNumber();
//If you want to send in the future ==> $time = '2016-07-30' //$time = '2016-07-30 12:50:50'
$client = new \SoapClient($this->getWebService());
$client->SendSMS($fromNum, $cellNumber, $messageContent, $user, $pass, '', 'send');
return true;
} catch (\SoapFault $sf) {
print $sf->faultcode . "\n";
print $sf->faultstring . "\n";
return ['code' => $sf->faultcode, 'message' => $sf->faultstring];
}
}
}