最近有个朋友找我,要给某一网站的某一功能做批量的操作。综合评估了一下,写了个脚本,各位可以参考。
#获取手机号
echo "请输入手机号:"
read phone
curl 'https://XXX.XXX.XXX/app/1.0/web/1.0/code/sms/mobile' \
-H 'Connection: keep-alive' \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'DNT: 1' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'Origin: https://aq.115.com' \
-H 'Sec-Fetch-Site: same-site' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: https://aq.115.com/' \
-H 'Accept-Language: zh-CN,zh;q=0.9' \
-H 'Cookie: PHPSESSID=uifm5d14cf22na6211s1tcu3k7;
USERSESSIONID=82b5da879ef5bcdafca7ed67ca650a87cd4eb7c2f90e75a6fd2854e04aa2bea9;
UM_distinctid=1777f9e1678154-0a4c5e57d12522-33657309-1ea000-1777f9e1679ca6;
acw_tc=784e2ca316127538031297598e28680ed3faf797783015e0fd6a2b05160a6e; 115_lang=zh' \
--data-raw 'mobile='+$phone+'&country=CN&tpl=login_from_sms&token=259343eee29fde71f4774547db78da2127f2d20b' \
--compressed#获取验证码进行登录
echo "请输入验证码:"
read vcode
server=$(curl 'https://XXX.XXX.XXX/app/1.0/web/1.0/login/sms' \
-H 'Connection: keep-alive' \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'DNT: 1' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'Origin: https://aq.115.com' \
-H 'Sec-Fetch-Site: same-site' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: https://aq.115.com/' \
-H 'Accept-Language: zh-CN,zh;q=0.9' \
-H 'Cookie: PHPSESSID=uifm5d14cf22na6211s1tcu3k7;
USERSESSIONID=82b5da879ef5bcdafca7ed67ca650a87cd4eb7c2f90e75a6fd2854e04aa2bea9;
UM_distinctid=1777f9e1678154-0a4c5e57d12522-33657309-1ea000-1777f9e1679ca6;
acw_tc=784e2ca316127538031297598e28680ed3faf797783015e0fd6a2b05160a6e;
115_lang=zh' \
--data-raw 'code='+$vcode+'&sso_mode=1&country=CN&account='+$phone+'&token=259343eee29fde71f4774547db78da2127f2d20b' \
--compressed
)#得到cookie中的信息
str1=${server#*UID:}
UID=${str1%%,*}
str2=${server#*CID:}
CID=${str2%%,*}
str3=${server#*SEID:}
SEID=${str3%%%%\}*}
echo $UID
echo $CID
echo $SEID
while read line
do
array=(${line//,/ })
#循环遍历请求进行兑换
curl 'https://XXX.XXX.XXX/order/coupon/?t=space' \
-H 'Connection: keep-alive' \
-H 'Cache-Control: max-age=0' \
-H 'Origin: https://vip.115.com' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'DNT: 1' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: navigate' \
-H 'Sec-Fetch-User: ?1' \
-H 'Sec-Fetch-Dest: document' \
-H 'Referer: https://vip.115.com/order/coupon/?t=space' \
-H 'Accept-Language: zh-CN,zh;q=0.9' \
-H 'Cookie: UM_distinctid=177803146bbcb6-051dbd33331997-33657309-1ea000-177803146bc473; USERSESSIONID=94d7a4bdbbf9276a9663eff3bda296f9ff8ce4a8b2ef0406d6a46c99f256ff34; PHPSESSID=2irqco84fp41bpilrqfohpp51u; 115_lang=zh; PAY_PREFERER=index_info_vip; PAY_WAP=0; PAY_MIN=0; payment=weixin_ntv; acw_tc=784e2c9e16127784274525248e7b443964a7693a3d4be954d53109e4dda970; loginType=1; UID='+$UID+';CID='+$CID+';SEID='+$SEID \
--data-raw 'coupon='+${array[0]}+'&user='+${array[1]}+'&vcode=aaaa' \
--compressed
done < duihuan.txt