Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions notifysms_aula02/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ''
]);

Expand Down
4 changes: 2 additions & 2 deletions notifysms_aula02/source/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -69,4 +69,4 @@ public function validateCode($user_email, $user_code)

}
}
}
}
54 changes: 54 additions & 0 deletions notifysms_aula02/source/notify/sms/TiniyoSms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Created by https://tiniyo.com.
* User: support@tiniyo.com
* Date: 10/11/2020
* Time: 13:37
*/

namespace Source\Notify\SMS;

class TiniyoSms {

private $urlService;
private $endPoint;
private $params;
private $callback;

public function __construct()
{
$this->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);
}

}