当前位置: 移动技术网 > IT编程>脚本编程>Python > 模拟开户接口,使用python脚本实现批量用户开通

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

2018年09月28日  | 移动技术网IT编程  | 我要评论

网球排名,欲乱我的皇兄,爱彩网

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': '<?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())

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网