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 OCP\Http\Client\IClient; |
16
|
|
|
use OCP\Http\Client\IClientService; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @method string getApiUser() |
20
|
|
|
* @method static setApiUser(string $apiUser) |
21
|
|
|
* @method string getApiPassword() |
22
|
|
|
* @method static setApiPassword(string $apiPassword) |
23
|
|
|
* @method string getDid() |
24
|
|
|
* @method static setDid(string $did) |
25
|
|
|
*/ |
26
|
|
|
class VoipMs extends AProvider { |
27
|
|
|
public const SCHEMA = [ |
28
|
|
|
'name' => 'VoIP.ms', |
29
|
|
|
'fields' => [ |
30
|
|
|
['field' => 'api_user', 'prompt' => 'Please enter your VoIP.ms API username:'], |
31
|
|
|
['field' => 'api_password', 'prompt' => 'Please enter your VoIP.ms API password:'], |
32
|
|
|
['field' => 'did', 'prompt' => 'Please enter your VoIP.ms DID:'], |
33
|
|
|
], |
34
|
|
|
]; |
35
|
|
|
private IClient $client; |
36
|
|
|
|
37
|
|
|
public function __construct( |
38
|
|
|
IClientService $clientService, |
39
|
|
|
) { |
40
|
|
|
$this->client = $clientService->newClient(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
#[\Override] |
44
|
|
|
public function send(string $identifier, string $message) { |
45
|
|
|
$user = $this->getApiUser(); |
46
|
|
|
$password = $this->getApiPassword(); |
47
|
|
|
$did = $this->getDid(); |
48
|
|
|
try { |
49
|
|
|
$this->client->get('https://voip.ms/api/v1/rest.php', [ |
50
|
|
|
'query' => [ |
51
|
|
|
'api_username' => $user, |
52
|
|
|
'api_password' => $password, |
53
|
|
|
'method' => 'sendSMS', |
54
|
|
|
'did' => $did, |
55
|
|
|
'dst' => $identifier, |
56
|
|
|
'message' => $message, |
57
|
|
|
], |
58
|
|
|
]); |
59
|
|
|
} catch (Exception $ex) { |
60
|
|
|
throw new MessageTransmissionException(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|