更多资料请参考:www.woyaocha.net/product/mobile

接口描述

功能描述

获取手机号码段的省市区以及运营商名称,通俗的说就是获取手机号码的归属地及电信运营商名称。

URL 示例

1)http 协议:

POST 方式请求:

Copy

http://cha.ebaitian.cn/api/json?appid=xxx&module=getMobileArea&mobile=xxx&sign=xxx

GET 方式请求:

Copy

http://cha.ebaitian.cn/api/json?type=get&appid=xxx&module=getMobileArea&mobile=xxx&sign=xxx

2)https 协议:

POST 方式请求:

Copy

https://cha.ebaitian.cn/api/json?appid=xxx&module=getMobileArea&mobile=xxx&sign=xxx

GET 方式请求:

Copy

https://cha.ebaitian.cn/api/json?type=get&appid=xxx&module=getMobileArea&mobile=xxx&sign=xxx

请求参数

数据包体

Copy

{"type": "get","appid": "1000xxxx","module": "getMobileArea","mobile": "18918910000","sign": "ecab4881ee80ad3d76bb1da68387428ca752eb885e52621a3129dcf4d9bc4fd4"
}

参数说明

参数 必选 类型 描述
type string 授权接口的请求方式
appid string 授权接口的 AppID,请填写您在我要查官网上申请到的 AppID
module string 目标请求的数据模块,查询手机号码归属地为:getMobileArea
mobile string 目标要查询的手机号码,仅限中国大陆地区11位数手机号码
sign string 请求凭证,具体计算方式见下面的其他说明

其他说明

1)type:可选值 get,如果赋值 get,则以 get 方式提交数据;默认以 post 方式提交数据;
2)sign:签名校验,根据公式 $sign=sha256(appid=$appid&module=getMobileArea&mobile=$mobile&appkey=$appkey) 生成;其中:appkey 为授权接口的 AppKey,请填写您在我要查官网上申请到的 AppKey 。

构造伪代码如下:

Copy

string type = "get"; //请求方式,可以赋值为:post
string appid = "1000xxxx"; //sdkappid 对应的 appid,需要业务方高度保密
string module = "getMobileArea"; //请求的数据模块,此处赋值:getMobileArea
string mobile = "18918910000"; //要查询的手机号码,注意仅能为中国大陆地区11位手机号码
string sign = sha256(appid=1000xxxx&module=getMobileArea&mobile=18918910000&appkey=56cf61af4b7897e704f67deb88ae8f24);

响应参数

数据包体

Copy

{"result":1,"description":"TRUE","flag":"","mobileInfo":{"mobilearea":"上海","mobiletype":"中国电信天翼卡","areacode":"021","zipcode":"200000"}
}

参数说明

参数 必选 类型 描述
result string 接口响应结果:0-失败;1-成功
description string 接口响应描述:一般为 TURE(result=1) 与 FALSE(result=0),或者返回错误信息
flag string 错误说明,没有错误则返回空
mobileInfo object 返回手机号码归属地信息

mobileInfo 参数说明:

参数 必选 类型 描述
mobilearea string 手机号码归属地,即手机号码对应的地区
mobiletype string 电信运营商及号卡类型
areacode string 归属地区号
zipcode string 归属地邮政编码

SDK 及代码示例

PHP SDK

方法一:以 POST 方式请求数据

Copy

//接口参数
$api_url='http://cha.ebaitian.cn/api/json';
$api_appid='1000xxxx';
$api_appkey='56cf61af4b7897e704f67deb88ae8f24';//函数,以POST方式提交数据,PHP需要开启CURL函数;数据传输安全,建议使用
function getMobileArea($mobile){global $api_url,$api_appid,$api_appkey;$posturl=$api_url;$data='appid='.$api_appid.'&module=getMobileArea&mobile='.$mobile;$sign=hash("sha256",$data.'&appkey='.$api_appkey);$postdata=array("appid"=>$api_appid,"appkey"=>$api_appkey,"module"=>"getMobileArea","mobile"=>$mobile,'sign'=>$sign);$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $posturl);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_POST, 1);curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);$output = curl_exec($curl);curl_close($curl);$obj=json_decode($output);$result=$obj->result;if($result==1){$value=$obj->mobileInfo->mobilearea;$value.=','.$obj->mobileInfo->mobiletype;$value.=','.$obj->mobileInfo->areacode;$value.=','.$obj->mobileInfo->zipcode;}else{$value=$obj->flag;}return $value;
}
//调用函数
$mobile='18918910000';
echo getMobileArea($mobile);
exit;

