From 6d5c9ff523af25cbfaa843a1a9f9974909d92687 Mon Sep 17 00:00:00 2001 From: tiniyoadmin <68080298+tiniyoadmin@users.noreply.github.com> Date: Tue, 10 Nov 2020 15:01:48 +0800 Subject: [PATCH 1/5] Create TiniyoSms.php --- .../source/notify/sms/TiniyoSms.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 notifysms_aula02/source/notify/sms/TiniyoSms.php diff --git a/notifysms_aula02/source/notify/sms/TiniyoSms.php b/notifysms_aula02/source/notify/sms/TiniyoSms.php new file mode 100644 index 0000000..653cd60 --- /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); + } + +} From b0b17941bc2961bf5c8b70ce8d3f854469d91f6b Mon Sep 17 00:00:00 2001 From: tiniyoadmin <68080298+tiniyoadmin@users.noreply.github.com> Date: Tue, 10 Nov 2020 15:04:16 +0800 Subject: [PATCH 2/5] Update config.php --- notifysms_aula02/config.php | 3 +++ 1 file changed, 3 insertions(+) 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' => '' ]); From 1bf99c2c29a4691e807e3b1d59ea578e4b377f2f Mon Sep 17 00:00:00 2001 From: tiniyoadmin <68080298+tiniyoadmin@users.noreply.github.com> Date: Tue, 10 Nov 2020 15:04:59 +0800 Subject: [PATCH 3/5] Update TiniyoSms.php --- notifysms_aula02/source/notify/sms/TiniyoSms.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifysms_aula02/source/notify/sms/TiniyoSms.php b/notifysms_aula02/source/notify/sms/TiniyoSms.php index 653cd60..385e9d8 100644 --- a/notifysms_aula02/source/notify/sms/TiniyoSms.php +++ b/notifysms_aula02/source/notify/sms/TiniyoSms.php @@ -8,7 +8,7 @@ namespace Source\Notify\SMS; -class DirectCall { +class TiniyoSMS { private $urlService; private $endPoint; From bd5e60df1c200cfe03aa12c9cd1041f3af9ff2a0 Mon Sep 17 00:00:00 2001 From: tiniyoadmin <68080298+tiniyoadmin@users.noreply.github.com> Date: Tue, 10 Nov 2020 15:05:27 +0800 Subject: [PATCH 4/5] Update TiniyoSms.php --- notifysms_aula02/source/notify/sms/TiniyoSms.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifysms_aula02/source/notify/sms/TiniyoSms.php b/notifysms_aula02/source/notify/sms/TiniyoSms.php index 385e9d8..9e5bb76 100644 --- a/notifysms_aula02/source/notify/sms/TiniyoSms.php +++ b/notifysms_aula02/source/notify/sms/TiniyoSms.php @@ -8,7 +8,7 @@ namespace Source\Notify\SMS; -class TiniyoSMS { +class TiniyoSms { private $urlService; private $endPoint; From 176e6695e9ade24f1385a7b82b8f61e3e737917e Mon Sep 17 00:00:00 2001 From: tiniyoadmin <68080298+tiniyoadmin@users.noreply.github.com> Date: Tue, 10 Nov 2020 15:09:38 +0800 Subject: [PATCH 5/5] Update User.php --- notifysms_aula02/source/models/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 +}