日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python調用騰訊云實名認證接口辨別身份證真假_python

作者:蘇涼.py ? 更新時間: 2022-07-03 編程語言

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

點擊免費獲取產品

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('請輸入你的姓名:')
# 查詢參數(shù)
queryParams = {
    "idcard":ID_card,
    "name": ID_name}
# body參數(shù)(POST方法下存在)
bodyParams = {
}
# url參數(shù)拼接
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”:“一致”?則說明身份證和人名一致則認證通過,否則不然。

原文鏈接:https://blog.csdn.net/weixin_46277553/article/details/124486944

欄目分類
最近更新