|
@@ -2,6 +2,12 @@
|
|
|
|
|
|
namespace mtopcard;
|
|
|
|
|
|
+require_once(BASE_HELPER_PATH . '/mtopcard/card_query.php');
|
|
|
+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');
|
|
|
+
|
|
|
use Log;
|
|
|
|
|
|
#用户卡的类型
|
|
@@ -184,11 +190,6 @@ function scard_type($card_type)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-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') {
|
|
@@ -276,186 +277,6 @@ function oil_type($cardno)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//[$validate,$card_type,$region_no,$isTransfer,$status,$black]
|
|
|
-function tianyan_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));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(array_key_exists($province,Prov2Noes)) {
|
|
|
- return Prov2Noes[$province];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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,UnknownCard,UnknownCard,false];
|
|
|
-
|
|
|
- $resp = json_decode($resp, true);
|
|
|
- if ($resp == false) return [false,UnknownCard,UnknownCard,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);
|
|
|
- $org_type = $type_checker($ispType);
|
|
|
- $isTransfer = $org_type != $card_type;
|
|
|
-
|
|
|
-
|
|
|
- return [true,$card_type,$org_type,$isTransfer];
|
|
|
- } else {
|
|
|
- Log::record("tianyan_transfer phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
|
|
|
- return [false,UnknownCard,UnknownCard,false];
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- [$succ,$_card_type,$_org_type,$_isTransfer] = $tianyan_cardtyper($card_no);
|
|
|
- if($succ) {
|
|
|
- $card_type = $_card_type;
|
|
|
- $org_type = $_org_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])) {
|
|
@@ -465,179 +286,8 @@ function is_validate($status)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function tencent_valid_phone($card_no)
|
|
|
-{
|
|
|
- $type_checker = function ($channel)
|
|
|
- {
|
|
|
- if($channel == 'CMCC') {
|
|
|
- return ChinaMobileCard;
|
|
|
- }
|
|
|
- elseif($channel == 'CTCC') {
|
|
|
- return ChinaTelecomCard;
|
|
|
- }
|
|
|
- elseif($channel == 'CUCC') {
|
|
|
- return ChinaUnicomCard;
|
|
|
- }
|
|
|
- else {
|
|
|
- return UnknownCard;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $validate_checker = function ($code)
|
|
|
- {
|
|
|
- // 字段code:【1 为实号;2为空号;3为停机;4为流量卡;5为沉默号】
|
|
|
- Log::record("status={$code}",Log::DEBUG);
|
|
|
- if (in_array($code, [2, 4])) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $regin_checker = function ($province)
|
|
|
- {
|
|
|
- if(empty($province)) return -1;
|
|
|
- $endtxts= ["省","市","自治区","特别行政区"];
|
|
|
-
|
|
|
- foreach ($endtxts as $endtxt)
|
|
|
- {
|
|
|
- if(strpos($province, $endtxt) === false) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- $province = mb_strcut($province, 0, strrpos($province, $endtxt));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(array_key_exists($province,Prov2Noes)) {
|
|
|
- return Prov2Noes[$province];
|
|
|
- } else {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $api_function = function ($card_no, &$card_type, &$validate, &$region_no,&$status) use($type_checker, $validate_checker, $regin_checker)
|
|
|
- {
|
|
|
- $secretId = 'AKIDkd6sT6C4765LtYN1W2fN2WC2Ynr42acemjQW';
|
|
|
- $secretKey = 'dupQeU838dhuQ8uDP2bi81nQNb5wt9KW1qLP7eWu';
|
|
|
- $source = 'market';
|
|
|
-
|
|
|
- // 签名
|
|
|
- $datetime = gmdate('D, d M Y H:i:s T');
|
|
|
- $signStr = sprintf("x-date: %s\nx-source: %s", $datetime, $source);
|
|
|
- $sign = base64_encode(hash_hmac('sha1', $signStr, $secretKey, true));
|
|
|
- $auth = sprintf('hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"', $secretId, $sign);
|
|
|
- $header = [
|
|
|
- "X-Source: {$source}",
|
|
|
- "X-Date: {$datetime}",
|
|
|
- "Authorization: {$auth}",
|
|
|
- ];
|
|
|
- $data['number'] = $card_no;
|
|
|
- $url = 'https://service-empgc6lp-1256724964.sh.apigw.tencentcs.com/release/query';
|
|
|
- $net_err = 0;
|
|
|
- $resp = http_request($url, $data, 'GET',false, $header,$net_err);
|
|
|
-
|
|
|
- if ($resp == false) return false;
|
|
|
-
|
|
|
- $resp = json_decode($resp, true);
|
|
|
- if ($resp == false) return false;
|
|
|
-
|
|
|
- if ($resp['ret'] == 200)
|
|
|
- {
|
|
|
- $data = $resp['data'];
|
|
|
- $code = intval($data['code']);
|
|
|
- $extend = $data['extend'];
|
|
|
- $status = $code;
|
|
|
- $card_type = $type_checker($extend['isp']);
|
|
|
- $validate = $validate_checker($code);
|
|
|
- $region_no = $regin_checker($extend['prov']);
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- Log::record("tencent_valid phone:{$card_no}", Log::DEBUG);
|
|
|
- return false;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $validate = true;
|
|
|
- $card_type = card_type($card_no,$region_no);
|
|
|
- $region_no = -1;
|
|
|
- $status = 6;
|
|
|
-
|
|
|
- $ret = $api_function($card_no, $card_type, $validate, $region_no, $status);
|
|
|
- if($ret)
|
|
|
- {
|
|
|
- return [$validate,$card_type,$region_no,$status];
|
|
|
- }
|
|
|
- return [$validate,$card_type,-1,$status];
|
|
|
-}
|
|
|
-
|
|
|
function valid_phone($card_no)
|
|
|
{
|
|
|
- $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;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $time_checker = function ($update_time)
|
|
|
- {
|
|
|
- //90 天以内数据有效
|
|
|
- $delta = time() - intval($update_time);
|
|
|
- return $delta < 360 * 86400 && $delta >= 0;
|
|
|
- };
|
|
|
-
|
|
|
- $pinfo_getter = function ($card_no) use ($validate_checker,$time_checker)
|
|
|
- {
|
|
|
- $mod_card = Model('card_info');
|
|
|
- $info = $mod_card->getCardInfo($card_no);
|
|
|
-
|
|
|
- if(empty($info)) {
|
|
|
- return [false,[]];
|
|
|
- }
|
|
|
- elseif($time_checker($info['update_time'])) {
|
|
|
- $mod_card->where(['card_no' => $card_no])->update(['using_times' => $info['using_times'] + 1]);
|
|
|
-
|
|
|
- $card_type = intval($info['card_type']);
|
|
|
- $region_no = intval($info['regin']);
|
|
|
- $isTransfer = intval($info['transfer']) == 0 ? false : true;
|
|
|
- $status = intval($info['card_state']);
|
|
|
- $black = intval($info['black']);
|
|
|
- $validate = $validate_checker($status);
|
|
|
-
|
|
|
- $result = [$validate,$card_type,$region_no,$isTransfer,$status,$black];
|
|
|
- return [true,$result];
|
|
|
- }
|
|
|
- else {
|
|
|
- return [false,[]];
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $pinfo_updator = function ($card_no,$card_type,$org_type,$region_no,$isTransfer,$status)
|
|
|
- {
|
|
|
- $mod_card = Model('card_info');
|
|
|
- $transfer = $isTransfer == true ? 1 : 0;
|
|
|
- $mod_card->replace_card($card_no,$card_type,$org_type,$region_no,$transfer,$status);
|
|
|
- };
|
|
|
-
|
|
|
- $validate = true;
|
|
|
- $black = 0;
|
|
|
-
|
|
|
- $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,$black];
|
|
|
- }
|
|
|
-
|
|
|
- [$succ,$result] = $pinfo_getter($card_no);
|
|
|
- if($succ) return $result;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// if($succ) $pinfo_updator($card_no,$card_type,$org_type,$region_no,$isTransfer,$status);
|
|
|
-
|
|
|
+ $query = new card_query();
|
|
|
+ return $query->validate($card_no);
|
|
|
}
|