diff --git a/notifysms_aula02/config.php b/notifysms_aula02/config.php index 31585e8..362a673 100644 --- a/notifysms_aula02/config.php +++ b/notifysms_aula02/config.php @@ -20,9 +20,12 @@ require_once __DIR__ . '/source/models/User.php'; +//You can send sms through tiniyo just signup on tiniyo, get your auth_id as CLIENT_ID and auth_secret as CLIENT_SECRET +//CALLBACK_URL is needed if you want to receive delivery report define('CONFIG_SMS', [ 'CLIENT_ID' => '', 'CLIENT_SECRET' => '', + 'CALLBACK_URL' => '', 'GUHWEB' => '' ]); diff --git a/notifysms_aula02/source/models/User.php b/notifysms_aula02/source/models/User.php index cdcbf48..4146df8 100644 --- a/notifysms_aula02/source/models/User.php +++ b/notifysms_aula02/source/models/User.php @@ -11,7 +11,7 @@ use CRUD\Create; use CRUD\Read; use CRUD\Update; -use Source\Notify\SMS\DirectCall; +use Source\Notify\SMS\DirectCall; //for sms through tiniyo, Use Source\Notify\SMS\TiniyoSms; class User { @@ -69,4 +69,4 @@ public function validateCode($user_email, $user_code) } } -} \ No newline at end of file +} diff --git a/notifysms_aula02/source/notify/sms/TiniyoSms.php b/notifysms_aula02/source/notify/sms/TiniyoSms.php new file mode 100644 index 0000000..9e5bb76 --- /dev/null +++ b/notifysms_aula02/source/notify/sms/TiniyoSms.php @@ -0,0 +1,54 @@ +urlService = 'https://api.tiniyo.com'; + } + + public function sendSMS($from, $to, $text) + { + $this->endPoint = sprintf("/v1/Account/%/Message",CONFIG_SMS['CLIENT_ID']); + + $this->params = [ + 'src' => $from, + 'dst' => $to, + 'url' => CONFIG_SMS['CALLBACK_URL'], + 'client_id' => CONFIG_SMS['CLIENT_ID'], + 'client_secret' => CONFIG_SMS['CLIENT_SECRET'], + 'format' => 'json' + 'text' => $text + ]; + + $this->post(); + } + + private function post() + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->urlService . $this->endPoint); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->params)); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + $this->callback = json_decode(curl_exec($ch)); + + curl_close($ch); + } + +}