'北京', 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 => '新疆' ]; #空号拦截状态 const CardState = [ 0 => '空号', 1 => '实号', 2 => '停机', 3 => '库无', 4 => '沉默号', 5 => '风险号' ]; function month_stamp($time=null) : int { $date = getdate($time); $stamp = $date['year'] * 100 + $date['mon']; return $stamp; } function topcard_type($str_type) { if(empty($str_type)) { return UnknownCard; } $str_type = trim(strtolower($str_type)); if($str_type == 'petrochina') { //中石油 return PetroChinaCard; } elseif ($str_type == 'sinopec') { //中石化 return SinopecCard; } elseif ($str_type == 'chinamobile') { //中石化 return ChinaMobileCard; } elseif($str_type == 'chinaunicom') { //手机卡 return ChinaUnicomCard; } elseif($str_type == 'chinatelecom') { //手机卡 return ChinaTelecomCard; } elseif($str_type == 'phone') { //手机卡 return PhoneCard; } elseif($str_type == 'third') { return ThirdRefillCard; } else { return UnknownCard; } } function scard_type($card_type) { if($card_type == PetroChinaCard) { //中石油 return 'petrochina'; } elseif ($card_type == SinopecCard) { //中石化 return 'sinopec'; } elseif ($card_type == ChinaMobileCard) { //中石化 return 'chinamobile'; } elseif($card_type == ChinaUnicomCard ) { //手机卡 return 'chinaunicom'; } elseif($card_type == ChinaTelecomCard) { //手机卡 return 'chinatelecom'; } elseif($card_type == PhoneCard) { //手机卡 return 'phone'; } elseif($card_type == ThirdRefillCard) { return 'third'; } else { return 'unknown'; } } require_once(BASE_HELPER_PATH . '/mtopcard/topcard.php'); require_once(BASE_HELPER_PATH . '/mtopcard/user_topcards.php'); require_once(BASE_HELPER_PATH . '/mtopcard/CardPaper.php'); require_once(BASE_HELPER_PATH . '/mtopcard/cards_helper.php'); function priority_cards($member_id, $page_type = '') { if($page_type == 'oil') { $types = [PetroChinaCard,SinopecCard]; } elseif($page_type == 'phone') { $types = [PhoneCard]; } else { $types = [PetroChinaCard,SinopecCard,PhoneCard]; } $user_cards = new user_topcards($member_id); return $user_cards->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; } elseif (preg_match('/^1\d{10}$/', $cardno, $matches)) { return PhoneCard; } else { return UnknownCard; } } function card_type($cardno,&$regin_no) { $regin_no = -1; 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)) { $regin_no = -1; 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; } } 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; } } function valid_phone($card_no) { $type_checker = function ($channel) { if($channel == '联通') { return ChinaUnicomCard; } elseif($channel == '电信') { return ChinaTelecomCard; } elseif($channel == '移动') { return ChinaMobileCard; } else { return UnknownCard; } }; $validate_checker = function ($status) { // "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号 Log::record("status={$status}",Log::DEBUG); if (in_array($status, [0,5])) { return false; } else { return true; } }; $regin_checker = function ($area) { if(empty($area)) return -1; $areas = explode('-',$area); if(count($areas) > 0) { $province = $areas[0]; $endtxts= ["省","市","自治区","特别行政区"]; foreach ($endtxts as $endtxt) { if(strpos($province, $endtxt) === false) { continue; } else { $province = mb_strcut($province, 0, strrpos($province, $endtxt)); } } $region = array_search($province, ProvinceList); return $region; } else { return -1; } }; $ali = function ($card_no, &$validate, &$region_no,&$status) use ($validate_checker, $regin_checker): bool { $url = 'https://mobileempty.shumaidata.com/mobileempty'; $params['mobile'] = $card_no; $headers = ["Authorization:APPCODE " . '8f92d951293f4d2ea48ff86d5a70c537']; $net_err = 0; $resp = http_request($url, $params, 'GET', false, $headers,$net_err); if ($resp == false) return false; $resp = json_decode($resp, true); if ($resp == false) return false; if ($resp['code'] == 200) { $data = $resp['data']; $status = intval($data['status']); $validate = $validate_checker(intval($data['status'])); $region_no = $regin_checker($data['area']); return true; } else { Log::record("ali_valid phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG); return false; } }; $tianyan = function ($card_no, &$validate, &$region_no,&$status) use ($validate_checker, $regin_checker): bool { $url = 'https://api.shumaidata.com/v4/mobile_empty/check'; $appid = '2Xfa6IFIPv0sVUjy'; $appSecurity = '2Xfa6IFIPv0sVUjynOddsfh6KXfbyJ84'; $cur = microtime (true); $data['appid'] = $appid; $data['timestamp'] = intval($cur * 1000); $content = "{$appid}&{$data['timestamp']}&{$appSecurity}"; $data['sign'] = md5($content); $data['mobile'] = $card_no; $net_err = 0; $resp = http_request($url, $data, 'GET',false, [],$net_err); if ($resp == false) return false; $resp = json_decode($resp, true); if ($resp == false) return false; if ($resp['code'] == 200) { $data = $resp['data']; $status = intval($data['status']); $validate = $validate_checker(intval($data['status'])); $region_no = $regin_checker($data['area']); return true; } else { Log::record("tianyan_valid phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG); return false; } }; $tianyan_cardtyper = function ($card_no) use ($type_checker) { $url = 'https://api.shumaidata.com/v4/mobile-transfer/query'; $appid = '2Xfa6IFIPv0sVUjy'; $appSecurity = '2Xfa6IFIPv0sVUjynOddsfh6KXfbyJ84'; $cur = microtime (true); $data['appid'] = $appid; $data['timestamp'] = intval($cur * 1000); $content = "{$appid}&{$data['timestamp']}&{$appSecurity}"; $data['sign'] = md5($content); $data['mobile'] = $card_no; $net_err = 0; $resp = http_request($url, $data, 'GET',false, [],$net_err); if ($resp == false) return false; $resp = json_decode($resp, true); if ($resp == false) return false; if ($resp['code'] == 200) { $data = $resp['data']; $ispType = $data['ispType']; $newIspType = $data['newIspType']; Log::record("tianyan_transfer phone:{$card_no} ispType:{$ispType} newIspType:{$newIspType}", Log::DEBUG); $card_type = $type_checker($newIspType); $isTransfer = $ispType != $newIspType; return [true,$card_type,$isTransfer]; } else { Log::record("tianyan_transfer phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG); return [false,UnknownCard,false]; } }; $validate = true; $card_type = card_type($card_no,$region_no); $region_no = -1; if($card_type == PetroChinaCard || $card_type == SinopecCard) { return [$validate,$card_type,$region_no,false,1]; } [$succ,$_card_type,$_isTransfer] = $tianyan_cardtyper($card_no); if($succ) { $card_type = $_card_type; $isTransfer = $_isTransfer; } else { $isTransfer = false; } $status = 6; $ret = $tianyan($card_no,$validate,$region_no,$status); if($ret) { return [$validate,$card_type,$region_no,$isTransfer,$status]; } $ret = $ali($card_no,$validate,$region_no,$status); if($ret) { return [$validate,$card_type,$region_no,$isTransfer,$status]; } return [true,$card_type,-1,false,$status]; } function is_validate($status) { if (in_array($status, [0,5])) { return false; } else { return true; } }