| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- # -*- coding: UTF-8 -*-
- import esigntool
- import requests
- from esigntool import esign_run_print_outer
- # 认证和授权服务API - 实名认证 - 发起类
- config = esigntool.Config() # 初始化配置类
- @esign_run_print_outer
- def getPsnAuthUrl(mobile):
- """
- 获取个人认证&授权页面链接
- :param mobile:实名用户手机号
- :return:请求响应
- """
- api_path = "/v3/psn-auth-url"
- method = esigntool.httpMethodEnum.POST
- body = {
- "clientType": "ALL", # 自动适配移动端或PC端
- "authorizeConfig": { # 实名认证可以不设置此参数,授权可以默认所有权限都设置
- "authorizedScopes": ["get_psn_identity_info", "psn_initiate_sign", "manage_psn_resource"]
- },
- "redirectConfig": {
- "redirectUrl": "https://www.baidu.com"
- },
- "psnAuthConfig": {
- "psnAccount": mobile,
- "psnInfo": {
- "psnName": ""
- }
- }
- }
- if mobile == "":
- print("请设置实名用户个人手机号")
- exit()
- # 签名并构造签名鉴权json请求头
- json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
- # 发起请求
- resp = requests.request(method, config.host + api_path, json=body, headers=json_headers)
- print(resp.text)
- return resp.text
- # 获取机构认证 & 授权页面链接
- @esign_run_print_outer
- def getOrgAuthUrl(mobile, orgName):
- """
- :param mobile:实名用户手机号
- :param orgName:实名企业名称
- :return:请求响应
- """
- api_path = "/v3/org-auth-url"
- method = esigntool.httpMethodEnum.POST
- body = {
- "clientType": "ALL", # 自动适配移动端或PC端
- "authorizeConfig": { # 实名认证可以不设置此参数,授权可以默认所有权限都设置
- "authorizedScopes": ["get_org_identity_info", "get_psn_identity_info", "org_initiate_sign",
- "psn_initiate_sign", "manage_org_resource", "manage_psn_resource", "use_org_order"]
- },
- "redirectConfig": {
- "redirectUrl": "https://www.baidu.com"
- },
- "orgAuthConfig": {
- "orgName": orgName,
- "transactorInfo": {
- "psnAccount": mobile
- }
- }
- }
- if mobile == "" or orgName == "":
- print("请设置实名用户个人手机号和实名企业的名称")
- exit()
- # 签名并构造签名鉴权json请求头
- json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
- # 发起请求
- resp = requests.request(method, config.host + api_path, json=body, headers=json_headers)
- print(resp.text)
- return resp.text
- if __name__ == '__main__':
- if config.appId == "" or config.scert == "":
- print("请设置应用appId和应用Secret")
- exit()
- mobile = "" # 请输入个人联系手机号
- orgName = "" # 请输入企业名称
- getPsnAuthUrl(mobile) # 获取个人认证&授权页面链接
- getOrgAuthUrl(mobile, orgName) # 获取机构认证 & 授权页面链接
|