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

1、目的

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

2、分析

A、接口含body和head部分,其中body中的某些变量为必填字段,包含用户的信息,接口可整理成body.xml、head.xml文件。

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

C、逐行读取list.txt文件,将其用户信息对应替换到body.xml文件中。然后使用curl方法发送接口信息。

D、将开户结果输出至result.log文件。

3、脚本实现

 1 #! /bin/sh
 2 
 3 Bxml=`dirname $0`/body.xml
 4 Hxml=`dirname $0`/head.xml
 5 File=`dirname $0`/list.txt
 6 Rfile=`dirname $0`/result.log
 7 
 8 echo "Error output ${Rfile}."
 9 echo "START ..."
10 echo "" > ${Rfile}
11 
12 while read LINE; do
13 
14     tel=`echo $LINE | awk '{print $1}'`
15     stbid=`echo $LINE | awk '{print $2}'`
16 
17     Phone=${tel}
18     Stbid=${stbid}
19     Date=`date +20%y%m%d%H%M%S`
20     PkgSeq=${Date}
21     Seq=`awk 'BEGIN{srand();print rand()*1000000}'`
22 
23 
24     sed -i  "s/<PkgSeq>.*<\/PkgSeq>/<PkgSeq>${Date}<\/PkgSeq>/g" ${Bxml}
25     sed -i  "s/<IDV>.*<\/IDV>/<IDV>${Phone}<\/IDV>/g" ${Bxml}
26     sed -i  "s/<OprT>.*<\/OprT>/<OprT>${Date}<\/OprT>/g" ${Bxml}
27     sed -i  "s/<Seq>.*<\/Seq>/<Seq>${Seq}<\/Seq>/g" ${Bxml}
28     sed -i  "s/<StbID>.*<\/StbID>/<StbID>${Stbid}<\/StbID>/g" ${Bxml}
29     sed -i  "s/<Account>.*<\/Account>/<Account>${Phone}<\/Account>/g" ${Bxml}
30     sed -i  "s/<EffetiTime>.*<\/EffetiTime>/<EffetiTime>${Date}<\/EffetiTime>/g" ${Bxml}
31 
32     sed -i  "s/<TransIDOTime>.*<\/TransIDOTime>/<TransIDOTime>${Date}<\/TransIDOTime>/g" ${Hxml}
33 
34 
35     curl -v  --connect-timeout 3 -F "[email protected];type=text/plain; charset=UTF-8" -F "[email protected];type=text/plain; charset=UTF-8" http://IP:6600/bossManagement 2>/dev/null
36     ret=$?
37     if [ $ret -ne 0 ]; then
38         echo "$LINE error($ret)"
39         echo "$LINE error($ret)" >> ${Rfile}
40     fi
41         sleep 2
42 done < ${File}
43 
44 
45 echo "END"

猜你喜欢

转载自www.cnblogs.com/wenquanli/p/9717162.html