方法二:以 GET 方式请求数据

Copy

//接口参数
$api_url='http://cha.ebaitian.cn/api/json';
$api_appid='1000xxxx';
$api_appkey='56cf61af4b7897e704f67deb88ae8f24';//函数,以GET方式提交数据
function getMobileArea($mobile){global $api_url,$api_appid,$api_appkey;$data='appid='.$api_appid.'&module=getMobileArea&mobile='.$mobile;$sign=hash("sha256",$data.'&appkey='.$api_appkey);$info_get=file_get_contents($api_url.'?type=get&'.$data.'&sign='.$sign);$info_json=json_decode($info_get, true);$result=$info_json['result'];if($result==1){$value=$info_json['mobileInfo']['mobilearea'];$value.=','.$info_json['mobileInfo']['mobiletype'];$value.=','.$info_json['mobileInfo']['areacode'];$value.=','.$info_json['mobileInfo']['zipcode'];}else{$value=$info_json['flag'];}return $value;
}
//调用函数
$mobile='18918910000';
echo getMobileArea($mobile);
exit;

Java SDK

Copy

//以下示例是以 GET 方式请求数据
public class QueryHelper {public static String apiurl="http://cha.ebaitian.cn/api/json";public static String appid="1000xxxx";public static String appkey="56cf61af4b7897e704f67deb88ae8f24";public static String module="getMobileArea";public static String getSHA256Str(String str){MessageDigest messageDigest;String encdeStr = "";try {messageDigest = MessageDigest.getInstance("SHA-256");byte[] hash = messageDigest.digest(str.getBytes("UTF-8"));encdeStr = Hex.encodeHexString(hash);} catch (NoSuchAlgorithmException e) {e.printStackTrace();} catch (UnsupportedEncodingException e) {e.printStackTrace();}return encdeStr;}public static String get(String urlString) {try {URL url = new URL(urlString);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setConnectTimeout(5 * 1000);conn.setReadTimeout(5 * 1000);conn.setDoInput(true);conn.setDoOutput(true);conn.setUseCaches(false);conn.setInstanceFollowRedirects(false);conn.setRequestMethod("GET"); int responseCode = conn.getResponseCode();if (responseCode == 200) {StringBuilder builder = new StringBuilder();BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));for (String s = br.readLine(); s != null; s = br.readLine()) {builder.append(s);}br.close();return builder.toString();}} catch (IOException e) {e.printStackTrace();}return null;}public static String queryMobile(String mobile){String sign=getSHA256Str("appid="+appid+"&module="+module+"&mobile="+mobile+"&appkey="+appkey);String url=apiurl+"?type=get&appid="+appid+"&module="+module+"&mobile="+mobile+"&sign="+sign;return get(url);}
}//使用示例
QueryHelper.queryMobile("18918910000");

Python SDK

Copy

#!/usr/bin/python
# -*- coding: utf-8 -*-
import httplib2
import hashlib
from urllib.parse import urlencode #python3
#from urllib import urlencode #python2apiurl='http://cha.ebaitian.cn/api/json'
appid='1000xxxx'
appkey='56cf61af4b7897e704f67deb88ae8f24'
module='getMobileArea'
mobile='18918910000'
data='appid='+appid+'&module='+module+'&mobile='+mobile
sign_data=data+'&appkey='+appkey# from Crypto.Cipher import AES
# from Crypto.Hash import SHA256
# 256
hash_256 = hashlib.sha256()
hash_256.update(sign_data.encode('utf-8'))
sign = hash_256.hexdigest()postdata = urlencode({'appid':appid,'module':module,'mobile':mobile,'sign':sign})
url = apiurl+'?'+postdata
http = httplib2.Http()
response, content = http.request(url,'GET')
print(content.decode("utf-8"))

Node.js SDK

方法一:以 POST 方式请求数据

Copy

