PHP 檢測銀行卡賬號

wml_macho發表於2019-07-25

1.未經過大量測試(可能不太嚴謹)


public function __luhm($s) {
$strlen = strlen($s);
    if($strlen < 15 || $strlen > 20){
      return false;
}

if(!preg_match("/^\d{15}$/i",$s) && !preg_match("/^\d{16}$/i",$s) && !preg_match("/^\d{17}$/i",$s) && !preg_match("/^\d{18}$/i",$s) && !preg_match("/^\d{19}$/i",$s)){
      return false;
}
 $n = 0;
 for ($i = strlen($s); $i >= 1; $i--) {
     $index=$i-1;
     //偶數位
     if ($i % 2==0) {
         $n += $s{$index};
     } else {//奇數位
         $t = $s{$index} * 2;
         if ($t > 9) {
             $t = (int)($t/10)+ $t%10;
         }
         $n += $t;
     }
 }
 return ($n % 10) == 0;
}

2.網上找的介面(未測試)

function bankCard($cardid){

 $card = file_get_contents("https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?cardNo={$cardid}&cardBinCheck=true");

 $bankCard = json_decode($card,ture);

 $bank = array(

 "CDB"=>"國家開發銀行","ICBC"=>"中國工商銀行","ABC"=>"中國農業銀行","BOC"=>"中國銀行","CCB"=>"中國建設銀行","PSBC"=>"中國郵政儲蓄銀行","COMM"=>"交通銀行","CMB"=>"招商銀行","SPDB"=>"上海浦東發展銀行","CIB"=>"興業銀行","HXBANK"=>"華夏銀行","GDB"=>"廣東發展銀行","CMBC"=>"中國民生銀行","CITIC"=>"中信銀行","CEB"=>"中國光大銀行","EGBANK"=>"恆豐銀行","CZBANK"=>"浙商銀行","BOHAIB"=>"渤海銀行","SPABANK"=>"平安銀行","SHRCB"=>"上海農村商業銀行","YXCCB"=>"玉溪市商業銀行","YDRCB"=>"堯都農商行","BJBANK"=>"北京銀行","SHBANK"=>"上海銀行","JSBANK"=>"江蘇銀行","HZCB"=>"杭州銀行","NJCB"=>"南京銀行","NBBANK"=>"寧波銀行","HSBANK"=>"徽商銀行","CSCB"=>"長沙銀行","CDCB"=>"成都銀行","CQBANK"=>"重慶銀行","DLB"=>"大連銀行","NCB"=>"南昌銀行","FJHXBC"=>"福建海峽銀行","HKB"=>"漢口銀行",

 "WZCB"=>"溫州銀行","QDCCB"=>"青島銀行","TZCB"=>"台州銀行","JXBANK"=>"嘉興銀行","CSRCB"=>"常熟農村商業銀行","NHB"=>"南海農村信用聯社","CZRCB"=>"常州農村信用聯社","H3CB"=>"內蒙古銀行","SXCB"=>"紹興銀行","SDEB"=>"順德農商銀行","WJRCB"=>"吳江農商銀行","ZBCB"=>"齊商銀行","GYCB"=>"貴陽市商業銀行","ZYCBANK"=>"遵義市商業銀行","HZCCB"=>"湖州市商業銀行","DAQINGB"=>"龍江銀行","JINCHB"=>"晉城銀行JCBANK","ZJTLCB"=>"浙江泰隆商業銀行","GDRCC"=>"廣東省農村信用社聯合社","DRCBCL"=>"東莞農村商業銀行","MTBANK"=>"浙江民泰商業銀行","GCB"=>"廣州銀行","LYCB"=>"遼陽市商業銀行","JSRCU"=>"江蘇省農村信用聯合社","LANGFB"=>"廊坊銀行","CZCB"=>"浙江稠州商業銀行","DYCB"=>"德陽商業銀行","JZBANK"=>"晉中市商業銀行","BOSZ"=>"蘇州銀行","GLBANK"=>"桂林銀行","URMQCCB"=>"烏魯木齊市商業銀行","CDRCB"=>"成都農商銀行",

 "ZRCBANK"=>"張家港農村商業銀行","BOD"=>"東莞銀行","LSBANK"=>"萊商銀行","BJRCB"=>"北京農村商業銀行","TRCB"=>"天津農商銀行","SRBANK"=>"上饒銀行","FDB"=>"富滇銀行","CRCBANK"=>"重慶農村商業銀行","ASCB"=>"鞍山銀行","NXBANK"=>"寧夏銀行","BHB"=>"河北銀行","HRXJB"=>"華融湘江銀行","ZGCCB"=>"自貢市商業銀行","YNRCC"=>"雲南省農村信用社","JLBANK"=>"吉林銀行","DYCCB"=>"東營市商業銀行","KLB"=>"崑崙銀行","ORBANK"=>"鄂爾多斯銀行","XTB"=>"邢臺銀行","JSB"=>"晉商銀行","TCCB"=>"天津銀行","BOYK"=>"營口銀行","JLRCU"=>"吉林農信","SDRCU"=>"山東農信","XABANK"=>"西安銀行","HBRCU"=>"河北省農村信用社","NXRCU"=>"寧夏黃河農村商業銀行","GZRCU"=>"貴州省農村信用社","FXCB"=>"阜新銀行","HBHSBANK"=>"湖北銀行黃石分行","ZJNX"=>"浙江省農村信用社聯合社","XXBANK"=>"新鄉銀行","HBYCBANK"=>"湖北銀行宜昌分行",

 "LSCCB"=>"樂山市商業銀行","TCRCB"=>"江蘇太倉農村商業銀行","BZMD"=>"駐馬店銀行","GZB"=>"贛州銀行","WRCB"=>"無錫農村商業銀行","BGB"=>"廣西北部灣銀行","GRCB"=>"廣州農商銀行","JRCB"=>"江蘇江陰農村商業銀行","BOP"=>"平頂山銀行","TACCB"=>"泰安市商業銀行","CGNB"=>"南充市商業銀行","CCQTGB"=>"重慶三峽銀行","XLBANK"=>"中山小欖村鎮銀行","HDBANK"=>"邯鄲銀行","KORLABANK"=>"庫爾勒市商業銀行","BOJZ"=>"錦州銀行","QLBANK"=>"齊魯銀行","BOQH"=>"青海銀行","YQCCB"=>"陽泉銀行","SJBANK"=>"盛京銀行","FSCB"=>"撫順銀行","ZZBANK"=>"鄭州銀行","SRCB"=>"深圳農村商業銀行","BANKWF"=>"濰坊銀行","JJBANK"=>"九江銀行","JXRCU"=>"江西省農村信用","HNRCU"=>"河南省農村信用","GSRCU"=>"甘肅省農村信用","SCRCU"=>"四川省農村信用","GXRCU"=>"廣西省農村信用","SXRCCU"=>"陝西信合","WHRCB"=>"武漢農村商業銀行","YBCCB"=>"宜賓市商業銀行",

 "KSRB"=>"崑山農村商業銀行","SZSBK"=>"石嘴山銀行","HSBK"=>"衡水銀行","XYBANK"=>"信陽銀行","NBYZ"=>"鄞州銀行","ZJKCCB"=>"張家口市商業銀行","XCYH"=>"許昌銀行","JNBANK"=>"濟寧銀行","CBKF"=>"開封市商業銀行","WHCCB"=>"威海市商業銀行","HBC"=>"湖北銀行","BOCD"=>"承德銀行","BODD"=>"丹東銀行","JHBANK"=>"金華銀行","BOCY"=>"朝陽銀行","LSBC"=>"臨商銀行","BSB"=>"包商銀行","LZYH"=>"蘭州銀行","BOZK"=>"周口銀行","DZBANK"=>"德州銀行","SCCB"=>"三門峽銀行","AYCB"=>"安陽銀行","ARCU"=>"安徽省農村信用社","HURCB"=>"湖北省農村信用社","HNRCC"=>"湖南省農村信用社","NYNB"=>"廣東南粵銀行","LYBANK"=>"洛陽銀行","NHQS"=>"農信銀清算中心","CBBQS"=>"城市商業銀行資金清算中心"

 );

 $bc = $bank[$bankCard['bank']];

 if($bc == '') return '卡號不存在 ';

 else return $bc;

}
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章