1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Christian Schrötter <[email protected]> |
7
|
|
|
* @author Christoph Wurst <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Nextcloud - Two-factor Gateway |
10
|
|
|
* |
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
13
|
|
|
* as published by the Free Software Foundation. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider; |
26
|
|
|
|
27
|
|
|
use Exception; |
28
|
|
|
use OCA\TwoFactorGateway\Exception\SmsTransmissionException; |
29
|
|
|
use OCP\Http\Client\IClient; |
30
|
|
|
use OCP\Http\Client\IClientService; |
31
|
|
|
|
32
|
|
|
class ClickatellCentral implements IProvider { |
33
|
|
|
|
34
|
|
|
const PROVIDER_ID = 'clickatellcentral'; |
35
|
|
|
|
36
|
|
|
/** @var IClient */ |
37
|
|
|
private $client; |
38
|
|
|
|
39
|
|
|
/** @var ClickatellCentralConfig */ |
40
|
|
|
private $config; |
41
|
|
|
|
42
|
|
|
public function __construct(IClientService $clientService, |
43
|
|
|
ClickatellCentralConfig $config) { |
44
|
|
|
$this->client = $clientService->newClient(); |
45
|
|
|
$this->config = $config; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $identifier |
50
|
|
|
* @param string $message |
51
|
|
|
* |
52
|
|
|
* @throws SmsTransmissionException |
53
|
|
|
*/ |
54
|
|
|
public function send(string $identifier, string $message) { |
55
|
|
|
$config = $this->getConfig(); |
56
|
|
|
try { |
57
|
|
|
$this->client->get(vsprintf('https://api.clickatell.com/http/sendmsg?user=%s&password=%s&api_id=%u&to=%s&text=%s', [ |
58
|
|
|
urlencode($config->getUser()), |
59
|
|
|
urlencode($config->getPassword()), |
60
|
|
|
$config->getApi(), |
61
|
|
|
urlencode($identifier), |
62
|
|
|
urlencode($message), |
63
|
|
|
])); |
64
|
|
|
} catch (Exception $ex) { |
65
|
|
|
throw new SmsTransmissionException(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return ClickatellCentralConfig |
71
|
|
|
*/ |
72
|
|
|
public function getConfig(): IProviderConfig { |
73
|
|
|
return $this->config; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|