網站首頁 編程語言 正文
今天給大家分享騰訊云的實名認證接口的調用
點擊免費獲取產品
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
相關推薦
- 2022-02-20 給定一個數(shù)組,讓數(shù)組的每一項都乘以2幾種實現(xiàn)方法
- 2023-03-27 python中的正則表達式,貪婪匹配與非貪婪匹配方式_python
- 2022-08-10 Go語言反射獲取類型屬性和方法示例_Golang
- 2022-08-20 Python操作HDF5文件示例_python
- 2022-05-27 Python腳本傳參數(shù)argparse模塊的使用_python
- 2022-07-19 Linux cat more grep head tail cut uniq sort tr命令詳解
- 2022-06-01 python?全角半角互換的實現(xiàn)示例_python
- 2022-10-04 goland?-sync/atomic原子操作小結_Golang
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支