Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
    public static function waring($msg)
    {
        exec("gnome-terminal -x bash -c \"date;echo 有票啦 {$msg}; read;\"");
        exit;
    }
    public static function show($msg)
    {
        echo "{$msg}\n";
    }
}
/*
 * HZH 杭州东
 * ARH 鳌江
 * php 123.php 2016-02-04 HZH ARH
 */
if (PHP_SAPI == 'cli' && isset($argv[0]) && $argv[0] == basename(__FILE__)) {
    var_dump($argv);
    if (isset($argv[1])) {
        train::$query_date = $argv[1];
        //出发时间
    }
    if (isset($argv[2])) {
        train::$from_station = $argv[2];
        //出发站
    }
    if (isset($argv[3])) {
        train::$to_station = $argv[3];
        //终点站
    }
}
train::main();