-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
43 lines (32 loc) · 1.25 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Yandex Money SMS credentials parser.
*
* @param string $message
* @return array
*/
function parseYandexMoneySMS(string $message) :array
{
// Get confirm code from string
$confirmCodeRegex = '/(?<![\d.,])\d{4,6}(?![\d.,])/m';
preg_match_all($confirmCodeRegex, $message, $confirmCodeMatches, PREG_SET_ORDER, 0);
[$confirmCode] = count($confirmCodeMatches) ? reset($confirmCodeMatches) : null;
// Get amount from string
$amountRegex = '/\d+[.,]\d+/m';
preg_match_all($amountRegex, $message, $amountMatches, PREG_SET_ORDER, 0);
[$amount] = count($amountMatches) ? reset($amountMatches) : null;
// Get wallet number from string
$walletNumberRegex = '/[0-9]{13,15}/m';
preg_match_all($walletNumberRegex, $message, $walletNumberMatches, PREG_SET_ORDER, 0);
[$walletNumber] = count($walletNumberMatches) ? reset($walletNumberMatches) : null;
// Return result data
$data = [
'confirmCode' => $confirmCode,
'amount' => $amount,
'walletNumber' => $walletNumber
];
return $data;
}
$message = "Пароль: 6105 Спишется 1507,54р. Перевод на счет 410017866772740";
$result = parseYandexMoneySMS($message);
print_r($result); // Array ( [confirmCode] => 6105 [amount] => 1507,54 [walletNumber] => 410017866772740 )