天天看點

辨識身份真假之【天眼數聚】騰訊雲身份證明名認證接口

🐚作者簡介:蘇涼(專注于網絡爬蟲,資料分析)

🐳部落格首頁:​​​蘇涼.py的部落格​​​ 🌐系列專欄:​​Python基礎文法專欄​​ 👑名言警句:海闊憑魚躍,天高任鳥飛。

📰要是覺得部落客文章寫的不錯的話,還望大家三連支援一下呀!!!

👉關注✨點贊👍收藏📂

今天給大家分享騰訊雲的實名認證接口的調用​

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('請輸入你的身份證資訊:')
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'))      

運作結果:

辨識身份真假之【天眼數聚】騰訊雲身份證明名認證接口