腾讯云身份证实名认证接口
苏凉.py 人气:0今天给大家分享腾讯云的实名认证接口的调用
from __future__ import print_function import ssl, hmac, base64, hashlib from datetime import datetime as pydatetime try: from urllib import urlencode from urllib2 import Request, urlopen except ImportError: from urllib.parse import urlencode from urllib.request import Request, urlopen # 云市场分配的密钥Id secretId = "**购买后多得到的ID**" # 云市场分配的密钥Key secretKey = "**购买后得到的Key**" source = "**用户名**" # 签名 datetime = pydatetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') signStr = "x-date: %s\nx-source: %s" % (datetime, source) sign = base64.b64encode(hmac.new(secretKey.encode('utf-8'), signStr.encode('utf-8'), hashlib.sha1).digest()) auth = 'hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"' % ( secretId, sign.decode('utf-8')) # 请求方法 method = 'GET' # 请求头 headers = { 'X-Source': source, 'X-Date': datetime, 'Authorization': auth, } ID_card = input('请输入你的SFZ信息:') ID_name = input('请输入你的姓名:') # 查询参数 queryParams = { "idcard":ID_card, "name": ID_name} # body参数(POST方法下存在) bodyParams = { } # url参数拼接 url = 'https://service-2n5qa8cl-1256140209.ap-shanghai.apigateway.myqcloud.com/release/eid/check' if len(queryParams.keys()) > 0: url = url + '?' + urlencode(queryParams) request = Request(url, headers=headers) request.get_method = lambda: method if method in ('POST', 'PUT', 'PATCH'): request.data = urlencode(bodyParams).encode('utf-8') request.add_header('Content-Type', 'application/x-www-form-urlencoded') ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE response = urlopen(request, context=ctx) content = response.read() if content: print(content.decode('utf-8'))
运行结果:
“description”:“一致” 则说明SFZ和人名一致则认证通过,否则不然。
加载全部内容