示例#1
0
文件: 123.php 项目: fly0311/12306
 public static function init()
 {
     $args = getopt('f:t:d:o:', array('tc::'));
     if (isset($args['f']) && isset($args['t']) && isset($args['d'])) {
         self::$query_date = $args['d'];
         self::$from_station_name = $args['f'];
         self::$to_station_name = $args['t'];
         self::$station_train_code = isset($args['tc']) ? $args['tc'] : '';
     } else {
         $usage = "请输入参数:\n-f\t出发地,如北京 \n-t\t目的地,如郓城 \n-d\t出发日,如2016-01-06 \n--tc\t车次,支持多车次查询如--tc='D2320,D2322'";
         self::show($usage);
         exit;
     }
     $stations = explode('|', self::$station_names);
     $total = count($stations);
     for ($i = 0; $i < $total && (empty(self::$from_station_code) || empty(self::$to_station_code)); $i++) {
         if (empty(self::$from_station_code) && $stations[$i] == self::$from_station_name) {
             self::$from_station_code = isset($stations[$i + 1]) ? $stations[$i + 1] : '';
         } else {
             if (empty(self::$to_station_code) && $stations[$i] == self::$to_station_name) {
                 self::$to_station_code = isset($stations[$i + 1]) ? $stations[$i + 1] : '';
             }
         }
     }
     if (empty(self::$from_station_code) || empty(self::$to_station_code) || empty(self::$query_date)) {
         $usage = "请输入参数:\n-f\t出发地,如北京 \n-t\t目的地,如郓城 \n-d\t出发日,如2016-01-06 \n";
         self::show($usage);
         exit;
     }
 }
示例#2
0
文件: 123.php 项目: hengqujushi/12306
                } else {
                    var_dump($restul);
                }
            }
        } while (true);
    }
    public static function do_query($rt)
    {
        foreach ($rt['data']['datas'] as $item) {
            $msg = "{$item['station_train_code']}\t{$item['gg_num']}\t{$item['gr_num']}\t{$item['qt_num']}\t{$item['rw_num']}\t{$item['rz_num']}\t{$item['tz_num']}\t{$item['wz_num']}\t{$item['yb_num']}\t{$item['yw_num']}\t{$item['yz_num']}\t{$item['ze_num']}\t{$item['zy_num']}\t{$item['swz_num']}";
            self::show($msg);
            if (is_numeric($item['gg_num']) && $item['gg_num'] > 0 || is_numeric($item['gr_num']) && $item['gr_num'] > 0 || is_numeric($item['qt_num']) && $item['qt_num'] > 0 || is_numeric($item['rw_num']) && $item['rw_num'] > 0 || is_numeric($item['rz_num']) && $item['rz_num'] > 0 || is_numeric($item['tz_num']) && $item['tz_num'] > 0 || is_numeric($item['wz_num']) && $item['wz_num'] > 0 || is_numeric($item['yb_num']) && $item['yb_num'] > 0 || is_numeric($item['yw_num']) && $item['yw_num'] > 0 || is_numeric($item['yz_num']) && $item['yz_num'] > 0 || is_numeric($item['ze_num']) && $item['ze_num'] > 0 || is_numeric($item['zy_num']) && $item['zy_num'] > 0 || is_numeric($item['swz_num']) && $item['swz_num'] > 0) {
                self::waring($msg);
            }
        }
        self::$query_num++;
        $msg = sprintf("\t\t\t\t%s\t%s => %s\t\tquery time: %s", self::$query_date, self::$from_station, self::$to_station, self::$query_num);
        self::show($msg);
    }
    public static function waring($msg)
    {
        exec("gnome-terminal -x bash -c \"date;echo 有票啦 {$msg}; read;\"");
        exit;
    }
    public static function show($msg)
    {
        echo "{$msg}\n";
    }
}
train::main();
示例#3
0
文件: 123.php 项目: guoyu07/12306
 public static function init_param()
 {
     $args = getopt('f:t:d:m:n:o');
     //出发地,目的地,出发日
     if (isset($args['f']) && isset($args['t']) && isset($args['d'])) {
         self::$query_date = strtotime($args['d']) ? $args['d'] : '';
         self::$from_station_name = $args['f'];
         self::$to_station_name = $args['t'];
         self::$from_station_code = isset(self::$station[$args['f']]) ? self::$station[$args['f']] : '';
         self::$to_station_code = isset(self::$station[$args['t']]) ? self::$station[$args['t']] : '';
     }
     if (empty(self::$from_station_code) || empty(self::$to_station_code) || empty(self::$query_date)) {
         self::usage();
     }
     //指定车次
     if (isset($args['m'])) {
         $trains = explode(',', $args['m']);
         foreach ($trains as $train) {
             self::$limit_train_list[] = strtoupper($train);
         }
     }
     //指定车座
     if (isset($args['n'])) {
         $tickets = explode(',', $args['n']);
         foreach ($tickets as $ticket) {
             if (!isset(self::$ticket_hash[$ticket])) {
                 self::error("无效车座: {$ticket}");
             }
             self::$limit_ticket_list[] = self::$ticket_hash[$ticket];
         }
     } else {
         self::$limit_ticket_list = self::$ticket_hash;
     }
 }