模拟开户接口,使用python脚本实现批量用户开通

2021-06-18 08:03

阅读:571

标签:分析   批量   readlines   spl   ipa   time   0.00   env   post   

1、目的

通过模拟接口方法,实现批量用户开通

 

2、分析

A、接口含body和head部分,其中body中的某些变量为必填字段,包含用户的信息。

B、用户信息清单可以整理成ott_after_check_device文件。

C、将ott_after_check_device文件转换成列表数据类型,将其用户信息对应替换到body.xml文件中。

 

3、脚本实现

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 
 4 import requests
 5 from requests_toolbelt.multipart.encoder import MultipartEncoder
 6 
 7 def get_txt_after_check_device():
 8     ott_after_check_device = ‘.\\ott_after_check_device.txt‘
 9     f = open(ott_after_check_device)
10     lines = f.readlines()
11     all_list_device = []
12     for line in lines:
13         line = line.replace("\n", ‘‘)
14         list_device = line.split(‘,‘)
15         all_list_device.append(list_device)
16     return all_list_device
17 
18 
19 def ott_boss(list_device):
20     sleep_time = 0.001
21     # print len(list_device)
22     for i in range(len(list_device)):
23         print u‘新开户数 :‘, i + 1
24         time.sleep(sleep_time)
25         acc_num = list_device[i][0]
26         stb_id = list_device[i][1]
27         print ‘STBID : ‘, stb_id
28         account = list_device[i][2]
29         url = ‘http://10.2.214.133:6600/oss/rest/mango/bossManagement/syncOrder‘
30         mul = MultipartEncoder(
31                 fields={
32                     ‘xmlhead‘: ‘‘
33                                ‘0100‘
34                                ‘0‘
35                                ‘‘
36                                ‘IPTVB412‘
37                                ‘T2101057‘
38                                ‘0‘
39                                ‘‘
40                                ‘‘
41                                ‘BOSS‘
42                                ‘00‘
43                                ‘‘
44                                ‘OTT‘
45                                ‘210‘
46                                ‘‘
47                                ‘‘
48                                ‘‘
49                                ‘2018092517323481311686‘
50                                ‘2018092517323416388122‘
51                                ‘20180211173234‘
52                                ‘ ‘,
53                     ‘xmlbody‘: ‘‘
54                                ‘version="1.0" encoding="UTF-8"?> ‘
55                                ‘73120180111000007‘
56                                ‘1‘
57                                ‘‘
58                                ‘01‘
59                                ‘%s‘
60                                ‘09‘
61                                ‘06‘
62                                ‘20180925171922‘
63                                ‘52‘
64                                ‘8121‘
65                                ‘738815023717‘
66                                ‘‘
67                                ‘‘
68                                ‘‘
69                                ‘‘
70                                ‘‘
71                                ‘‘
72                                ‘K381‘
73                                ‘‘
74                                ‘‘
75                                ‘1‘
76                                ‘%s‘
77                                ‘%s‘
78                                ‘111111‘
79                                ‘2‘
80                                ‘20180925171922‘
81                                ‘08‘
82                                ‘mango‘
83                                ‘defaultBasicProduct‘
84                                ‘01‘
85                                ‘‘
86                                ‘  ‘
87                                ‘]]>‘ % (acc_num, stb_id, account)
88                 }
89         )
90         header = {‘Content-Type‘: mul.content_type}
91         body = mul
92         response = requests.post(url, data=body, headers=header)
93         print response.content
94         print response.status_code
95 
96 
97 if __name__ == ‘__main__‘:
98     ott_boss(get_txt_after_check_device())

 

模拟开户接口,使用python脚本实现批量用户开通

标签:分析   批量   readlines   spl   ipa   time   0.00   env   post   

原文地址:https://www.cnblogs.com/wenquanli/p/9717595.html


评论


亲,登录后才可以留言!