$number = '6214832018989180'; $parity = strlen($number) % 2; $total = 0; // Split each digit into an array $digits = str_split($number); foreach ($digits as $key => $digit) { // Foreach digit // for every second digit from the right most, we must multiply * 2 if (($key % 2) == $parity) $digit = ($digit * 2); // each digit place is it's own number (11 is really 1 + 1) if ($digit >= 10) { // split the digits $digit_parts = str_split($digit); // add them together $digit = $digit_parts[0] + $digit_parts[1]; } // add them to the total $total += $digit; } $r = ($total % (false ? 5 : 10) == 0 ? true : false);
解决方法使用支付宝接口:
https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=6214832018989180 &cardBinCheck=true
可查询银行卡相关信息,从而验证银行卡有效