Server IP : 66.29.132.124 / Your IP : 3.143.239.63 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/book24.ng/modules/Sms/Core/Drivers/ |
Upload File : |
<?php namespace Modules\Sms\Core\Drivers; use Modules\Sms\Core\Exceptions\SmsException; use phpDocumentor\Reflection\DocBlock\Tags\Throws; class NexmoDriver extends Driver { protected $config; public function __construct($config) { $this->config = $config; } public function send() { $data = [ 'from'=>$this->config['from'], 'text'=>$this->message, 'to'=>$this->recipient, 'api_key'=>$this->config['key'], 'api_secret'=>$this->config['secret'], ]; $curl = $this->nexmoCurl($data); $result = json_decode($curl,true); if(!empty($result['messages'][0]['error-text'])){ throw new SmsException($result['messages'][0]['error-text']); } return $result; } public function nexmoCurl($data){ $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $this->config['url']); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_POST, count($data)); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $result = curl_exec($ch); curl_close($ch); return $result; } }