#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import urllib, json
from urllib import urlencode
reload(sys)
sys.setdefaultencoding('utf-8')
def main():
"""
参数配置:
phone:手机号
queryList:查询类型(如:A;B,多种类别中间用英文分号分隔,A:小号;B:验证码接收平台;C:电商欺诈号;D:互联网金融)全选可以输入ALL ,默认ALL
key:申请的手机黑名单查询API key
"""
params = {"key":"*******", "phone":"15998888888", "queryList":"ALL"}
queryResult = query(params)
# print queryResult
if queryResult:
if queryResult['error_code'] == 0:
print "结果:%s" % queryResult['result']
else:
print "错误码:%s,查询失败:%s" % (queryResult['error_code'],queryResult['reason'])
else:
print "网络请求失败"
def query(params):
"""
返回JSON格式参考:
{
"reason":"success",
"result":{
"phone":"15998888888",
"queryList":"ALL", /* 查询类型参数 */
"isBlack":false, /* 手机号码是否是黑名单 */
"isLegal":true, /* 手机号码是否合法 */
"customSource":"" /* 黑名单泄露源 */
},
"error_code":0
}
"""
params = urlencode(params)
url = 'http://v.juhe.cn/phoneBlack/query.php?%s' % params
wp = urllib.urlopen(url)
content = wp.read()
res = json.loads(content)
# print content
if res:
return res
else:
return False
if __name__ == "__main__":
main()