1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* SPDX-FileCopyrightText: 2024 Kim Syversen <[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 getUrl() |
20
|
|
|
* @method static setUrl(string $url) |
21
|
|
|
* @method string getUser() |
22
|
|
|
* @method static setUser(string $user) |
23
|
|
|
* @method string getPassword() |
24
|
|
|
* @method static setPassword(string $password) |
25
|
|
|
* @method string getServiceid() |
26
|
|
|
* @method static setServiceid(string $serviceid) |
27
|
|
|
*/ |
28
|
|
|
class PuzzelSMS extends AProvider { |
29
|
|
|
public const SCHEMA = [ |
30
|
|
|
'id' => 'puzzel', |
31
|
|
|
'name' => 'Puzzel SMS', |
32
|
|
|
'fields' => [ |
33
|
|
|
['field' => 'url', 'prompt' => 'Please enter your PuzzelSMS URL:'], |
34
|
|
|
['field' => 'user', 'prompt' => 'Please enter your PuzzelSMS username:'], |
35
|
|
|
['field' => 'password', 'prompt' => 'Please enter your PuzzelSMS password:'], |
36
|
|
|
['field' => 'serviceid', 'prompt' => 'Please enter your PuzzelSMS service ID:'], |
37
|
|
|
], |
38
|
|
|
]; |
39
|
|
|
private IClient $client; |
40
|
|
|
|
41
|
|
|
public function __construct( |
42
|
|
|
IClientService $clientService, |
43
|
|
|
) { |
44
|
|
|
$this->client = $clientService->newClient(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
#[\Override] |
48
|
|
|
public function send(string $identifier, string $message) { |
49
|
|
|
try { |
50
|
|
|
$this->client->get( |
51
|
|
|
$this->getUrl(), |
52
|
|
|
[ |
53
|
|
|
'query' => [ |
54
|
|
|
'username' => $this->getUser(), |
55
|
|
|
'password' => $this->getPassword(), |
56
|
|
|
'message[0].recipient' => '+' . $identifier, |
57
|
|
|
'message[0].content' => $message, |
58
|
|
|
'serviceId' => $this->getServiceid(), |
59
|
|
|
], |
60
|
|
|
] |
61
|
|
|
); |
62
|
|
|
} catch (Exception $ex) { |
63
|
|
|
throw new MessageTransmissionException(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|