//以 POST 方式提交
var http = require('http');  var querystring = require('querystring');  //参数设置
var appid = '1000xxxx';
var appkey = '56cf61af4b7897e704f67deb88ae8f24';
var module = 'getMobileArea';//目标查询手机号码
var mobile='18918910000';//签名,SHA256 不可直接调用;函数参考下载地址:https://github.com/alexweber/jquery.sha256
var sign = SHA256('appid='+appid+'&module='+module+'&mobile='+mobile+'&appkey='+appkey);//这是需要提交的数据
var post_data = {appid: appid,  module: module,mobile: mobile,sign: sign
};  var content = querystring.stringify(post_data);  var options = {  hostname: 'cha.ebaitian.cn',  port: 80,  path: '/api/json',  method: 'POST',  headers: {  'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'  }
};  var req = http.request(options, function (res) {  console.log('STATUS: ' + res.statusCode);  console.log('HEADERS: ' + JSON.stringify(res.headers));  res.setEncoding('utf8');  res.on('data', function (chunk) {  console.log('BODY: ' + chunk);  //JSON.parse(chunk)});
});  req.on('error', function (e) {  console.log('problem with request: ' + e.message);
});  // write data to request body
req.write(content);  req.end();

方法二:以 GET 方式请求数据

Copy

//以 GET 方式提交
var http = require('http');  var querystring = require('querystring');  //参数设置
var appid = '1000xxxx';
var appkey = '56cf61af4b7897e704f67deb88ae8f24';
var module = 'getMobileArea';//目标查询手机号码
var mobile='18918910000';//签名,SHA256 不可直接调用;函数参考下载地址:https://github.com/alexweber/jquery.sha256
var sign = SHA256('appid='+appid+'&module='+module+'&mobile='+mobile+'&appkey='+appkey);//这是需要提交的数据
var data = {appid: appid, module: module,mobile: mobile,sign: sign
};var content = querystring.stringify(data);  var options = {  hostname: 'cha.ebaitian.cn',  port: 80,  path: '/api/json?' + content,  method: 'GET'
};  var req = http.request(options, function (res) {  console.log('STATUS: ' + res.statusCode);  console.log('HEADERS: ' + JSON.stringify(res.headers));  res.setEncoding('utf8');  res.on('data', function (chunk) {  console.log('BODY: ' + chunk);});
});  req.on('error', function (e) {  console.log('problem with request: ' + e.message);
});  req.end();

C# SDK

Copy

using System;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.Text;public class getMobileInfo{public static string getInfo(string appid, string appkey, string module, string mobile){string url = string.Format("http://cha.ebaitian.cn/api/json?type=get&appid={0}&module={1}&mobile={2}&sgin={3}", appid, module, mobile, sgin);using (WebClient client = new WebClient()){client.Encoding = Encoding.UTF8;return client.DownloadString(url);}}
}string mobileInfo = getMobileInfo.getInfo("1000xxxx", "getMobileArea", "18918910000", "ecab4881ee80ad3d76bb1da68387428ca752eb885e52621a3129dcf4d9bc4fd4", Request.UserHostAddress);
Console.WriteLine(mobileInfo);
Response.Write(mobileInfo);

JavaScript SDK

方法一:以 POST 方式请求数据

Copy

//使用 JQuery 请先加载最新的 JQuery 插件
//参数设置
var apiurl = 'http://cha.ebaitian.cn/api/json';
var appid = '1000xxxx';
var appkey = '56cf61af4b7897e704f67deb88ae8f24';
var module = 'getMobileArea';//目标查询手机号码
var mobile='18918910000';//签名,SHA256 不可直接调用;函数参考下载地址:https://github.com/alexweber/jquery.sha256
var sign = SHA256('appid='+appid+'&module='+module+'&mobile='+mobile+'&appkey='+appkey);//提交数据
$.ajax({url:apiurl,type:'post',dataType:'json',data:{appid:appid,module:module,mobile:mobile,sign:sign},success:function(res){console.log(res);}
});

方法二:以 GET 方式请求数据

Copy

//使用 JQuery 请先加载最新的 JQuery 插件
//参数设置
var apiurl = 'http://cha.ebaitian.cn/api/json';
var appid = '1000xxxx';
var appkey = '56cf61af4b7897e704f67deb88ae8f24';
var module = 'getMobileArea';//目标查询手机号码
var mobile='18918910000';//签名,SHA256 不可直接调用;函数参考下载地址:https://github.com/alexweber/jquery.sha256
var sign = SHA256('appid='+appid+'&module='+module+'&mobile='+mobile+'&appkey='+appkey);//提交数据
$.ajax({url:apiurl,type:'post',dataType:'json',data:{appid:appid,module:module,mobile:mobile,sign:sign},success:function(res){console.log(res);}
});

ASP SDK

Copy

'设置参数
dim apiurl, appid, appkey, module, mobile, sign
apiurl="http://cha.ebaitian.cn/api/json"
appid="1000xxxx'
appkey="56cf61af4b7897e704f67deb88ae8f24"
module="getMobileArea"
mobile="18918910000"'签名,SHA256 不可直接调用;函数参考地址:https://blog.csdn.net/yesoce/article/details/128546
sgin=SHA256("appid=&appid&"&module="&module&"&mobile="&mobile&"&appkey="&appkey)'异步提交数据
function PostHTTPPage(url,data)dim Http set Http=server.createobject("MSXML2.SERVERXMLHTTP.3.0")Http.open "POST",url,falseHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"Http.send(data) if Http.readystate<>4 then exit function End ifPostHTTPPage=bytesToBSTR(Http.responseBody,"UTF-8")set http=nothing if err.number<>0 then err.Clear
End function'提交数据
dim postdata, strTest
postdata="appid=&appid&"&module="&module&"&mobile="&mobile&"&sign="&sign
strTest=PostHTTPPage(apiurl,postdata)'返回结果
response.write(strTest)
response.end

常见问题

API 接口参数为空

此错误返回 JSON 数据如下:

Copy

{"result":0,"description":"API接口参数为空","flag":"appid:sign"
}

解决方法:
1)请检查 appid 及 sign 是否为空;
2)确保 appid 是从官网获取到正确的接口授权;
3)确保 sign 计算生成是正确的。

