diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-07-18 16:41:11 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-07-18 16:41:11 +0300 |
commit | 43895519a718810fc0ac0defd76047e0fd6229d9 (patch) | |
tree | f79996c40cb6a80cd2baa8af5b4a3bcf1c0ca413 /localwebsite/handlers/ModemHandler.php | |
parent | 9b40fbdd31f9366cf4fba4db04e85aa26e7c8a04 (diff) |
lws: fix sms sending on short numbers
Diffstat (limited to 'localwebsite/handlers/ModemHandler.php')
-rw-r--r-- | localwebsite/handlers/ModemHandler.php | 38 |
1 files changed, 21 insertions, 17 deletions
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']); |