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

2020-01-19 14:31:33 浏览数 (1)

1、目的

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

2、分析

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

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

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

3、脚本实现

代码语言:javascript复制
 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': '<?xml version="1.0" encoding="UTF-8"?> <InterBOSS>'
33                                '<Version>0100</Version>'
34                                '<TestFlag>0</TestFlag>'
35                                '<BIPType>'
36                                '<BIPCode>IPTVB412</BIPCode>'
37                                '<ActivityCode>T2101057</ActivityCode>'
38                                '<ActionCode>0</ActionCode>'
39                                '</BIPType>'
40                                '<RoutingInfo>'
41                                '<OrigDomain>BOSS</OrigDomain>'
42                                '<RouteType>00</RouteType>'
43                                '<Routing>'
44                                '<HomeDomain>OTT</HomeDomain>'
45                                '<RouteValue>210</RouteValue>'
46                                '</Routing>'
47                                '</RoutingInfo>'
48                                '<TransInfo>'
49                                '<SessionID>2018092517323481311686</SessionID>'
50                                '<TransIDO>2018092517323416388122</TransIDO>'
51                                '<TransIDOTime>20180211173234</TransIDOTime>'
52                                '</TransInfo> </InterBOSS>',
53                     'xmlbody': '<?xml version="1.0" encoding="UTF-8"?> <InterBOSS>     <SvcCont><![CDATA[<?xml '
54                                'version="1.0" encoding="UTF-8"?> <OrdSynReq>'
55                                '<PkgSeq>73120180111000007</PkgSeq>'
56                                '<RecNum>1</RecNum>'
57                                '<UD1>'
58                                '<IDType>01</IDType>'
59                                '<IDV>%s</IDV>'
60                                '<Brand>09</Brand>'
61                                '<Opr>06</Opr>'
62                                '<OprT>20180925171922</OprT>'
63                                '<BizType>52</BizType>'
64                                '<Seq>8121</Seq>'
65                                '<BroadbandID>738815023717</BroadbandID>'
66                                '<ZipCode></ZipCode>'
67                                '<Address></Address>'
68                                '<UserName></UserName>'
69                                '<UserSex></UserSex>'
70                                '<IDCardType></IDCardType>'
71                                '<IDCardNum></IDCardNum>'
72                                '<AreaCode>K381</AreaCode>'
73                                '<GroupID></GroupID>'
74                                '<POCont>'
75                                '<ActType>1</ActType>'
76                                '<StbID>%s</StbID>'
77                                '<Account>%s</Account>'
78                                '<Password>111111</Password>'
79                                '<ChrgType>2</ChrgType>'
80                                '<EffetiTime>20180925171922</EffetiTime>'
81                                '<Channel>08</Channel>'
82                                '<SPID>mango</SPID>'
83                                '<BizCode>defaultBasicProduct</BizCode>'
84                                '<BizKind>01</BizKind>'
85                                '</POCont>'
86                                '</UD1> </OrdSynReq> '
87                                ']]></SvcCont> </InterBOSS>' % (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())

0 人点赞