1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* SPDX-FileCopyrightText: 2024 Henning Bopp <[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 getUser() |
20
|
|
|
* @method static setUser(string $user) |
21
|
|
|
* |
22
|
|
|
* @method string getApikey() |
23
|
|
|
* @method static setApikey(string $apikey) |
24
|
|
|
*/ |
25
|
|
|
class ClickSend extends AProvider { |
26
|
|
|
public const SCHEMA = [ |
27
|
|
|
'name' => 'ClickSend', |
28
|
|
|
'fields' => [ |
29
|
|
|
['field' => 'user', 'prompot' => 'Please enter your clicksend.com username:'], |
30
|
|
|
['field' => 'apikey', 'prompot' => 'Please enter your clicksend.com api key (or subuser password):'], |
31
|
|
|
], |
32
|
|
|
]; |
33
|
|
|
private IClient $client; |
34
|
|
|
|
35
|
|
|
public function __construct( |
36
|
|
|
IClientService $clientService, |
37
|
|
|
) { |
38
|
|
|
$this->client = $clientService->newClient(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
#[\Override] |
42
|
|
|
public function send(string $identifier, string $message) { |
43
|
|
|
$apiKey = $this->getApiKey(); |
44
|
|
|
$username = $this->getUser(); |
45
|
|
|
try { |
46
|
|
|
$this->client->get('https://api-mapper.clicksend.com/http/v2/send.php', [ |
47
|
|
|
'query' => [ |
48
|
|
|
'method' => 'http', |
49
|
|
|
'username' => $username, |
50
|
|
|
'key' => $apiKey, |
51
|
|
|
'to' => $identifier, |
52
|
|
|
'message' => $message, |
53
|
|
|
'senderid' => 'nextcloud' |
54
|
|
|
], |
55
|
|
|
]); |
56
|
|
|
} catch (Exception $ex) { |
57
|
|
|
throw new MessageTransmissionException(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|