/var/www/vhosts/nabawater/common/helpers
Edit: /var/www/vhosts/nabawater/common/helpers/SmsGateway.php (1862B)
* This GatewayApi is used to send SMS
* Class SmsGateway (used GuzzleHttp)
* @package common\helpers
* @author Baluraj R
*/
namespace common\helpers;
use common\models\Configuration;
use yii\helpers\Json;
use Twilio\Rest\Client;
class SmsGateway {
private $api_key;
private static $instance;
private $from;
public function __construct() {
$this->setApiKey(Configuration::get(Configuration::SMS_ACCOUNT_ID));
$this->setFrom(Configuration::get(Configuration::SMS_GATEWAY_FROM));
}
public static function getInstance() {
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function setApiKey($apikey) {
$this->api_key = $apikey;
}
public function setFrom($from)
{
$this->from = $from;
return $this;
}
public function sendSMS($mobile, $msg)
{
try {
// Account details
$apiKey = $this->api_key;
$sender = $this->from;
$message = rawurlencode($msg);
// Prepare data for POST request
$data = array('apikey' => $apiKey, 'numbers' => $mobile, "sender" => $sender, "message" => $message);
// Send the POST request with cURL
$ch = curl_init('https://api.textlocal.in/send/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
} catch (\Exception $Ste) {
return $Ste;
}
}
}