目录
一、Fiddler抓取小程序包
二、分析抓到的包
一、获取全部车辆列表
二、获取班车停靠点
三、Python实现预约车辆
一、获取明天的日期
二、获取班车id
三、获取车辆停靠点
四、Server酱实现消息提示
四、利用宝塔面板,进行定时执行脚本,实现自动约车
一、Fiddler抓小程序包
此过程可能需要代理ip 会用到Proxifier工具
二、分析抓到的包
一、获取全部车辆列表
其中token、openid的值一样 startDate、endDate为获取的日期,访问此接口将返回全部班车数据,格式为json格式,在其中可以获取到车次的id
https://api.****.cn/interface?version=a-3.7.9&method=passenger.listRegularNew&token={token}&store=applet&isQywx=0&companyId=****&startDate={tomorrow}&endDate={tomorrow}&keyword=&schedulingStatus=127&offset=0&length=-1&sortKey=start_time&sortType=ASC&needInfo=true&openid={token}&lang=zh_cn
二、获取班车停靠点
startStopId、endStopId为班车的上车站和下车站
三、Python实现预约车辆
一、获取明天的日期
由于预约的是第二天的车辆,所以需要获取的是第二天的日期
from datetime import datetime,timedelta
nowtime = datetime.now()
nowtime = nowtime + timedelta(days=1)
tomorrow = nowtime.strftime('%Y-%m-%d') #取明天时间
二、获取班车id
我们可以对车辆的起始点和车辆的牌照在json数据中来进行获取车辆的id
def qucheng(self):global id, url1for num in data["data"]:if num["startStop"] == "***" and num["plateNo"] == "***": #前一个参数为起始点 后面为车牌号id = num["id"]print(id)
三、获取车辆停靠点
同获取班车id一样,我们可以在获取到的班车停靠点的json数据中,搜索我们想要上下车的停靠id
for stop in stopdata["data"]:if stop["stopName"] == "******** : #上车站stopid = stop["stopId"]print(stopid)for stop1 in stopdata["data"]:if stop1["stopName"] == "*******": #下车站stopid1 = stop1["stopId"]print(stopid1)
最后将所有获取到的参数填入接口中,进行访问就可以了
四、Server酱实现消息提示
def send_msg(self):url = "https://sctapi.ftqq.com/%s.send" % SENDKEYdata = {"title": self.response1,}resp = requests.post(url, data=data)return resp.json()
四、利用宝塔面板,进行定时执行脚本,实现自动约车
在宝塔面板中安装Python项目管理器,添加项目,安装需要的模块,最后用计划任务中的shell脚本来实现定时发送。