split sms characters to 160

This commit is contained in:
Ibnu Maksum 2023-12-12 13:36:00 +07:00
parent dd4329ad3d
commit b7c663f4ee
No known key found for this signature in database
GPG key ID: 7FC82848810579E5

View file

@ -24,19 +24,39 @@ class Message
global $config; global $config;
run_hook('send_sms'); #HOOK run_hook('send_sms'); #HOOK
if (!empty($config['sms_url'])) { if (!empty($config['sms_url'])) {
if (strlen($config['sms_url']) > 4 && substr($config['sms_url'], 0, 4) != "http") { if (strlen($txt) > 160) {
try{ $txts = str_split($txt, 160);
$mikrotik = Mikrotik::info($config['sms_url']); foreach ($txts as $txt) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); if (strlen($config['sms_url']) > 4 && substr($config['sms_url'], 0, 4) != "http") {
Mikrotik::sendSMS($client, $phone, $txt); try {
}catch(Exception $e){ $mikrotik = Mikrotik::info($config['sms_url']);
// ignore, add to logs $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
_log("Failed to send SMS using Mikrotik.\n". $e->getMessage(), 'SMS', 0); Mikrotik::sendSMS($client, $phone, $txt);
} catch (Exception $e) {
// ignore, add to logs
_log("Failed to send SMS using Mikrotik.\n" . $e->getMessage(), 'SMS', 0);
}
} else {
$smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']);
$smsurl = str_replace('[text]', urlencode($txt), $smsurl);
Http::getData($smsurl);
}
} }
} else { } else {
$smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']); if (strlen($config['sms_url']) > 4 && substr($config['sms_url'], 0, 4) != "http") {
$smsurl = str_replace('[text]', urlencode($txt), $smsurl); try {
Http::getData($smsurl); $mikrotik = Mikrotik::info($config['sms_url']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::sendSMS($client, $phone, $txt);
} catch (Exception $e) {
// ignore, add to logs
_log("Failed to send SMS using Mikrotik.\n" . $e->getMessage(), 'SMS', 0);
}
} else {
$smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']);
$smsurl = str_replace('[text]', urlencode($txt), $smsurl);
Http::getData($smsurl);
}
} }
} }
} }
@ -87,7 +107,8 @@ class Message
return "$via: $msg"; return "$via: $msg";
} }
public static function sendInvoice($cust, $trx){ public static function sendInvoice($cust, $trx)
{
global $config; global $config;
$textInvoice = Lang::getNotifText('invoice_paid'); $textInvoice = Lang::getNotifText('invoice_paid');
$textInvoice = str_replace('[[company_name]]', $config['CompanyName'], $textInvoice); $textInvoice = str_replace('[[company_name]]', $config['CompanyName'], $textInvoice);