|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* SPDX-FileCopyrightText: 2024 Francois Blackburn <[email protected]> |
|
7
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\Drivers; |
|
11
|
|
|
|
|
12
|
|
|
use Exception; |
|
13
|
|
|
use OCA\TwoFactorGateway\Exception\MessageTransmissionException; |
|
14
|
|
|
use OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\AProvider; |
|
15
|
|
|
use OCA\TwoFactorGateway\Provider\FieldDefinition; |
|
16
|
|
|
use OCA\TwoFactorGateway\Provider\Settings; |
|
17
|
|
|
use OCP\Http\Client\IClient; |
|
18
|
|
|
use OCP\Http\Client\IClientService; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @method string getApiUser() |
|
22
|
|
|
* @method static setApiUser(string $apiUser) |
|
23
|
|
|
* @method string getApiPassword() |
|
24
|
|
|
* @method static setApiPassword(string $apiPassword) |
|
25
|
|
|
* @method string getDid() |
|
26
|
|
|
* @method static setDid(string $did) |
|
27
|
|
|
*/ |
|
28
|
|
|
class VoipMs extends AProvider { |
|
29
|
|
|
private IClient $client; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
IClientService $clientService, |
|
33
|
|
|
) { |
|
34
|
|
|
$this->client = $clientService->newClient(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function createSettings(): Settings { |
|
38
|
|
|
return new Settings( |
|
39
|
|
|
id: 'voipms', |
|
40
|
|
|
name: 'VoIP.ms', |
|
41
|
|
|
fields: [ |
|
42
|
|
|
new FieldDefinition( |
|
43
|
|
|
field: 'api_user', |
|
44
|
|
|
prompt: 'Please enter your VoIP.ms API username:', |
|
45
|
|
|
), |
|
46
|
|
|
new FieldDefinition( |
|
47
|
|
|
field: 'api_password', |
|
48
|
|
|
prompt: 'Please enter your VoIP.ms API password:', |
|
49
|
|
|
), |
|
50
|
|
|
new FieldDefinition( |
|
51
|
|
|
field: 'did', |
|
52
|
|
|
prompt: 'Please enter your VoIP.ms DID:', |
|
53
|
|
|
), |
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
#[\Override] |
|
59
|
|
|
public function send(string $identifier, string $message) { |
|
60
|
|
|
$user = $this->getApiUser(); |
|
61
|
|
|
$password = $this->getApiPassword(); |
|
62
|
|
|
$did = $this->getDid(); |
|
63
|
|
|
try { |
|
64
|
|
|
$this->client->get('https://voip.ms/api/v1/rest.php', [ |
|
65
|
|
|
'query' => [ |
|
66
|
|
|
'api_username' => $user, |
|
67
|
|
|
'api_password' => $password, |
|
68
|
|
|
'method' => 'sendSMS', |
|
69
|
|
|
'did' => $did, |
|
70
|
|
|
'dst' => $identifier, |
|
71
|
|
|
'message' => $message, |
|
72
|
|
|
], |
|
73
|
|
|
]); |
|
74
|
|
|
} catch (Exception $ex) { |
|
75
|
|
|
throw new MessageTransmissionException(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|