-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsms_service.php
More file actions
79 lines (70 loc) · 2.71 KB
/
sms_service.php
File metadata and controls
79 lines (70 loc) · 2.71 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use Simpay\Configuration;
use Simpay\Exception\Forbidden;
use Simpay\Exception\InternalServerError;
use Simpay\Exception\NotFound;
use Simpay\Exception\Unauthorized;
use Simpay\Exception\Unknown;
use Simpay\Exception\UnprocessableEntity;
use Simpay\Model\Request\ServiceId;
use Simpay\Model\Request\ServiceNumber;
use Simpay\Model\Request\SmsCode;
$configuration = new Configuration('your_api_key', 'your_api_password', 'en');
$factory = new Simpay\HttpClientFactory($configuration);
$api = new Simpay\SmsServiceApi($factory);
try {
// Get all SMS services
$services = $api->smsServiceList();
foreach ($services->data as $service) {
echo $service->id . PHP_EOL;
echo $service->name . PHP_EOL;
echo $service->description . PHP_EOL;
echo $service->type . PHP_EOL;
echo $service->status . PHP_EOL;
echo $service->adult . PHP_EOL;
echo $service->createdAt->format('Y-m-d H:i:s') . PHP_EOL;
}
// Get details of an SMS service
$serviceId = new ServiceId('d151e4f9');
$service = $api->smsServiceShow($serviceId);
echo $service->id . PHP_EOL;
echo $service->name . PHP_EOL;
echo $service->description . PHP_EOL;
echo $service->type . PHP_EOL;
echo $service->status . PHP_EOL;
echo $service->adult . PHP_EOL;
echo $service->createdAt->format('Y-m-d H:i:s') . PHP_EOL;
// Check an SMS code for a service
$serviceId = new ServiceId('d151e4f9');
$code = new SmsCode('123456');
$serviceNumber = ServiceNumber::createServiceNumber7055();
$checkData = $api->smsServiceCheckCode($serviceId, $code, $serviceNumber);
echo $checkData->number . PHP_EOL;
echo $checkData->value . PHP_EOL;
echo $checkData->code . PHP_EOL;
echo $checkData->test . PHP_EOL;
echo $checkData->used . PHP_EOL;
if (true === $checkData->used && null !== $checkData->usedAt) {
echo $checkData->usedAt->format('Y-m-d H:i:s') . PHP_EOL;
}
} catch (Unauthorized $exception) {
// Handle unauthorized exception
echo $exception->getMessage() . PHP_EOL;
} catch (Forbidden $exception) {
// Handle forbidden exception
echo $exception->getMessage() . PHP_EOL;
} catch (NotFound $exception) {
// Handle not found exception
echo $exception->getMessage() . PHP_EOL;
} catch (UnprocessableEntity $exception) {
// Handle unprocessable entity exception
echo $exception->getMessage() . PHP_EOL;
} catch (InternalServerError $exception) {
// Handle internal server error exception
echo $exception->getMessage() . PHP_EOL;
} catch (Unknown $exception) {
// Handle unknown exception
echo $exception->getMessage() . PHP_EOL;
}