本文介紹一個穩定運行多年的免費手機歸屬地查詢 API(SAE 平台),支援三大運營商 13/14/15/17/18 號段,提供 JSON 與 XML 兩種輸出格式,適合驗證碼發送、風控分析、用戶畫像等場景。
GET https://appyun.sinaapp.com/index.php?app=mobile&controller=index&action=api
參數:
mobile 必填 11 位手機號 或 7 位號段(如 13800138000 / 1335586)
outfmt 必填 json | xml
app/controller/action 固定值 mobile/index/api
{
"id": "80012",
"Mobile": "13800138000",
"Province": "北京",
"City": "北京",
"AreaCode": "010",
"PostCode": "100000",
"Operators": "中國移動",
"Card": "GSM"
}
<?xml version="1.0" encoding="utf-8"?>
<QueryResponse>
<Mobile>13800138000</Mobile>
<QueryResult>True</QueryResult>
<Province>北京</Province>
<City>北京</City>
<AreaCode>010</AreaCode>
<PostCode>100000</PostCode>
<Operators>中國移動</Operators>
<Card>GSM</Card>
</QueryResponse>
function getMobileInfo($mobile) {
$url = 'https://appyun.sinaapp.com/index.php?app=mobile&controller=index&action=api&outfmt=json&mobile=' . urlencode($mobile);
$response = @file_get_contents($url);
if ($response === false) return ['error' => 'Network error'];
$data = json_decode($response, true);
return $data ?: ['error' => 'Invalid JSON'];
}
// 使用
$info = getMobileInfo('13800138000');
if (isset($info['Province'])) {
echo "歸屬地:{$info['Province']} {$info['City']} {$info['Operators']}";
}
stream_context_create(['http'=>['timeout'=>3]]),失敗指數退避重試 2-3 次。免費 API 適合開發測試、低頻內部工具;核心業務務必自建或採購商業級 SLA 服務。