priority_cards($types); } function topcard_format($card_list) { $ret = []; foreach ($card_list as $item) { $card = new topcard($item); $item = $card->format(); $item['card_type'] = scard_type($item['card_type']); $ret[] = $item; } return $ret; } function simple_card_type($cardno) { if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) { return SinopecCard; } elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) { return PetroChinaCard; } elseif (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]|19[578])\d{8}$/', $cardno, $matches)) { return ChinaMobileCard; } elseif (preg_match('/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) { return ChinaUnicomCard; } elseif (preg_match('/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) { return ChinaTelecomCard; } else { return UnknownCard; } } function card_type($cardno) { if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) { return SinopecCard; } elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) { return PetroChinaCard; } elseif(preg_match('/^1\d{10}$/',$cardno,$matches)) { $checker = function ($phone) { if (empty($phone)) return false; //手机号不能为空 $url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel={$phone}"; $resp = http_request($url); //获取API返回 的数据 $resp = mb_convert_encoding($resp, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'); //解决中文乱码 $datas = explode('=', $resp); if(count($datas) == 2) { $body = trim($datas[1]); if(preg_match_all("/(\w+):'([^']+)/", $body, $m)) { $res = array_combine($m[1], $m[2]); return $res; } } return false; }; $ret = $checker($cardno); if (empty($ret)) { Log::record("淘宝接口没法使用了,用传统办法识别卡类型",Log::DEBUG); if (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]|19[578])\d{8}$/', $cardno, $matches)) { return ChinaMobileCard; } elseif (preg_match('/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) { return ChinaUnicomCard; } elseif (preg_match('/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) { return ChinaTelecomCard; } else { return UnknownCard; } } elseif($ret['catName'] == '中国联通') { return ChinaUnicomCard; } elseif($ret['catName'] == '中国电信') { return ChinaTelecomCard; } elseif($ret['catName'] == '中国移动') { return ChinaMobileCard; } else { return UnknownCard; } } else { return UnknownCard; } } function oil_type($cardno) { if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) { return SinopecCard; } elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) { return PetroChinaCard; } else { return UnknownCard; } }