phpnuxbill/system/autoload/Message.php

76 lines
2.4 KiB
PHP
Raw Normal View History

2023-03-06 15:48:05 +08:00
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
class Message
{
public static function sendTelegram($txt)
{
global $config;
run_hook('send_telegram'); #HOOK
if (!empty($config['telegram_bot']) && !empty($config['telegram_target_id'])) {
Http::getData('https://api.telegram.org/bot' . $config['telegram_bot'] . '/sendMessage?chat_id=' . $config['telegram_target_id'] . '&text=' . urlencode($txt));
2023-03-06 15:48:05 +08:00
}
}
public static function sendSMS($phone, $txt)
{
global $config;
run_hook('send_sms'); #HOOK
if (!empty($config['sms_url'])) {
$smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']);
$smsurl = str_replace('[text]', urlencode($txt), $smsurl);
Http::getData($smsurl);
2023-03-06 15:48:05 +08:00
}
}
public static function sendWhatsapp($phone, $txt)
{
global $config;
run_hook('send_whatsapp'); #HOOK
if (!empty($config['wa_url'])) {
$waurl = str_replace('[number]', urlencode($phone), $config['wa_url']);
$waurl = str_replace('[text]', urlencode($txt), $waurl);
Http::getData($waurl);
2023-03-06 15:48:05 +08:00
}
}
2023-08-14 15:16:03 +08:00
public static function sendPackageNotification($phone, $name, $package, $message, $via)
2023-03-06 15:48:05 +08:00
{
2023-08-14 15:16:03 +08:00
$msg = str_replace('[[name]]', "*$name*", $message);
$msg = str_replace('[[package]]', "*$package*", $msg);
2023-03-06 15:48:05 +08:00
if (
!empty($phone) && strlen($phone) > 5
2023-08-14 15:16:03 +08:00
&& !empty($message) && in_array($via, ['sms', 'wa'])
2023-03-06 15:48:05 +08:00
) {
if ($via == 'sms') {
Message::sendSMS($phone, $msg);
} else if ($via == 'wa') {
Message::sendWhatsapp($phone, $msg);
}
}
2023-08-14 15:16:03 +08:00
return "$via: $msg";
2023-03-06 15:48:05 +08:00
}
2023-08-24 12:35:23 +08:00
public static function sendBalanceNotification($phone, $name, $balance, $message, $via)
{
$msg = str_replace('[[name]]', "*$name*", $message);
$msg = str_replace('[[balance]]', "*" . Lang::moneyFormat($balance) . "*", $msg);
if (
!empty($phone) && strlen($phone) > 5
&& !empty($message) && in_array($via, ['sms', 'wa'])
) {
if ($via == 'sms') {
Message::sendSMS($phone, $msg);
} else if ($via == 'wa') {
Message::sendWhatsapp($phone, $msg);
}
}
return "$via: $msg";
}
2023-03-06 15:48:05 +08:00
}