| 1 |
<?php |
| 2 |
|
| 3 |
namespace LAM\PLUGINS\SMS; |
| 4 |
|
| 5 |
/* |
| 6 |
|
| 7 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 8 |
Copyright (C) 2025 - 2026 Roland Gruber |
| 9 |
|
| 10 |
This program is free software; you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation; either version 2 of the License, or |
| 13 |
(at your option) any later version. |
| 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 General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program; if not, write to the Free Software |
| 22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 |
|
| 24 |
*/ |
| 25 |
|
| 26 |
use LAMException; |
| 27 |
|
| 28 |
/** |
| 29 |
* GatewayAPI SMS provider. |
| 30 |
* |
| 31 |
* @author Roland Gruber |
| 32 |
*/ |
| 33 |
|
| 34 |
/** |
| 35 |
* GatewayAPI SMS provider. |
| 36 |
* |
| 37 |
* @package LAM\PLUGINS\SMS |
| 38 |
*/ |
| 39 |
class GatewayApiSmsProvider implements SmsProvider { |
| 40 |
|
| 41 |
/** |
| 42 |
* @inheritDoc |
| 43 |
*/ |
| 44 |
public function getLabel(): string { |
| 45 |
return 'GatewayAPI'; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @inheritDoc |
| 50 |
*/ |
| 51 |
public function getId(): string { |
| 52 |
return 'gatewayApi'; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @inheritDoc |
| 57 |
*/ |
| 58 |
public function sendSms(string $message, string $number, ?string $apiKey = '', ?string $apiToken = '', |
| 59 |
?string $accountId = '', ?string $region = '', ?string $from = '', ?string $subject = ''): void { |
| 60 |
$curl = curl_init(); |
| 61 |
$postData = [ |
| 62 |
"recipients" => [ |
| 63 |
['msisdn' => $number] |
| 64 |
], |
| 65 |
"message" => $message, |
| 66 |
"label" => "LAM Pro", |
| 67 |
"sender" => SmsService::SENDER_NAME |
| 68 |
]; |
| 69 |
$postJson = json_encode($postData); |
| 70 |
curl_setopt_array($curl, [ |
| 71 |
CURLOPT_URL => 'https://gatewayapi.eu/rest/mtsms', |
| 72 |
CURLOPT_RETURNTRANSFER => true, |
| 73 |
CURLOPT_POST => true, |
| 74 |
CURLOPT_POSTFIELDS => $postJson, |
| 75 |
CURLOPT_USERPWD => $apiToken, |
| 76 |
CURLOPT_HTTPHEADER => [ |
| 77 |
'Content-Type: application/json', |
| 78 |
'Accept: application/json', |
| 79 |
], |
| 80 |
]); |
| 81 |
$response = curl_exec($curl); |
| 82 |
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
| 83 |
logNewMessage(LOG_DEBUG, 'SMS gateway response: ' . $response); |
| 84 |
$responseJson = json_decode($response, true); |
| 85 |
if ($httpCode !== 200) { |
| 86 |
logNewMessage(LOG_ERR, 'Unable to send SMS: ' . $response); |
| 87 |
$message = $responseJson['message'] ?? ''; |
| 88 |
throw new LAMException(null, $message); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* @inheritDoc |
| 94 |
*/ |
| 95 |
public function usesApiToken(): bool { |
| 96 |
return true; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* @inheritDoc |
| 101 |
*/ |
| 102 |
public function usesApiKey(): bool { |
| 103 |
return false; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* @inheritDoc |
| 108 |
*/ |
| 109 |
public function usesAccountId(): bool { |
| 110 |
return false; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* @inheritDoc |
| 115 |
*/ |
| 116 |
public function usesFrom(): bool { |
| 117 |
return false; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* @inheritDoc |
| 122 |
*/ |
| 123 |
public function usesRegion(): bool { |
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* @inheritDoc |
| 129 |
*/ |
| 130 |
public function usesSubject(): bool { |
| 131 |
return false; |
| 132 |
} |
| 133 |
|
| 134 |
} |