mirror of
https://github.com/LDAPAccountManager/lam.git
synced 2025-10-03 01:39:33 +02:00
#441 SMS sending
This commit is contained in:
parent
573605cf09
commit
09dbbcb0fc
6 changed files with 112 additions and 5 deletions
|
@ -1678,7 +1678,7 @@ function isCommandlineSafeEmailAddress($address) {
|
||||||
* @throws LAMException error during SMS connection
|
* @throws LAMException error during SMS connection
|
||||||
*/
|
*/
|
||||||
function sendSmsTestMessage(string $providerId, ?string $apiKey, ?string $apiToken, string $number): void {
|
function sendSmsTestMessage(string $providerId, ?string $apiKey, ?string $apiToken, string $number): void {
|
||||||
include_once __DIR__ . '/plugins/sms/SmsProvider.inc';
|
include_once __DIR__ . '/plugins/sms/SmsService.inc';
|
||||||
$smsService = new SmsService();
|
$smsService = new SmsService();
|
||||||
try {
|
try {
|
||||||
$smsService->sendSms(_('LAM test message'), $number, $providerId, $apiKey, $apiToken);
|
$smsService->sendSms(_('LAM test message'), $number, $providerId, $apiKey, $apiToken);
|
||||||
|
|
107
lam/lib/plugins/sms/GatewayApiSmsProvider.inc
Normal file
107
lam/lib/plugins/sms/GatewayApiSmsProvider.inc
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LAM\PLUGINS\SMS;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
|
Copyright (C) 2025 Roland Gruber
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use LAMException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GatewayAPI SMS provider.
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GatewayAPI SMS provider.
|
||||||
|
*
|
||||||
|
* @package LAM\PLUGINS\SMS
|
||||||
|
*/
|
||||||
|
class GatewayApiSmsProvider implements SmsProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getLabel(): string {
|
||||||
|
return 'GatewayAPI';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getId(): string {
|
||||||
|
return 'gatewayApi';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function sendSms(string $message, string $number, ?string $apiKey = '', ?string $apiToken = ''): void {
|
||||||
|
$curl = curl_init();
|
||||||
|
$postData = [
|
||||||
|
"recipients" => [
|
||||||
|
['msisdn' => $number]
|
||||||
|
],
|
||||||
|
"message" => $message,
|
||||||
|
"label" => "LAM Pro",
|
||||||
|
"sender" => "LAM Pro"
|
||||||
|
];
|
||||||
|
$postJson = json_encode($postData);
|
||||||
|
curl_setopt_array($curl, [
|
||||||
|
CURLOPT_URL => 'https://gatewayapi.eu/rest/mtsms',
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_POSTFIELDS => $postJson,
|
||||||
|
CURLOPT_USERPWD => $apiToken,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Accept: application/json',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
logNewMessage(LOG_DEBUG, 'SMS message for: ' . $number);
|
||||||
|
$response = curl_exec($curl);
|
||||||
|
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($curl);
|
||||||
|
logNewMessage(LOG_DEBUG, 'SMS gateway response: ' . $response);
|
||||||
|
$responseJson = json_decode($response, true);
|
||||||
|
if (($httpCode !== 200)) {
|
||||||
|
logNewMessage(LOG_ERR, 'Unable to send SMS: ' . $response);
|
||||||
|
$message = $responseJson['message'] ?? '';
|
||||||
|
throw new LAMException(null, $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function usesApiToken(): bool {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function usesApiKey(): bool {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -34,7 +34,7 @@ use LAMException;
|
||||||
/**
|
/**
|
||||||
* SMSAPI SMS provider.
|
* SMSAPI SMS provider.
|
||||||
*
|
*
|
||||||
* @package LAM\PLUGINS\CAPTCHA
|
* @package LAM\PLUGINS\SMS
|
||||||
*/
|
*/
|
||||||
class SmsApiSms implements SmsProvider {
|
class SmsApiSms implements SmsProvider {
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace LAM\PLUGINS\SMS;
|
||||||
use LAMException;
|
use LAMException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMS providers.
|
* SMS service.
|
||||||
*
|
*
|
||||||
* @author Roland Gruber
|
* @author Roland Gruber
|
||||||
*/
|
*/
|
|
@ -34,7 +34,7 @@ use LAMException;
|
||||||
/**
|
/**
|
||||||
* Sweego SMS provider.
|
* Sweego SMS provider.
|
||||||
*
|
*
|
||||||
* @package LAM\PLUGINS\CAPTCHA
|
* @package LAM\PLUGINS\SMS
|
||||||
*/
|
*/
|
||||||
class SweegoSms implements SmsProvider {
|
class SweegoSms implements SmsProvider {
|
||||||
|
|
|
@ -70,7 +70,7 @@ include_once(__DIR__ . '/../../lib/status.inc');
|
||||||
/** LAM Pro */
|
/** LAM Pro */
|
||||||
include_once(__DIR__ . '/../../lib/selfService.inc');
|
include_once(__DIR__ . '/../../lib/selfService.inc');
|
||||||
/** SMS */
|
/** SMS */
|
||||||
include_once __DIR__ . '/../../lib/plugins/sms/SmsProvider.inc';
|
include_once __DIR__ . '/../../lib/plugins/sms/SmsService.inc';
|
||||||
|
|
||||||
// start session
|
// start session
|
||||||
if (isFileBasedSession()) {
|
if (isFileBasedSession()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue