Я отправляю смс на номер в codeigniter используя twilio.Это мой код
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once(APPPATH . 'third_party/twilio-php-master/Twilio/autoload.php');
use Twilio\Rest\Client;
class Twilio {
protected $sid = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
protected $token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
protected $from = '+123456789';
public function sendSMS($number, $text) {
$data = ['phone' => $number, 'text' => $text];
return $this->sms($data);
}
protected function sms($data) {
$client = new Client($this->sid, $this->token);
try {
$smsObj = $client->messages->create(
// the number you'd like to send the message to
$data['phone'], array(
// A Twilio phone number you purchased at twilio.com/console
"from" => $this->from,
// the body of the text message you'd like to send
'body' => $data['text']
)
);
$returnData['price'] = $smsObj->price;
$returnData['status'] = $smsObj->status;
$returnData['sid'] = $smsObj->sid;
$returnData['to'] = $smsObj->to;
$returnData['from'] = $smsObj->from;
$returnData['body'] = $smsObj->body;
$returnData['direction'] = $smsObj->direction;
$data = $returnData;
$status = 'true';
} catch (Twilio\Exceptions\RestException $e) {
$data = [];
$status = 'false due to '.$e->getStatus();
}
return [
"status" => $status,
"data" => $data
];
}
}
Правильное сообщение отправляется, но я не могу получить правильное сообщение об ошибке.Вот как я это называю
$this->load->library('Twilio');
$lib = new Twilio();
$response = $lib->sendSMS('+92','Sample SMS');
Я получаю это сообщение об ошибке
An uncaught Exception was encountered
Type: Error
Message: Call to undefined method Twilio\Exceptions\RestException::getStatus()
Filename: E:\xampp\htdocs\binance\application\libraries\Twilio.php
Line Number: 56
Backtrace:
File: E:\xampp\htdocs\binance\application\libraries\Twilio.php
Line: 28
Function: sms
File: E:\xampp\htdocs\binance\application\controllers\admin\Trade.php
Line: 498
Function: sendSMS
File: E:\xampp\htdocs\binance\index.php
Line: 316
Function: require_once