Created
July 5, 2018 15:30
-
-
Save antonshell/839acf83835c8451f420ed71d2302d89 to your computer and use it in GitHub Desktop.
Yandex money sms parser
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 | |
// generator is here: | |
// https://funpay.ru/yandex/emulator | |
function parseMessage($message){ | |
//code | |
preg_match("/[' '][0-9]{4}['\n']/", $message, $code); | |
$code = $code[0] ?? ''; | |
$code = trim($code); | |
// amount | |
preg_match("/[' '][0-9]{1,}[','][0-9]{2}['р.']/u", $message, $amountDouble); | |
$amountDouble = $amountDouble[0] ?? ''; | |
$amountDouble = mb_substr($amountDouble, 0, -1); | |
preg_match("/[' '][0-9]{1,}['р.']/u", $message, $amountInt); | |
$amountInt = $amountInt[0] ?? ''; | |
$amountInt = mb_substr($amountInt, 0, -1); | |
$amount = $amountDouble ?: $amountInt; | |
// account | |
preg_match("/[0-9]{14}/", $message, $account); | |
$account = $account[0] ?? ''; | |
return [ | |
'code' => $code, | |
'amount' => $amount, | |
'account' => $account, | |
]; | |
} | |
$message = 'Пароль: 0122 | |
Спишется 2010,06р. | |
Перевод на счет 41001664447777'; | |
$data = parseMessage($message); | |
echo json_encode($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment