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

不言
发布: 2018-09-28 14:18:20
转载
2565 人浏览过

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

1、目的

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

2、分析

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

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

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

3、脚本实现

#!/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={
                    &#39;xmlhead&#39;: &#39;<?xml version="1.0" encoding="UTF-8"?> <InterBOSS>&#39;
                               &#39;<Version>0100</Version>&#39;
                               &#39;<TestFlag>0</TestFlag>&#39;
                               &#39;<BIPType>&#39;
                               &#39;<BIPCode>IPTVB412</BIPCode>&#39;
                               &#39;<ActivityCode>T2101057</ActivityCode>&#39;
                               &#39;<ActionCode>0</ActionCode>&#39;
                               &#39;</BIPType>&#39;
                               &#39;<RoutingInfo>&#39;
                               &#39;<OrigDomain>BOSS</OrigDomain>&#39;
                               &#39;<RouteType>00</RouteType>&#39;
                               &#39;<Routing>&#39;
                               &#39;<HomeDomain>OTT</HomeDomain>&#39;
                               &#39;<RouteValue>210</RouteValue>&#39;
                               &#39;</Routing>&#39;
                               &#39;</RoutingInfo>&#39;
                               &#39;<TransInfo>&#39;
                               &#39;<SessionID>2018092517323481311686</SessionID>&#39;
                               &#39;<TransIDO>2018092517323416388122</TransIDO>&#39;
                               &#39;<TransIDOTime>20180211173234</TransIDOTime>&#39;
                               &#39;</TransInfo> </InterBOSS>&#39;,
                    &#39;xmlbody&#39;: &#39;<?xml version="1.0" encoding="UTF-8"?> <InterBOSS>     <SvcCont><![CDATA[<?xml &#39;
                               &#39;version="1.0" encoding="UTF-8"?> <OrdSynReq>&#39;
                               &#39;<PkgSeq>73120180111000007</PkgSeq>&#39;
                               &#39;<RecNum>1</RecNum>&#39;
                               &#39;<UD1>&#39;
                               &#39;<IDType>01</IDType>&#39;
                               &#39;<IDV>%s</IDV>&#39;
                               &#39;<Brand>09</Brand>&#39;
                               &#39;<Opr>06</Opr>&#39;
                               &#39;<OprT>20180925171922</OprT>&#39;
                               &#39;<BizType>52</BizType>&#39;
                               &#39;<Seq>8121</Seq>&#39;
                               &#39;<BroadbandID>738815023717</BroadbandID>&#39;
                               &#39;<ZipCode></ZipCode>&#39;
                               &#39;<Address></Address>&#39;
                               &#39;<UserName></UserName>&#39;
                               &#39;<UserSex></UserSex>&#39;
                               &#39;<IDCardType></IDCardType>&#39;
                               &#39;<IDCardNum></IDCardNum>&#39;
                               &#39;<AreaCode>K381</AreaCode>&#39;
                               &#39;<GroupID></GroupID>&#39;
                               &#39;<POCont>&#39;
                               &#39;<ActType>1</ActType>&#39;
                               &#39;<StbID>%s</StbID>&#39;
                               &#39;<Account>%s</Account>&#39;
                               &#39;<Password>111111</Password>&#39;
                               &#39;<ChrgType>2</ChrgType>&#39;
                               &#39;<EffetiTime>20180925171922</EffetiTime>&#39;
                               &#39;<Channel>08</Channel>&#39;
                               &#39;<SPID>mango</SPID>&#39;
                               &#39;<BizCode>defaultBasicProduct</BizCode>&#39;
                               &#39;<BizKind>01</BizKind>&#39;
                               &#39;</POCont>&#39;
                               &#39;</UD1> </OrdSynReq> &#39;
                               &#39;]]></SvcCont> </InterBOSS>&#39; % (acc_num, stb_id, account)
                }
        )
        header = {&#39;Content-Type&#39;: mul.content_type}
        body = mul
        response = requests.post(url, data=body, headers=header)
        print response.content
        print response.status_code


if __name__ == &#39;__main__&#39;:
    ott_boss(get_txt_after_check_device())
登录后复制

以上是python脚本如何模拟接口实现批量用户开通(代码)的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:cnblogs.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板