1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* SPDX-FileCopyrightText: 2024 Pascal Clémot <[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
|
|
|
*/ |
26
|
|
|
class PlaySMS extends AProvider { |
27
|
|
|
public const SCHEMA = [ |
28
|
|
|
'name' => 'PlaySMS', |
29
|
|
|
'fields' => [ |
30
|
|
|
['field' => 'url', 'prompt' => 'Please enter your PlaySMS URL:'], |
31
|
|
|
['field' => 'user', 'prompt' => 'Please enter your PlaySMS username:'], |
32
|
|
|
['field' => 'password', 'prompt' => 'Please enter your PlaySMS password:'], |
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
|
|
|
try { |
46
|
|
|
$this->client->get( |
47
|
|
|
$this->getUrl(), |
48
|
|
|
[ |
49
|
|
|
'query' => [ |
50
|
|
|
'app' => 'ws', |
51
|
|
|
'u' => $this->getUser(), |
52
|
|
|
'h' => $this->getPassword(), |
53
|
|
|
'op' => 'pv', |
54
|
|
|
'to' => $identifier, |
55
|
|
|
'msg' => $message, |
56
|
|
|
], |
57
|
|
|
] |
58
|
|
|
); |
59
|
|
|
} catch (Exception $ex) { |
60
|
|
|
throw new MessageTransmissionException(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|