-
Notifications
You must be signed in to change notification settings - Fork 1
/
twilio.php
54 lines (44 loc) · 1.25 KB
/
twilio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Twilio;
use Authy\AuthyApi;
/**
* Will send a verification SMS to the given phone number and region code.
*
* @param string $phone
* @param int $countryNumber
*
* @return array|false
*/
function sendVerificationCode($phone, $countryNumber)
{
global $_t;
if(DEBUG_TWILIO) {
return [
'uuid' => vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(openssl_random_pseudo_bytes(16)), 4)),
'seconds' => 600
];
}
$authy = new AuthyApi(AUTHY_API_KEY);
$result = $authy->phoneVerificationStart($phone, $countryNumber, 'sms', 4, $_t['lang']['iso_lang']);
if($result->ok()) {
return [
'uuid' => $result->bodyvar('uuid'),
'seconds' => $result->bodyvar('seconds_to_expire')
];
}
return false;
}
function checkVerification($phone, $countryNumber, $code) {
if(DEBUG_TWILIO) {
if((string)$code === '1234') {
return true;
}
return 'Code is 1234, we are in testing mode.';
}
$authy = new AuthyApi(AUTHY_API_KEY);
$result = $authy->phoneVerificationCheck($phone, $countryNumber, $code);
if($result->bodyvar('success') === true) {
return true;
}
return $result->bodyvar('message');
}