c765d9b1 by 付孟奇

自动化框架初始化,完成话术变量场景模拟

0 parents
No preview for this file type
1 # Default ignored files
2 /shelf/
3 /workspace.xml
4 # Datasource local storage ignored files
5 /dataSources/
6 /dataSources.local.xml
7 # Editor-based HTTP Client requests
8 /httpRequests/
1 <?xml version="1.0" encoding="UTF-8"?>
2 <module type="PYTHON_MODULE" version="4">
3 <component name="NewModuleRootManager">
4 <content url="file://$MODULE_DIR$" />
5 <orderEntry type="inheritedJdk" />
6 <orderEntry type="sourceFolder" forTests="false" />
7 </component>
8 </module>
...\ No newline at end of file ...\ No newline at end of file
1 <component name="InspectionProjectProfileManager">
2 <profile version="1.0">
3 <option name="myName" value="Project Default" />
4 <inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
5 <Languages>
6 <language minSize="111" name="Python" />
7 </Languages>
8 </inspection_tool>
9 </profile>
10 </component>
...\ No newline at end of file ...\ No newline at end of file
1 <component name="InspectionProjectProfileManager">
2 <settings>
3 <option name="USE_PROJECT_PROFILE" value="false" />
4 <version value="1.0" />
5 </settings>
6 </component>
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4">
3 <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
4 </project>
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4">
3 <component name="ProjectModuleManager">
4 <modules>
5 <module fileurl="file://$PROJECT_DIR$/.idea/SituApiSupport.iml" filepath="$PROJECT_DIR$/.idea/SituApiSupport.iml" />
6 </modules>
7 </component>
8 </project>
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4">
3 <component name="VcsDirectoryMappings">
4 <mapping directory="$PROJECT_DIR$" vcs="Git" />
5 </component>
6 </project>
...\ No newline at end of file ...\ No newline at end of file
1 # @Time : 2022/8/23 15:13
2 # @Author : 付孟奇
3
4 from unittestreport import TestRunner
5 from util.HandleJenkins import handle_jenkins
6 from util.HandleData import handle_data
7 from config.VendorPath import base_path
8 import unittest
9
10 # 执行的项目文件目录
11 pro = handle_jenkins()['pro']
12 email_data = handle_jenkins()['email']
13 email = str(email_data).split(',')
14 if len(email) > 1:
15 email = ','.join(email)
16 title = handle_jenkins()['title']
17 env = handle_jenkins()['env']
18
19 # 执行数据库初始化
20 # TODO
21 # handle_data.db_ini()
22 # handle_data.handle_global()
23
24 # 执行文件地址
25 # TODO
26 suite_case = unittest.defaultTestLoader.discover(base_path + '/case/', pattern='*.py')
27
28 runner = TestRunner(suite_case,
29 filename="report.html",
30 report_dir='./report',
31 title=title,
32 tester='测试组',
33 desc='接口自动化测试报告',
34 templates=1,
35 pro=pro,
36 env=env
37 )
38 runner.run()
39 # runner.send_email(host="smtp.exmail.qq.com",
40 # port=465,
41 # user="fumengqi@situdata.com",
42 # password="Fz315824",
43 # to_addrs=email)
44
45 # 执行数据库清理
46 # TODO
1 # @Time : 2022/8/23 11:15
2 # @Author : 付孟奇
3 from ddt import ddt, data
4 from config.VendorPath import excel_path, global_path
5 from util.HandleJenkins import handle_jenkins
6 from util.HandleData import handle_data
7 from util.HandleSpeech import handle_speech
8 from util.HandleRequest import DealRequest
9 from util.HandleLog import logger
10 from util.HandleFile import file_read_save
11 import unittest
12 import json
13 import re
14 import operator
15
16 # 获取配置信息
17 vendor_name = handle_jenkins()['pro']
18 # 获取项目所有测试用例
19 data_list = handle_data.load_excel(excel_path, '话术变量验证')
20
21
22 @ddt
23 class DDTTest(unittest.TestCase):
24
25 @data(*data_list)
26 def test_case(self, data_list):
27 logger.info('***************【' + str(data_list['desc']) + '】接口测试开始***************')
28 logger.info('接口测试用例为:' + str(data_list))
29
30 # 1、设置报告的接口信息
31 self._testMethodName = data_list['uri']
32 if data_list['positive_case'] == '正向':
33 self._testMethodDoc = '正向case--' + data_list['desc']
34 elif data_list['positive_case'] == '反向':
35 self._testMethodDoc = '正向case--' + data_list['desc']
36 else:
37 self._testMethodDoc = data_list['desc']
38
39 # 2、参数整理
40 re_headers = handle_data.handle_params(data_list['headers'])
41 logger.info('请求头为:' + str(re_headers))
42
43 re_method = data_list['method']
44 re_url = handle_jenkins()['host'] + data_list['uri']
45 re_params = handle_data.handle_params(data_list['params'])
46 logger.info('请求参数为:' + str(re_params))
47
48 # 3、进行接口请求
49 res = DealRequest(re_method, re_url, re_headers, re_params).return_response()
50 logger.info('接口测试结果为:' + str(res))
51
52 # 4、响应断言
53 assert_num = str(data_list['response_assert']).count('话术变量验证') # 判断是否是话术场景
54 if assert_num == 0:
55 assert_data = json.loads(data_list['response_assert'])
56 for k in assert_data:
57 self.assertEqual(handle_data.get_value(res, k)[0], assert_data[k])
58 else: # 话术变量验证
59 orderRecordId = res.get('result').get('orderRecordId')
60 if orderRecordId is not None:
61 assert_msg = handle_speech.getAssert(orderRecordId)
62 if assert_msg['code'] ==0:
63 logger.info(assert_msg['msg'])
64 else:
65 raise Exception(assert_msg['msg'])
66
67 # 5、判断是否需要保存响应信息:正向case且有相应需要保存的
68 if res['code'] == 0:
69 if data_list['save_args'] != '' and data_list['positive_case'] == '正向':
70 list_args = re.split(r'[,,;;、.。]', data_list['save_args'])
71 dic_args = {}
72 for i in list_args:
73 res_args = handle_data.get_value(res, i)[0]
74 dic_args[i] = res_args
75 file_read_save(global_path, str(int(data_list['id'])), dic_args)
76
77 logger.info('***************【' + str(data_list['desc']) + '】接口测试结束***************')
78
79
80 if __name__ == '__main__':
81 unittest.main()
No preview for this file type
1 # @Time : 2022/8/22 15:39
2 # @Author : 付孟奇
3
4 import os
5 import time
6
7 # 项目根路径
8 base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9
10 # 日志路径
11 log_path = os.path.join(base_path, 'log/{}.log'.format(time.strftime('%Y-%m-%d')))
12
13 # 公共参数文件路径
14 global_path = os.path.join(base_path, 'config/global_params.json')
15
16 # Excel数据路径
17 excel_path = os.path.join(base_path, 'data/自动化接口测试.xlsx')
18
19 # 生成报告文件路径
20 report_path = os.path.join(base_path, 'report/report.html')
No preview for this file type
1 [mysql]
2 ;mysql_host = localhost
3 ;mysql_port = 3306
4 ;mysql_user = root
5 ;mysql_passwd = fumengqi
6 ;mysql_db = automation
7
8
9 mysql_host = rm-2zen60zh797n662w4lo.mysql.rds.aliyuncs.com
10 mysql_port = 3306
11 mysql_user = sanheyi_stg
12 mysql_passwd = x39l&Cgid150t4kvfKA
13 mysql_db = sanheyi_stg
...\ No newline at end of file ...\ No newline at end of file
1 {
2 "1": {
3 "md5": "d003784d3e6dbc116efcb6d550440465"
4 },
5 "2": {
6 "token": "28fbd3f975224bb995403d1bb3d36acb"
7 },
8 "3": {
9 "orderRecordId": 157
10 }
11 }
...\ No newline at end of file ...\ No newline at end of file
No preview for this file type
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
1 2022-10-17 16:34:00,037 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
2 2022-10-17 16:34:00,039 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
3 2022-10-17 16:34:16,574 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
4 2022-10-17 16:34:16,574 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
5 2022-10-17 16:35:51,541 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
6 2022-10-17 16:35:51,543 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
7 2022-10-17 16:37:04,101 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
8 2022-10-17 16:37:04,102 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
9 2022-10-17 18:09:44,684 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
10 2022-10-17 18:09:44,686 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
11 2022-10-17 18:11:42,848 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
12 2022-10-17 18:11:42,849 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
13 2022-10-17 18:58:25,502 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
14 2022-10-17 18:58:25,504 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
This diff could not be displayed because it is too large.
1 2022-10-21 10:44:23,145 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
2 2022-10-21 10:44:23,146 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
3 2022-10-21 10:44:23,249 - root - INFO - 订单类型是一主一附
4 2022-10-21 10:46:28,083 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
5 2022-10-21 10:46:28,084 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
6 2022-10-21 10:46:28,148 - root - INFO - 订单类型是一主一附
7 2022-10-21 14:11:23,345 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
8 2022-10-21 14:11:23,347 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
9 2022-10-21 14:11:23,479 - root - ERROR - 测试用例打开失败,原因是:No sheet named <'字典映射'>
10 2022-10-21 14:11:35,370 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
11 2022-10-21 14:11:35,371 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
12 2022-10-21 14:11:35,480 - root - ERROR - 测试用例打开失败,原因是:No sheet named <'字典映射'>
13 2022-10-21 14:11:45,000 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
14 2022-10-21 14:11:45,001 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
15 2022-10-21 14:12:06,469 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
16 2022-10-21 14:12:06,469 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
17 2022-10-21 15:54:42,714 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
18 2022-10-21 15:54:42,716 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
19 2022-10-21 15:54:57,324 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
20 2022-10-21 15:54:57,325 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
21 2022-10-21 15:55:04,643 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
22 2022-10-21 15:55:04,643 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
23 2022-10-21 15:55:22,540 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
24 2022-10-21 15:55:22,541 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
25 2022-10-21 15:56:07,622 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
26 2022-10-21 15:56:07,623 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
27 2022-10-21 15:56:18,385 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
28 2022-10-21 15:56:18,385 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
29 2022-10-21 15:56:26,975 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
30 2022-10-21 15:56:26,976 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
31 2022-10-21 15:57:59,658 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
32 2022-10-21 15:57:59,659 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
33 2022-10-21 15:58:11,573 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
34 2022-10-21 15:58:11,574 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
35 2022-10-21 17:27:00,953 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
36 2022-10-21 17:27:00,954 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
37 2022-10-21 17:27:01,128 - root - INFO - 订单类型是一主一附
38 2022-10-21 17:29:04,822 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
39 2022-10-21 17:29:04,824 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
40 2022-10-21 17:29:04,965 - root - INFO - 订单类型是一主一附
41 2022-10-21 17:34:29,194 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
42 2022-10-21 17:34:29,195 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
43 2022-10-21 17:34:58,757 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
44 2022-10-21 17:34:58,758 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
45 2022-10-21 17:37:05,508 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
46 2022-10-21 17:37:05,509 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
47 2022-10-21 17:37:22,839 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
48 2022-10-21 17:37:22,840 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
49 2022-10-21 17:37:41,744 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
50 2022-10-21 17:37:41,745 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
51 2022-10-21 17:38:15,490 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
52 2022-10-21 17:38:15,490 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
53 2022-10-21 17:38:48,933 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
54 2022-10-21 17:38:48,934 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
55 2022-10-21 17:40:04,703 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
56 2022-10-21 17:40:04,704 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
57 2022-10-21 17:40:19,984 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
58 2022-10-21 17:40:19,986 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
59 2022-10-21 17:41:48,315 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
60 2022-10-21 17:41:48,316 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
61 2022-10-21 17:43:10,828 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
62 2022-10-21 17:43:10,829 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
63 2022-10-21 17:44:18,478 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
64 2022-10-21 17:44:18,478 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
65 2022-10-21 17:47:16,184 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
66 2022-10-21 17:47:16,186 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
67 2022-10-21 18:03:55,509 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
68 2022-10-21 18:03:55,512 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
69 2022-10-21 18:04:03,979 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
70 2022-10-21 18:04:03,979 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
71 2022-10-21 18:04:04,109 - root - INFO - 订单类型是一主一附
72 2022-10-21 18:06:03,429 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
73 2022-10-21 18:06:03,429 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
74 2022-10-21 18:06:23,813 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载中......
75 2022-10-21 18:06:23,814 - root - INFO - /Users/jingyuxiang/Desktop/code/python/SituApiSupport/config/db.ini 文件加载成功......
76 2022-10-21 18:06:23,935 - root - INFO - 订单类型是一主一附
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
1 CREATE TABLE `citic_role` (
2 `id` bigint(20) NOT NULL AUTO_INCREMENT,
3 `name` varchar(40) CHARACTER SET utf8mb4 DEFAULT NULL,
4 `mark` int(11) DEFAULT NULL,
5 `desc` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL,
6 `pid` bigint(20) DEFAULT NULL COMMENT '父id',
7 `path` varchar(255) DEFAULT NULL COMMENT '上级角色id完整路径',
8 `role_key` varchar(100) NOT NULL DEFAULT '' COMMENT '角色权限字符串',
9 `role_sort` int(4) NOT NULL DEFAULT '0' COMMENT '显示顺序',
10 `data_scope` char(1) DEFAULT '1' COMMENT '数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)',
11 `menu_check_strictly` tinyint(1) DEFAULT '1' COMMENT '菜单树选择项是否关联显示',
12 `organization_check_strictly` tinyint(1) DEFAULT '1' COMMENT '部门树选择项是否关联显示',
13 `status` char(1) NOT NULL DEFAULT '0' COMMENT '角色状态(0正常 1停用)',
14 `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
15 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
16 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
17 `extra_info` varchar(500) DEFAULT NULL COMMENT '附加信息',
18 PRIMARY KEY (`id`) USING BTREE
19 ) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;
...\ No newline at end of file ...\ No newline at end of file
1 CREATE TABLE `citic_user` (
2 `id` bigint(20) NOT NULL AUTO_INCREMENT,
3 `username` varchar(45) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '工号',
4 `password` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL,
5 `name` varchar(30) CHARACTER SET utf8mb4 DEFAULT NULL,
6 `telephone` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL,
7 `activate` tinyint(4) DEFAULT NULL COMMENT '1 = 已激活, 2 = 未激活, 3 = 已禁用',
8 `org_code` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '组织机构代码',
9 `create_time` datetime DEFAULT CURRENT_TIMESTAMP,
10 `activate_time` datetime DEFAULT NULL,
11 `branch_id` bigint(20) DEFAULT NULL COMMENT '分公司_id',
12 `branch_name` varchar(45) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '分公司_name',
13 `sub_branch_id` bigint(20) DEFAULT NULL COMMENT '支公司_id',
14 `sub_branch_name` varchar(45) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '支公司_name',
15 `marketing_channel` varchar(45) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '营销渠道',
16 `departed` tinyint(4) DEFAULT NULL COMMENT '是否离职 1 = 离职 2 = 在职',
17 `user_type` tinyint(4) DEFAULT NULL COMMENT '1 = app端 2 = web端(信诚) 3 = web端(思图)',
18 `last_login_time` datetime DEFAULT NULL COMMENT '最后一次登录时间',
19 `directly_agency_id` bigint(11) DEFAULT NULL COMMENT '直属机构id',
20 `directly_agency_name` varchar(45) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '直属机构名字',
21 `id_card` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '身份证',
22 `licensed` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '职业证',
23 `open_id` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '微信号',
24 `emp_no` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '业务员工号',
25 `extra_info` text CHARACTER SET utf8mb4 COMMENT '额外信息',
26 `email` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL,
27 `employee_id` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '工号',
28 `source` tinyint(4) DEFAULT NULL COMMENT '用户来源:1=本地注册,2=统一登录获取',
29 `group_id` bigint(20) DEFAULT NULL COMMENT '团队id',
30 `company_name` varchar(225) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '销售人员所属中介公司名称',
31 `company_code` varchar(50) DEFAULT NULL COMMENT '销售人员所属经代公司编码',
32 `cert_type` varchar(4) DEFAULT NULL COMMENT '证件类型',
33 PRIMARY KEY (`id`) USING BTREE
34 ) ENGINE=InnoDB AUTO_INCREMENT=8204 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
...\ No newline at end of file ...\ No newline at end of file
1 CREATE TABLE `citic_user_role` (
2 `id` bigint(20) NOT NULL AUTO_INCREMENT,
3 `user_id` bigint(20) DEFAULT NULL,
4 `role_id` bigint(20) DEFAULT NULL,
5 PRIMARY KEY (`id`) USING BTREE
6 ) ENGINE=InnoDB AUTO_INCREMENT=8188 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
...\ No newline at end of file ...\ No newline at end of file
File mode changed
1 CREATE TABLE `order_base_info` (
2 `id` bigint(20) NOT NULL AUTO_INCREMENT,
3 `task_id` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '双录任务号',
4 `order_id` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '电子订单号',
5 `policy_no` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '保单号',
6 `serial_no` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '字纸投保单流水号',
7 `self_no` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '保全订单号',
8 `customer_name` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '投保人姓名',
9 `customer_id_card_type` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '投保人证件类型',
10 `customer_num` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL,
11 `product_type` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '产品类型',
12 `ptt_id` bigint(20) DEFAULT NULL COMMENT '产品模板id',
13 `product_name` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '产品名称',
14 `product_code` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '产品编号',
15 `pr_id` bigint(20) DEFAULT NULL COMMENT '产品表主键id',
16 `organization_name` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '管理机构名称',
17 `org_id` bigint(20) DEFAULT NULL COMMENT '管理机构表主键id(支公司机构id)',
18 `quality_audit_status` int(11) DEFAULT '0' COMMENT '质检状态(1 = 未录制 , 2 =质检中,3 =已质检)',
19 `quality_audit_count` int(11) DEFAULT '0' COMMENT '质检次数',
20 `upload_time` datetime DEFAULT NULL COMMENT '最后一次上传时间',
21 `recording_time` int(11) DEFAULT NULL COMMENT '录制时间',
22 `recording_people` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '录制人',
23 `quality_audit_advice` int(11) DEFAULT '0' COMMENT '质检结果 (0 = 待质检,1 = 通过,2 = 重录,3 = 补录)',
24 `ac_id` bigint(20) DEFAULT NULL COMMENT '账户id',
25 `top_org_id` bigint(20) DEFAULT NULL COMMENT '顶级机构表id',
26 `extra_info` text CHARACTER SET utf8mb4 COMMENT '额外话术模板变量信息',
27 `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
28 `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
29 `life_cycle` tinyint(4) DEFAULT NULL COMMENT '1、被覆盖。2、创建(无效)。3、待录制(生效)。11、驳回补录。12、驳回重录。13、首次提交。14、审核通过。15. 已完成 21、首次可质检。22、补录提交。23、重录提交。',
30 `lock_order` int(10) DEFAULT '2' COMMENT '订单锁定状态(1 = 锁定, 2 = 未锁定)',
31 `order_no_type` int(11) DEFAULT NULL COMMENT '1 = 电子订单号,2 = 纸质投保单流水号',
32 `salesman_username` varchar(40) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '录制人工号',
33 `marketing_channel` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '营销渠道',
34 `need_tts` int(11) DEFAULT NULL COMMENT '1 = 开启; 2= 关闭',
35 `salesman_id` bigint(20) DEFAULT NULL COMMENT '营销员ID',
36 `org_code` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '组织机构代码',
37 `branch_id` bigint(20) DEFAULT NULL COMMENT '分公司机构管理id',
38 `recording_begin_time` bigint(20) DEFAULT NULL COMMENT '录制开始时间',
39 `appnt_age` varchar(20) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '投保人年龄',
40 `encrypt_key` varchar(200) CHARACTER SET utf8mb4 DEFAULT NULL,
41 `insure_self` int(11) DEFAULT NULL COMMENT '自保件/非自保件(1 = 自保件;2 = 非自保件;)',
42 `support_remote` int(11) DEFAULT '2' COMMENT '是否支持远程(1 = 支持;2 = 不支持;)',
43 `system_type` int(11) DEFAULT '1' COMMENT '双录类型(1 = 现场;2 = 远程;)',
44 `mixed_flow_status` int(11) DEFAULT '1' COMMENT '混流状态(1 = 完成;2 = 处理中;...)',
45 `record_rs` int(11) DEFAULT NULL COMMENT '选中需要质检(1 = 选中, 2= 未选中)',
46 `hesitate_period` int(11) DEFAULT NULL COMMENT '真正的犹豫期',
47 `hesitate_period_history` int(11) DEFAULT NULL COMMENT '如果打开开关,那么这个列存开关之前的犹豫期\r\n如果关闭开关,把此项清空,然后把这个项的值拿到真的犹豫期里面',
48 `order_no` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL,
49 `cont_no` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL,
50 `first_recording_begin_time` bigint(20) DEFAULT NULL COMMENT '首次录制时间',
51 `apply_date` date DEFAULT NULL COMMENT '投保申请日期',
52 `gender` int(11) DEFAULT NULL COMMENT '1 = 男 2 = 女',
53 `order_source` int(11) DEFAULT '1' COMMENT '1 = 电子订单号(扫码录入),2 = 纸质投保单流水号(手工录入), 3 = 系统对接,4=跳转入件',
54 `redress_status` int(10) DEFAULT '2' COMMENT '订单是否被复审人员更正过(1 = 更正, 2 = 未更正)',
55 `version_code` varchar(16) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '二维码版本号',
56 `audit_source` int(11) DEFAULT NULL COMMENT '质检抽样结果 1=抽样质检,2=强制通过 > X质检,3=自动通过',
57 `quota_type` int(5) DEFAULT NULL COMMENT '保全项:1-新增附加险,2-变更投保人',
58 `record_type` int(5) DEFAULT NULL COMMENT '双录类型:1-新契约,2-保全',
59 `applicant_remote_flag` int(11) DEFAULT NULL COMMENT '投保人远程标志 : 1:允许远程 2:不允许远程',
60 `many_insures_flag` int(11) DEFAULT NULL COMMENT '多被保人标志 0:单被保人 1:多被保人',
61 `same_person` int(11) DEFAULT NULL COMMENT '投被保人是否为同一人标志 1:同一人 2:不同人',
62 `lock_expire_time` datetime DEFAULT NULL COMMENT '订单锁定过期时间',
63 `system_source` varchar(10) DEFAULT NULL COMMENT '系统来源:1-经英宝,2-微信公众号',
64 `insurance_company` varchar(20) DEFAULT NULL COMMENT '保司来源',
65 `sign_order_status` tinyint(4) DEFAULT '0' COMMENT '签单状态(0-未签单,1-已签单)',
66 `correction_status` int(11) DEFAULT '0' COMMENT '更正状态 0 = 默认不用更正(电子/比对一致的); 1 = 已更正; 2 = 未更正;',
67 PRIMARY KEY (`id`) USING BTREE,
68 KEY `life_cycle_index` (`life_cycle`) USING BTREE,
69 KEY `order_id_index` (`order_id`) USING BTREE,
70 KEY `policy_no_index` (`policy_no`) USING BTREE,
71 KEY `serial_no_index` (`serial_no`) USING BTREE,
72 KEY `create_time_index` (`create_time`) USING BTREE
73 ) ENGINE=InnoDB AUTO_INCREMENT=60 DEFAULT CHARSET=utf8 COMMENT='订单主表';
...\ No newline at end of file ...\ No newline at end of file
1 CREATE TABLE `speech_variable` (
2 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
3 `name` varchar(32) NOT NULL DEFAULT '' COMMENT '变量名称',
4 `desc` varchar(64) NOT NULL DEFAULT '' COMMENT '变量描述',
5 `sort` int(11) NOT NULL DEFAULT '0' COMMENT '变量排序值:根据sort排序',
6 `group_id` int(11) NOT NULL DEFAULT '0' COMMENT '变量所属组ID',
7 `level` int(11) NOT NULL DEFAULT '1' COMMENT '变量所属组层级',
8 `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
9 `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
10 `version` int(11) NOT NULL DEFAULT '0' COMMENT '版本号',
11 `deleted` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否删除:0-被删除,1-正常',
12 `available` smallint(6) NOT NULL DEFAULT '1' COMMENT '是否可用:0-不可用,1-可用',
13 `display` smallint(6) NOT NULL DEFAULT '1' COMMENT '是否显示:0-不显示,1-显示',
14 `record_type` smallint(6) DEFAULT '3' COMMENT '1-新契约, 2-保全, 3-共同属性',
15 `extra_info` varchar(255) DEFAULT NULL COMMENT '额外描述信息',
16 PRIMARY KEY (`id`) USING BTREE,
17 KEY `deleted_index` (`deleted`) USING BTREE
18 ) ENGINE=InnoDB AUTO_INCREMENT=77 DEFAULT CHARSET=utf8mb4 COMMENT='话术变量表';
...\ No newline at end of file ...\ No newline at end of file
1 # @Time : 2022/8/30 16:28
2 # @Author : 付孟奇
3 from config.VendorPath import base_path
4 from util.HandleFile import load_ini_file
5 from util.HandleLog import logger
6 import os
7 import pymysql
8
9 db_file_path = os.path.join(base_path, 'config', 'db.ini')
10
11
12 class DBLoad:
13 def __init__(self):
14 db_res = load_ini_file(db_file_path, 'mysql')
15 self.DB_CONF = {
16 'host': db_res['mysql_host'],
17 'port': int(db_res['mysql_port']),
18 'user': db_res['mysql_user'],
19 'passwd': db_res['mysql_passwd'],
20 'db': db_res['mysql_db'],
21 }
22 self.connect()
23
24 def connect(self, db_conf=None):
25 # 通过字典拆包传递配置信息,建立数据库连接
26 if db_conf is None:
27 db_conf = self.DB_CONF
28 self.conn = pymysql.connect(**db_conf, autocommit=True)
29 # 通过 cursor() 创建游标对象,并让查询结果以字典格式输出
30 self.cur = self.conn.cursor(cursor=pymysql.cursors.DictCursor)
31
32 def select_db(self, sql):
33 """查询"""
34 # 检查连接是否断开,如果断开就进行重连
35 self.conn.ping(reconnect=True)
36 # 使用 execute() 执行sql
37 self.cur.execute(sql)
38 # 使用 fetchall() 获取查询结果
39 data = self.cur.fetchall()
40 return data
41
42 def execute_db(self, sql):
43 """更新/新增/删除"""
44 try:
45 # 检查连接是否断开,如果断开就进行重连
46 self.conn.ping(reconnect=True)
47 # 使用 execute() 执行sql
48 self.cur.execute(sql)
49 # 提交事务
50 self.conn.commit()
51 except Exception as e:
52 logger.info("操作MySQL出现错误,错误原因:{}".format(e))
53 # 回滚所有更改
54 self.conn.rollback()
55
56
57 db_load = DBLoad()
1 # @Time : 2022/8/23 14:45
2 # @Author : 付孟奇
3 from util.HandleLog import logger
4 from util.HandleFile import file_read_global
5 import xlrd
6 import json
7
8
9 class DateLoad:
10
11 # 读取Excel数据--按行
12 def load_excel(self, file, tag):
13 data_list = []
14 try:
15 book = xlrd.open_workbook(file)
16 tag = book.sheet_by_name(tag)
17 # 获取行数
18 row_num = tag.nrows
19 header = tag.row_values(0)
20 for i in range(1, row_num):
21 # 读取行
22 row_data = tag.row_values(i)
23 # 读取行中的每一列的值
24 d = dict(zip(header, row_data))
25 data_list.append(d)
26 return data_list
27 except Exception as e:
28 logger.error('测试用例打开失败,原因是:%s' % e)
29
30 # 查找特定key的value信息
31 def get_value(self, source_json, object_key):
32 result = []
33 if isinstance(source_json, dict) and object_key in source_json.keys():
34 value = source_json[object_key]
35 result.append(value)
36 return result
37 elif isinstance(source_json, (list, tuple)):
38 for item in source_json:
39 value = self.get_value(item, object_key)
40 if value == "None" or value is None:
41 pass
42 elif len(value) == 0:
43 pass
44 else:
45 result.append(value)
46 return result
47 else:
48 if isinstance(source_json, dict):
49 for k in source_json:
50 value = self.get_value(source_json[k], object_key)
51 if value == "None" or value is None:
52 pass
53 elif len(value) == 0:
54 pass
55 else:
56 for item in value:
57 result.append(item)
58 return result
59
60 # 处理请求的可变参数
61 def handle_params(self, args):
62 try:
63 if str(args).count('话术变量验证') == 1: # 话术变量场景测试参数特殊处理
64 from util.HandleSpeech import handle_speech
65 params_list = str(args).split('-')
66 args = handle_speech.getRestult(params_list[1])
67 return json.loads(args)
68 elif args[0] == '{':
69 args = json.loads(args)
70 old_key = [] # 变量的key的集合
71 old_value = [] # 变量集合
72 # 遍历请求参数中,所有的变量信息
73 for k, v in args.items():
74 if str(v)[0] == '#':
75 old_key.append(k)
76 old_value.append(v)
77 # 替换变量值
78 if len(old_value) != 0:
79 logger.info('需要替换的变量信息为:' + str(old_value))
80 key_dic = {}
81 for i in old_value:
82 v_key = str(i[1:]).split('.')
83 res = file_read_global(v_key)
84 key_dic[i] = res
85 logger.info('可变参数的信息为:' + str(key_dic))
86 # 参数替换
87 for j in key_dic:
88 self.dic_del(args, j, key_dic)
89 logger.info('可变参数替换完毕:' + str(args))
90 return args
91 else:
92 return ''
93 except:
94 return {'code': 1, 'result': '参数错误,请检查替换信息是否正确'}
95
96 # json格式字典处理
97 def dic_del(self, data_json, data_key, key_dic):
98 if isinstance(data_json, dict):
99 for k, v in data_json.items():
100 if v == data_key:
101 data_json[k] = key_dic[data_key]
102 else:
103 self.dic_del(v, data_key, key_dic)
104 elif isinstance(data_json, list):
105 for i in data_json:
106 self.dic_del(i, data_key, key_dic)
107
108
109 handle_data = DateLoad()
110
111 if __name__ == '__main__':
112 handle_data.handle_global()
1 # @Time : 2022/8/24 16:07
2 # @Author : 付孟奇
3 from config.VendorPath import global_path
4 from util.HandleLog import logger
5 import configparser
6 import json
7 import base64
8 import yaml
9
10
11 # 读取ini文件内容
12 def load_ini_file(file_path, sec):
13 logger.info("{} 文件加载中......".format(file_path))
14 config = configparser.ConfigParser()
15 config.read(file_path, encoding="UTF-8")
16 data = dict(config[sec])
17 logger.info("{} 文件加载成功......".format(file_path))
18 return data
19
20
21 # 读取yaml文件内容
22 def load_yaml_file(file_path):
23 logger.info("{} 文件加载中......".format(file_path))
24 with open(file_path, encoding='utf-8') as f:
25 data = yaml.safe_load(f)
26 logger.info("{} 文件加载成功......".format(file_path))
27 return data
28
29
30 # 读取json文件并重新存储
31 def file_read_save(file_path, file_key, file_value):
32 with open(file_path, 'r+') as f:
33 file_data = json.load(f)
34 file_data[str(file_key)] = file_value
35 f.seek(0)
36 f.truncate()
37 json.dump(file_data, f, indent=4, ensure_ascii=False)
38 logger.info('响应信息存储完毕!!!')
39
40
41 # 读取公共参数文件指定内容
42 def file_read_global(args):
43 with open(global_path, 'r') as f:
44 file_data = json.load(f)
45 res = file_data[args[0]][args[1]]
46 return res
47
48
49 # 读取图片转换64
50 def file_base_64(path):
51 with open(path, 'rb') as f:
52 base64_data = base64.b64encode(f.read())
53 data = base64_data.decode()
54 return data
1 # @Time : 2022/10/31 18:14
2 # @Author : 付孟奇
3 from util.HandleFile import load_yaml_file
4 from util.HandleDB import db_load
5 from config.VendorPath import base_path, global_path
6 import os
7 import json
8
9 ddl_file_path = os.path.join(base_path, 'sql', 'speech_variable.yaml')
10
11
12 class InitLoad:
13 def __init__(self):
14 print('111')
15
16 # 初始化数据库
17 def db_ini(self):
18 # 加载数据库建表SQL
19 res_yaml = load_yaml_file(ddl_file_path)
20 # 执行插入SQL
21 db_load.execute_db(res_yaml)
22 self.handle_global()
23
24 # 清空公共参数文件内容
25 def handle_global(self):
26 data = {}
27 json.dump(data, open(global_path, 'w'), indent=4)
28
29
30 handle_init = InitLoad()
31 if __name__ == '__main__':
32 handle_init.handle_global()
1 # @Time : 2022/8/22 15:40
2 # @Author : 付孟奇
3 import sys
4
5 '''
6 1、项目名称
7 2、项目环境
8 3、当前环境域名
9 4、邮件发送地址
10 5、邮件名称
11 6、联系人电话
12 '''
13
14
15 def handle_jenkins():
16 config_info = {}
17 # Jenkins参数
18 if len(sys.argv) > 1:
19 config_info['pro'] = sys.argv[1]
20 config_info['env'] = sys.argv[2]
21 config_info['host'] = sys.argv[3]
22 config_info['email'] = sys.argv[4]
23 config_info['title'] = sys.argv[5]
24 else:
25 # 本地兼容
26 config_info['pro'] = '话术变量'
27 config_info['env'] = 'staging'
28 config_info['host'] = 'https://staging-moonlight-life-video.situdata.com' # https://staging-moonlight-life-video.situdata.com
29 config_info['email'] = 'fumengqi@situdata.com'
30 config_info['title'] = '本地调试'
31 config_info['phone'] = '15737319294'
32 return config_info
1 # @Time : 2022/8/22 15:37
2 # @Author : 付孟奇
3 import logging
4 from config.VendorPath import log_path
5
6
7 class Log:
8 def insert_log(self, level, message):
9 # 创建一个logger
10 logger = logging.getLogger()
11 logger.setLevel(logging.DEBUG)
12 # 创建一个handler,用于写入日志文件
13 fh = logging.FileHandler(log_path, 'a', encoding='utf-8')
14 fh.setLevel(logging.DEBUG)
15 # 再创建一个handler,用于输出到控制台
16 ch = logging.StreamHandler()
17 ch.setLevel(logging.DEBUG)
18 # 定义handler的输出格式
19 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
20 fh.setFormatter(formatter)
21 ch.setFormatter(formatter)
22 # 给logger添加handler
23 logger.addHandler(fh)
24 logger.addHandler(ch)
25 # 记录一条日志
26 if level == 'info':
27 logger.info(message)
28 elif level == 'debug':
29 logger.debug(message)
30 elif level == 'warning':
31 logger.warning(message)
32 elif level == 'error':
33 logger.error(message)
34 logger.removeHandler(ch)
35 logger.removeHandler(fh)
36 # 关闭打开的文件
37 fh.close()
38
39 def debug(self, message):
40 self.insert_log('debug', message)
41
42 def info(self, message):
43 self.insert_log('info', message)
44
45 def warning(self, message):
46 self.insert_log('warning', message)
47
48 def error(self, message):
49 self.insert_log('error', message)
50
51
52 logger = Log()
1 # @Time : 2022/8/24 11:40
2 # @Author : 付孟奇
3 from requests import Timeout, RequestException
4 import requests
5
6
7 class DealRequest:
8 def __init__(self, method, url, headers, params):
9 self.method = method
10 self.url = url
11 self.headers = headers
12 self.params = params
13
14 def return_response(self):
15 return self.res_request()
16
17 def res_request(self):
18 if self.method == 'POST':
19 res = self.res_post(self.url, self.headers, self.params)
20 elif self.method == "GET":
21 res = self.res_get(self.url, self.headers, self.params)
22 elif self.method == "PUT":
23 res = self.res_put(url=self.url, params=self.params)
24 elif self.method == "DELETE":
25 res = self.res_delete(url=self.url, params=self.params, headers=self.headers)
26 else:
27 res = {'code': 1, 'result': '接口请求失败,当前请求方式不支持'}
28 return res
29
30 def res_post(self, url, headers, params):
31 try:
32 res = requests.request('POST', url, headers=headers, json=params)
33 if res.status_code == 200:
34 return res.json()
35 else:
36 return {'code': 1, 'result': '接口请求失败,返回状态码:%s' % str(res.status_code)}
37 except Timeout as e:
38 return {'code': 1, 'result': '请求超时:%s' % e}
39 except RequestException as e:
40 return {'code': 1, 'result': '请求异常:%s' % e}
41 except Exception as e:
42 return {'code': 1, 'result': 'post请求出错,出错原因:%s' % e}
43
44 def res_get(self, url, headers, params):
45 try:
46 if params == '':
47 res = requests.get(url, headers=headers)
48 else:
49 res = requests.get(url, headers=headers, params=params)
50 if res.status_code == 200:
51 return res.json()
52 else:
53 return {'code': 1, 'result': '接口请求失败,返回状态码:%s' % str(res.status_code)}
54 except Timeout as e:
55 return {'code': 1, 'result': '请求超时:%s' % e}
56 except RequestException as e:
57 return {'code': 1, 'result': '请求异常:%s' % e}
58 except Exception as e:
59 return {'code': 1, 'result': 'get请求出错,出错原因:%s' % e}
60
61 def res_put(self, url, params):
62 try:
63 r = requests.put(url, params=params)
64 except Timeout as e:
65 return {'code': 1, 'result': '请求超时:%s' % e}
66 except RequestException as e:
67 return {'code': 1, 'result': '请求异常:%s' % e}
68 except Exception as e:
69 return {'code': 1, 'result': 'put请求出错,出错原因:%s' % e}
70
71 def res_delete(self, url, headers, params):
72 try:
73 r = requests.delete(url, headers=headers, params=params)
74 except Timeout as e:
75 return {'code': 1, 'result': '请求超时:%s' % e}
76 except RequestException as e:
77 return {'code': 1, 'result': '请求异常:%s' % e}
78 except Exception as e:
79 return {'code': 1, 'result': 'delete请求出错,出错原因:%s' % e}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!