Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@antonshell
Created July 5, 2018 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonshell/839acf83835c8451f420ed71d2302d89 to your computer and use it in GitHub Desktop.
Save antonshell/839acf83835c8451f420ed71d2302d89 to your computer and use it in GitHub Desktop.
Yandex money sms parser
<?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