Rus*_*wer 6 php payment credit-card luhn
我使用以下PHP代码来计算BPay的CRN:
<?php
function LuhnCalc($number) {
$chars = array_reverse(str_split($number, 1));
$odd = array_intersect_key($chars, array_fill_keys(range(1, count($chars), 2), null));
$even = array_intersect_key($chars, array_fill_keys(range(0, count($chars), 2), null));
$even = array_map(function($n) { return ($n >= 5)?2 * $n - 9:2 * $n; }, $even);
$total = array_sum($odd) + array_sum($even);
return ((floor($total / 10) + 1) * 10 - $total) % 10;
}
print LuhnCalc($_GET['num']);
?>
Run Code Online (Sandbox Code Playgroud)
然而,似乎BPAY是MOD 10的第5版,我找不到任何文档.它似乎与MOD10不一样.
测试的以下数字:
2005,1597,3651,0584,9675
bPAY
2005 = 20052
1597 = 15976
3651 = 36514
0584 = 05840
9675 = 96752
MY CODE
2005 = 20057
1597 = 15974
3651 = 36517
0584 = 05843
9675 = 96752
Run Code Online (Sandbox Code Playgroud)
如您所见,它们都不匹配BPAY数字.
该 PHP 函数将根据 mod10 版本 5 算法生成 BPay 参考号。
谁知道为什么 BPay 不能将其添加到他们的网站上。我只是通过谷歌搜索找到了一个解释,该算法被称为“MOD10V05”而不是“Mod 10 version 5”。
function generateBpayRef($number) {
$number = preg_replace("/\D/", "", $number);
// The seed number needs to be numeric
if(!is_numeric($number)) return false;
// Must be a positive number
if($number <= 0) return false;
// Get the length of the seed number
$length = strlen($number);
$total = 0;
// For each character in seed number, sum the character multiplied by its one based array position (instead of normal PHP zero based numbering)
for($i = 0; $i < $length; $i++) $total += $number{$i} * ($i + 1);
// The check digit is the result of the sum total from above mod 10
$checkdigit = fmod($total, 10);
// Return the original seed plus the check digit
return $number . $checkdigit;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4814 次 |
| 最近记录: |