API 接口参数无效

此错误返回 JSON 数据如下:

Copy

{"result":0,"description":"API接口参数无效","flag":"appid"
}

解决方法:
1)请检查 appid 是否正确;
2)确保 appid 是从官网获取到正确的接口授权。

API 接口授权已到期

此错误返回 JSON 数据如下:

Copy

{"result":0,"description":"API接口授权已到期","flag":"end:2018-12-31 23:59:59"
}

解决方法:
1)请检查 appid 对应接口授权的期限是否过期;
2)如果接口授权过期,请到官网更新(免费用户直接更新,无需续费)或续费(针对商业付费用户)。

签名错误

此错误返回 JSON 数据如下:

Copy

{"result":0,"description":"签名错误","flag":"getMobileArea->sign"
}

解决方法:
1)请检查 sign 签名计算是否正确;
2)签名 sign 根据公式 $sign=sha256(appid=$appid&module=getMobileArea&mobile=$mobile&appkey=$appkey) 生成;其中:appkey 为授权接口的 AppKey,请填写您在我要查官网上申请到的 AppKey 。

请求受限

此错误返回 JSON 数据如下:

Copy

{"result":0,"description":"请求受限","flag":"getMobileArea->daylimit"
}

解决方法:
1)授权接口已超出当前接口产品请求的最大限制;
2)请根据实际使用需求升级您的接口产品。

