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 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 getUsername() |
22
|
|
|
* @method static setUsername(string $username) |
23
|
|
|
* @method string getPassword() |
24
|
|
|
* @method static setPassword(string $password) |
25
|
|
|
* @method string getSenderid() |
26
|
|
|
* @method static setSenderid(string $senderid) |
27
|
|
|
*/ |
28
|
|
|
class EcallSMS extends AProvider { |
29
|
|
|
private IClient $client; |
30
|
|
|
|
31
|
1 |
|
public function __construct( |
32
|
|
|
IClientService $clientService, |
33
|
|
|
) { |
34
|
1 |
|
$this->client = $clientService->newClient(); |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public function createSettings(): Settings { |
38
|
1 |
|
return new Settings( |
39
|
1 |
|
id: 'ecallsms', |
40
|
1 |
|
name: 'EcallSMS', |
41
|
1 |
|
fields: [ |
42
|
1 |
|
new FieldDefinition( |
43
|
1 |
|
field: 'username', |
44
|
1 |
|
prompt: 'Please enter your eCall.ch username:', |
45
|
1 |
|
), |
46
|
1 |
|
new FieldDefinition( |
47
|
1 |
|
field: 'password', |
48
|
1 |
|
prompt: 'Please enter your eCall.ch password:', |
49
|
1 |
|
), |
50
|
1 |
|
new FieldDefinition( |
51
|
1 |
|
field: 'senderid', |
52
|
1 |
|
prompt: 'Please enter your eCall.ch sender ID:', |
53
|
1 |
|
), |
54
|
1 |
|
] |
55
|
1 |
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
#[\Override] |
59
|
|
|
public function send(string $identifier, string $message) { |
60
|
|
|
$user = $this->getUsername(); |
61
|
|
|
$password = $this->getPassword(); |
62
|
|
|
$senderId = $this->getSenderId(); |
63
|
|
|
try { |
64
|
|
|
$this->client->get('https://url.ecall.ch/api/sms', [ |
65
|
|
|
'query' => [ |
66
|
|
|
'username' => $user, |
67
|
|
|
'password' => $password, |
68
|
|
|
'Callback' => $senderId, |
69
|
|
|
'address' => $identifier, |
70
|
|
|
'message' => $message, |
71
|
|
|
], |
72
|
|
|
]); |
73
|
|
|
} catch (Exception $ex) { |
74
|
|
|
throw new MessageTransmissionException(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|