1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
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_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”:“一致” 则说明身份证和人名一致则认证通过,否则不然。
以上就是python辨别身份真假之腾讯云身份证实名认证接口的详细内容,更多关于辨别身份真假之腾讯云身份证实名认证接口的资料请关注服务器之家其它相关文章!
原文链接:https://blog.csdn.net/weixin_46277553/article/details/124486944