手机号码查询-整提供 Demo 代码示例及数据专业且全面的 API 查询接口相关推荐

  1. 院校代码/高等学校查询-整提供 Demo 代码示例及数据专业且全面的 API 查询接口

    更多资料请参考:www.woyaocha.net/product/school 接口描述 功能描述 通过院校名称获取院校对应的院校代码/高等学校,或者通过院校代码/高等学校获取对应的院校名称:后期将会 ...

  2. 2019-nCoV肺炎疫情同程查询-完整提供 Demo 代码示例及数据专业且全面的 API 查询接口

    更多资料请参考:www.woyaocha.net/product/trip2019ncov 手机查询链接(已开发好的):www.woyaocha.net/trip2019ncov 接口使用 我要查询 ...

  3. POS 商户编号查询-完整提供 Demo 代码示例及数据专业且全面的 API 查询接口

    更多资料请参考:www.woyaocha.net/product/posmcc 接口描述 功能描述 通过商户编号获取中国大陆地区所有线下收单机构的商户信息,如:收单机构.MCC编码类别.适用费率及商户 ...

  4. 行政区划代码查询-完整提供 Demo 代码示例及数据专业且全面的 API 查询接口

    更多资料请参考:www.woyaocha.net/product/area 接口描述 功能描述 根据行政区划代码获取行政区划名称,或者根据行政区划名称获取行政区划代码. URL 示例 1)http 协 ...

  5. 快递查询(快递单号智能识别/快递公司+快递单号)-完整提供 Demo 代码示例及数据专业且全面的 API 查询接口

    更多资料请参考:www.woyaocha.net/product/express 查询说明 接口一:快递单号智能识别 快递单号智能识别,是根据查询的快递单号自动智能识别出该运单所属的快递公司,再获取快 ...

  6. 一封传话聚合推送各语言demo代码示例

    一封传话聚合推送各语言demo代码示例 前言 查看一封传话的API文档的GET请求只需一行代码,在url上拼接head和body参数即可完成推送.这里针对body数据量较大的情况,给出各语言实现的de ...

  7. 哪里可提供低代码开源大数据解决方案?

    如今的时代,对数据的管理要求越来越高,其实,这也是新经济时代下的办公需求.针对数据化时代的发展要求,开源大数据解决方案可以为企业分忧解难,做好数据化管理和分析,优化数据资源,为企业的发展决策提供强而有 ...

  8. db2分页查询语句优化_面试官:数据量很大,分页查询很慢,怎么优化?

    当需要从数据库查询的表有上万条记录的时候,一次性查询所有结果会变得很慢,特别是随着数据量的增加特别明显,这时需要使用分页查询.对于数据库分页查询,也有很多种方法和优化的点. 下面简单说一下我知道的一些 ...

  9. Google推出HTML 5练兵场 提供详尽代码示例,互联网营销

    继Apple推出自己的HTML 5网站之后,作为推广HTML 5两巨头之一的Google也不甘寂寞,于是不久前他们推出HTML5 ROCKS.   Google推广HTML 5网站HTML5 ROCK ...

最新文章

  1. 微软出手,干翻 IDEA?网友:先干翻Eclipse吧..
  2. 删除windows7的隐藏分区
  3. fiddler4 使用教程
  4. LINUX下的21个特殊符号 转
  5. Clojure语法学习-循环
  6. 磁盘的顺序读写与随机读写详解
  7. 冬季小学期 NIIT公司 web前端培训 CSS
  8. pb retrieve时停止工作_大佬们挂在嘴边的PE、PB是什么?
  9. Hibernate 入门之轻松上手 选择自 chainshun 的 Blog
  10. OceanBase杨传辉:一体化架构的分布式数据库已成为企业级系统首选
  11. js中文件写入(字符串写入)_note
  12. 解决Django文件表单验证forms.FileField(required=True),总是无法通过验证:这个字段是必填项
  13. OpenShift 4 - DevSecOps Workshop (1) - 安装 Workshop 环境
  14. linux 下kali linux 中使用hydra 进行对虚拟机中win10系统的密码破解
  15. 机器学习--组合分类方法之随机森林算法原理和实现(RF)
  16. PCB设计线宽、线距规则设置多大?
  17. Android APP LOGO尺寸
  18. 手机cpu性能天梯图2022 手机cpu性能排行2022 手机cpu哪个好
  19. 【opencv】18、视频操作
  20. 事实、循环、条件判断

热门文章

  1. 蒸妙集团布局未来大产业格局
  2. c# 微信支付V3商家转账到零钱避坑宝典(二)
  3. python 支付宝 退款 demo(python-alipay-sdk)
  4. QQ智能系统:为何会受到大众喜欢的呢?
  5. 十分钟搭建属于自己的小说网
  6. 2022年湖北省援企稳岗促就业有哪些优惠政策?申报条件以及奖补汇总
  7. 雅思口语考试分享(北京)
  8. python录制视频和声音_使用python编写一个录制屏幕及右下角录视频的工具
  9. matlab %3c=运算符,Maximize 3x+y with constraints in Matlab
  10. js 手动触发input事件