├── config.ini ├── README.md ├── main.php └── kuaidi.php /config.ini: -------------------------------------------------------------------------------- 1 | 1200722815552 = 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kuaidi 2 | 自动查快递 3 | 4 | ### INTRODUCTION 5 | 6 | 下完单后会不会不自觉地查快递信息? 7 | 8 | 让机器来代劳吧! 9 | 10 | 利用[快递100](http://kuaidi100.com)的接口查快递实时信息 11 | 12 | 利用[Server酱](http://sc.ftqq.com/2.version)来微信通知 13 | 14 | ### USAGE 15 | 16 | 1. 把```kuaidi.php```里的```appkey```修改成你的 17 | 2. 在```config.ini```里添加快递单号(要符合```php.ini```格式) 18 | 3. 添加一个crontab(一小时一次即可)运行```main.php```,然后等消息吧 19 | 20 | 21 | Have fun ! 22 | 23 | -------------------------------------------------------------------------------- /main.php: -------------------------------------------------------------------------------- 1 | $v) { 11 | $result = query($k); 12 | if (empty($result['data'])) 13 | continue; 14 | $data = $result['data'][0]; 15 | if (strtotime($data['time']) > $v) { 16 | $msg = "{$result['com']} ({$k}) \n {$data['time']} \n {$data['context']}"; 17 | sendNotice($msg); 18 | $new_wait_query_nums[$k] = strtotime($data['time']); 19 | } else { 20 | $new_wait_query_nums[$k] = $v; 21 | } 22 | sleep(1); 23 | } 24 | 25 | if ($new_wait_query_nums != $wait_query_nums) { 26 | write_ini_file($config_file, $new_wait_query_nums); 27 | } 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /kuaidi.php: -------------------------------------------------------------------------------- 1 | $item) { 66 | if (is_array($item)) { 67 | $content .= "\n[{$key}]\n"; 68 | foreach ($item as $key2 => $item2) { 69 | if (is_numeric($item2) || is_bool($item2)) 70 | $content .= "{$key2} = {$item2}\n"; 71 | else 72 | $content .= "{$key2} = \"{$item2}\"\n"; 73 | } 74 | }else { 75 | if (is_numeric($item) || is_bool($item)) 76 | $content .= "{$key} = {$item}\n"; 77 | else 78 | $content .= "{$key} = \"{$item}\"\n"; 79 | } 80 | } 81 | if (!$handle = fopen($path, 'w')) { 82 | return false; 83 | } 84 | 85 | if (!fwrite($handle, $content)) { 86 | return false; 87 | } 88 | 89 | fclose($handle); 90 | return true; 91 | } 92 | 93 | /** 94 | * 发通知 95 | * 96 | * @param $msg string 97 | * 98 | * @return void 99 | */ 100 | function sendNotice($msg) 101 | { 102 | global $server_chan_app_key; 103 | $title = '快递信息'; 104 | $query_string = http_build_query( 105 | array( 106 | 'text' => $title, 107 | 'desp' => $msg, 108 | ) 109 | ); 110 | $url = 'http://sc.ftqq.com/' . $server_chan_app_key . '.send?' . $query_string; 111 | file_get_contents($url); 112 | } --------------------------------------------------------------------------------