網站首頁 編程語言 正文
今天給大家分享騰訊云的實名認證接口的調用
點擊免費獲取產品
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'))
運行結果:
“description”:“一致”?則說明身份證和人名一致則認證通過,否則不然。
原文鏈接:https://blog.csdn.net/weixin_46277553/article/details/124486944
相關推薦
- 2023-01-30 基于redis樂觀鎖實現并發排隊_Redis
- 2021-12-04 C#獲取Windows10屏幕縮放比例的操作方法_C#教程
- 2023-05-30 python中pip無法正確安裝或路徑出錯的解決方案_python
- 2022-12-11 SQL中創建存儲過程_MsSql
- 2022-10-07 OpenCV實現物體的凸包檢測的示例代碼_C 語言
- 2022-02-25 C語言函數棧幀的創建和銷毀介紹_C 語言
- 2022-03-26 postman模擬post請求的四種請求體_相關技巧
- 2022-08-22 Python中可以用三種方法判斷文件是否存在_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支