Last active
February 16, 2020 20:02
-
-
Save wavilov/951300d96494c294f144093c4723237d to your computer and use it in GitHub Desktop.
Тестовое на внимательного разработчика FunPay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHP version 7 | |
* | |
* Парсинг смс Яндекс.Денег | |
* | |
* @category Tools | |
* @package FunPay vacancy | |
* @author sdm210 <wavilov@gmail.com> | |
* @license Non commercial | |
* @link https://github.com/wavilov | |
*/ | |
function cutAround($text, $fragment) { | |
$temp = mb_substr($text, 0, mb_strpos($text, $fragment)); | |
$temp .= mb_substr($text, mb_strpos($text, $fragment) + mb_strlen($fragment)); | |
return $temp; | |
} | |
function yandexParse($smsText) { | |
if (!preg_match('/\d{15}/', $smsText, $matches)) { | |
return 'Не смогла найти кошелёк'; | |
} | |
$wallet = $matches[0]; | |
$smsText = cutAround($smsText, $matches[0]); | |
if (!preg_match('/\d+(\.|,)?\d+ ?(р\.|руб)/', $smsText, $matches)) { | |
return 'Не смогла найти сумму'; | |
} | |
$amountText = str_replace(',', '.', mb_substr($matches[0], 0, mb_strpos($matches[0], ' '))); | |
$amountFloat = floatval($amountText); | |
$smsText = cutAround($smsText, $matches[0]); | |
if (!preg_match('/\d{4}/', $smsText, $matches)) { | |
return 'Не смогла найти пароль'; | |
} | |
$password = $matches[0]; | |
return [$password, $amountFloat, $wallet]; | |
} | |
$smsText = 'Пароль: 8677 | |
Спишется 11,06 р. | |
Перевод на счет 410019205394564'; | |
print_r(yandexParse($smsText)); | |
print_r("\n\n"); | |
$smsText = 'С кошелька 410019205394564 снимем 1144р. Цифровой код "8677". Покупайте наших слонов!'; | |
print_r(yandexParse($smsText)); | |
print_r("\n\n"); | |
$smsText = 'Ход конём! Расход бабла 8611 рублей равен твоем паролю 8611. (Кошелёк 861186118611861). Попробуй-ка распарси!'; | |
print_r(yandexParse($smsText)); | |
print_r("\n\n"); | |
$smsText = 'К оплате ТУТСЛОМАЛОСЬ рубля, | |
Пароль 1232, кошелёк 410019205394564'; | |
print_r(yandexParse($smsText) . "\n\n"); | |
print_r("\n"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment