-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-sms-verification-basic-auth.php
56 lines (45 loc) · 1.45 KB
/
test-sms-verification-basic-auth.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
55
56
<?php
declare(strict_types=1);
const URL = "https://verificationapi-v1.sinch.com/verification/v1/verifications";
const METHOD = "POST";
/*
The key from one of your Verification Apps, found here https://dashboard.sinch.com/verification/apps
*/
$applicationKey = "<REPLACE_WITH_VERIF_APP_KEY>";
/*
The secret from the Verification App that uses the key above, found here https://dashboard.sinch.com/verification/apps
*/
$applicationSecret = "<REPLACE_WITH_VERIF_APP_SECRET>";
/*
The number that will receive the SMS PIN. Test accounts are limited to verified numbers.
The number must be in E.164 Format, e.g. Netherlands 0639111222 -> +31639111222
*/
$toNumber = "<REPLACE_WITH_TO_NUMBER>";
$smsVerficationPayload = [
"identity" => [
"type" => "number",
"endpoint" => $toNumber
],
"method" => "sms"
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Authorization: Basic " . base64_encode($applicationKey . ":" . $applicationSecret)
],
CURLOPT_POSTFIELDS => json_encode($smsVerficationPayload),
CURLOPT_URL => URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => METHOD,
]);
$response = curl_exec($curl);
$error = curl_error($curl);
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($error) {
echo "cURL Error #:" . $error . "\n";
} else {
echo $response . "\n";
echo $statusCode . "\n";
}