From 43895519a718810fc0ac0defd76047e0fd6229d9 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 18 Jul 2022 16:41:11 +0300 Subject: lws: fix sms sending on short numbers --- localwebsite/handlers/ModemHandler.php | 38 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'localwebsite') diff --git a/localwebsite/handlers/ModemHandler.php b/localwebsite/handlers/ModemHandler.php index a874a94..aca69a3 100644 --- a/localwebsite/handlers/ModemHandler.php +++ b/localwebsite/handlers/ModemHandler.php @@ -200,25 +200,29 @@ class ModemHandler extends RequestHandler }; $phone = preg_replace('/\s+/', '', $phone); - $country = null; - if (!startsWith($phone, '+')) - $country = 'RU'; - - $phoneUtil = PhoneNumberUtil::getInstance(); - try { - $number = $phoneUtil->parse($phone, $country); - } catch (NumberParseException $e) { - debugError(__METHOD__.': failed to parse number '.$phone.': '.$e->getMessage()); - $go_back('Неверный номер ('.$e->getMessage().')'); - return; - } - if (!$phoneUtil->isValidNumber($number)) { - $go_back('Неверный номер'); - return; - } + // при отправке смс на короткие номера не надо использовать libphonenumber и вот это вот всё + if (strlen($phone) > 4) { + $country = null; + if (!startsWith($phone, '+')) + $country = 'RU'; + + $phoneUtil = PhoneNumberUtil::getInstance(); + try { + $number = $phoneUtil->parse($phone, $country); + } catch (NumberParseException $e) { + debugError(__METHOD__.': failed to parse number '.$phone.': '.$e->getMessage()); + $go_back('Неверный номер ('.$e->getMessage().')'); + return; + } - $phone = $phoneUtil->format($number, PhoneNumberFormat::E164); + if (!$phoneUtil->isValidNumber($number)) { + $go_back('Неверный номер'); + return; + } + + $phone = $phoneUtil->format($number, PhoneNumberFormat::E164); + } $cfg = $config['modems'][$selected]; $e3372 = new E3372($cfg['ip'], $cfg['legacy_token_auth']); -- cgit v1.2.3