python脚本如何模拟接口实现批量用户开通(代码)


本文摘自php中文网,作者不言,侵删。

本篇文章给大家带来的内容是关于python脚本如何模拟接口实现批量用户开通(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

1、目的

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

2、分析

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

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

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

3、脚本实现

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import requests

from requests_toolbelt.multipart.encoder import MultipartEncoder

 

def get_txt_after_check_device():

    ott_after_check_device = '.\\ott_after_check_device.txt'

    f = open(ott_after_check_device)

    lines = f.readlines()

    all_list_device = []

    for line in lines:

        line = line.replace("\n", '')

        list_device = line.split(',')

        all_list_device.append(list_device)

    return all_list_device

 

 

def ott_boss(list_device):

    sleep_time = 0.001

    # print len(list_device)

    for i in range(len(list_device)):

        print u'新开户数 :', i + 1

        time.sleep(sleep_time)

        acc_num = list_device[i][0]

        stb_id = list_device[i][1]

        print 'STBID : ', stb_id

        account = list_device[i][2]

        url = 'http://10.2.214.133:6600/oss/rest/mango/bossManagement/syncOrder'

        mul = MultipartEncoder(

                fields={

                    'xmlhead': '<?xml version="1.0" encoding="UTF-8"?> <InterBOSS>'

                               '<Version>0100</Version>'

                               '<TestFlag>0</TestFlag>'

                               '<BIPType>'

                               '<BIPCode>IPTVB412</BIPCode>'

                               '<ActivityCode>T2101057</ActivityCode>'

                               '<ActionCode>0</ActionCode>'

                               '</BIPType>'

                               '<RoutingInfo>'

                               '<OrigDomain>BOSS</OrigDomain>'

                               '<RouteType>00</RouteType>'

                               '<Routing>'

                               '<HomeDomain>OTT</HomeDomain>'

                               '<RouteValue>210</RouteValue>'

                               '</Routing>'

                               '</RoutingInfo>'

                               '<TransInfo>'

                               '<SessionID>2018092517323481311686</SessionID>'

                               '<TransIDO>2018092517323416388122</TransIDO>'

                               '<TransIDOTime>20180211173234</TransIDOTime>'

                               '</TransInfo> </InterBOSS>',

                    'xmlbody': '<?xml version="1.0" encoding="UTF-8"?> <InterBOSS>     <SvcCont><![CDATA[<?xml '

                               'version="1.0" encoding="UTF-8"?> <OrdSynReq>'

                               '<PkgSeq>73120180111000007</PkgSeq>'

                               '<RecNum>1</RecNum>'

                               '<UD1>'

                               '<IDType>01</IDType>'

                               '<IDV>%s</IDV>'

                               '<Brand>09</Brand>'

                               '<Opr>06</Opr>'

                               '<OprT>20180925171922</OprT>'

                               '<BizType>52</BizType>'

                               '<Seq>8121</Seq>'

                               '<BroadbandID>738815023717</BroadbandID>'

                               '<ZipCode></ZipCode>'

                               '<Address></Address>'

                               '<UserName></UserName>'

                               '<UserSex></UserSex>'

                               '<IDCardType></IDCardType>'

                               '<IDCardNum></IDCardNum>'

                               '<AreaCode>K381</AreaCode>'

                               '<GroupID></GroupID>'

                               '<POCont>'

                               '<ActType>1</ActType>'

                               '<StbID>%s</StbID>'

                               '<Account>%s</Account>'

                               '<Password>111111</Password>'

                               '<ChrgType>2</ChrgType>'

                               '<EffetiTime>20180925171922</EffetiTime>'

                               '<Channel>08</Channel>'

                               '<SPID>mango</SPID>'

                               '<BizCode>defaultBasicProduct</BizCode>'

                               '<BizKind>01</BizKind>'

                               '</POCont>'

                               '</UD1> </OrdSynReq> '

                               ']]></SvcCont> </InterBOSS>' % (acc_num, stb_id, account)

                }

        )

        header = {'Content-Type': mul.content_type}

        body = mul

        response = requests.post(url, data=body, headers=header)

        print response.content

        print response.status_code

 

 

if __name__ == '__main__':

    ott_boss(get_txt_after_check_device())

以上就是python脚本如何模拟接口实现批量用户开通(代码)的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python如何自定义函数

Python参数是什么?实例详解必备与关键字参数

Python gui是什么?

Python函数怎么用

Python的注释有哪些

Python生成随机数的方法_Python

Python set函数是什么

Python中split的用法详解

如何打开Python shell

Python怎么输入变量

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...