1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* SPDX-FileCopyrightText: 2024 Fabian Zihlmann <[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 getUsername() |
20
|
|
|
* @method static setUsername(string $username) |
21
|
|
|
* @method string getPassword() |
22
|
|
|
* @method static setPassword(string $password) |
23
|
|
|
* @method string getSenderid() |
24
|
|
|
* @method static setSenderid(string $senderid) |
25
|
|
|
*/ |
26
|
|
|
class EcallSMS extends AProvider { |
27
|
|
|
public const SCHEMA = [ |
28
|
|
|
'name' => 'EcallSMS', |
29
|
|
|
'fields' => [ |
30
|
|
|
['field' => 'user', 'prompt' => 'Please enter your eCall.ch username:'], |
31
|
|
|
['field' => 'password', 'prompt' => 'Please enter your eCall.ch password:'], |
32
|
|
|
['field' => 'sender_id', 'prompt' => 'Please enter your eCall.ch sender ID:'], |
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->getUsername(); |
46
|
|
|
$password = $this->getPassword(); |
47
|
|
|
$senderId = $this->getSenderId(); |
48
|
|
|
try { |
49
|
|
|
$this->client->get('https://url.ecall.ch/api/sms', [ |
50
|
|
|
'query' => [ |
51
|
|
|
'username' => $user, |
52
|
|
|
'password' => $password, |
53
|
|
|
'Callback' => $senderId, |
54
|
|
|
'address' => $identifier, |
55
|
|
|
'message' => $message, |
56
|
|
|
], |
57
|
|
|
]); |
58
|
|
|
} catch (Exception $ex) { |
59
|
|
|
throw new MessageTransmissionException(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|