import requests import esigntool from esigntool import esign_run_print_outer # 印章服务API config = esigntool.Config() # 初始化配置类 @esign_run_print_outer def createPsn_seals(): """ 创建个人模板印章 :return: """ # 构建请求body体 body = { "psnId": "c7e002***0541e7", "sealName": "这是一个自定义的名称", "sealTemplateStyle": "SQUARE_LEFT_BORDER", "sealSize": "20_20", "sealColor": "RED", "sealSuffix": "2", "sealOldStyle": "OLD_1", "sealOpacity": "100" } api_path = "/v3/seals/psn-seals/create-by-template" # 拼接请求路径 method = esigntool.httpMethodEnum.POST # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求 print(resp.text) return resp @esign_run_print_outer def create_image(): """ 创建个人图片印章 :return: """ # 构建请求body体 body = { "psnId": "c7e0029***0541e7", "sealImageFileKey": "$c3c7170e-xx-xx-xx-xx", "sealName": "这是一个自定义的印章名称", "sealWidth": "20", "sealHeight": "10", "sealColor": "RED" } api_path = "/v3/seals/psn-seals/create-by-image" # 拼接请求路径 method = esigntool.httpMethodEnum.POST # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求 print(resp.text) return resp @esign_run_print_outer def seals_query(): """ 查询个人印章列表 :return: """ psnId = "c7e00290541e7" pageNum = "1" pageSize = "20" api_path = "/v3/seals/psn-seal-list?psnId={}&pageNum={}&pageSize={}".format(psnId, pageNum, pageSize) # 拼接请求路径 print(api_path) method = esigntool.httpMethodEnum.GET # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求 print(resp.text) return resp @esign_run_print_outer def sealsinfo_query(): """ 查询指定印章详情 :return: """ psnId = "c7e0****41e7" sealId = "1caebb40***31f7f95087de" api_path = "/v3/seals/psn-seal-info?psnId={}&sealId={}".format(psnId, sealId) # 拼接请求路径 print(api_path) method = esigntool.httpMethodEnum.GET # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求 print(resp.text) return resp @esign_run_print_outer def change_seals(): """ 设置个人默认印章 :return: """ # 构建请求body体 body = { "psnId": "c7e0029***41e7", "sealId": "d2749c50-xx-xx-xx-ce4482c7747f" } api_path = "/v3/seals/psn-seals/set-default-seal" # 拼接请求路径 method = esigntool.httpMethodEnum.POST # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求 print(resp.text) return resp @esign_run_print_outer def seals_delete(): """ 删除个人印章 :return:DELETE """ psnId = "c7e00290541e7" sealId = "1caebb40***31f7f95087de" api_path = "/v3/seals/psn-seal?psnId={}&sealId={}".format(psnId, sealId) # 拼接请求路径 print(api_path) method = esigntool.httpMethodEnum.DELETE # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求 print(resp.text) return resp @esign_run_print_outer def create_sealsurl(): """ 获取创建个人印章页面链接 :return: """ # 构建请求body体 body = { "psnId": "c7e002***0541e7", "sealName": "这是一个预定义印章名称", "customBizNum": "这是一串开发者内部系统自定义的编号", "redirectUrl": "https://www.xxx.cn/", "uneditableFields": ["sealName", "sealOpacity"], } api_path = "/v3/seals/psn-seal-create-url" # 拼接请求路径 method = esigntool.httpMethodEnum.POST # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求 print(resp.text) return resp @esign_run_print_outer def manage_sealsurl(): """ 获取管理个人印章页面链接 :return: """ # 构建请求body体 body = { "psnId": "c7e002***0541e7" } api_path = "/v3/seals/psn-seals-manage-url" # 拼接请求路径 method = esigntool.httpMethodEnum.POST # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求 print(resp.text) return resp if __name__ == '__main__': createPsn_seals() # 创建个人模板印章 create_image() # 创建个人图片印章 seals_query() # 查询个人印章列表 sealsinfo_query() # 查询指定印章详情 change_seals() # 设置个人默认印章 seals_delete() # 删除个人印章 create_sealsurl() # 获取创建个人印章页面链接 manage_sealsurl() # 获取管理个人印章页面链接