- psdshow2015-03-31论坛元老64439
- 本帖最后由 psdshow 于 2015-11-22 16:26 编辑 *
- - /dev/null 2>&1
- - $type = $_SERVER['argv'][1];
- - if($type == 'en'){
- $json_url = 'https://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability2';
- }else{
- $type = 'ca';
- $json_url = 'https://ws.ovh.ca/dedicated/r2/ws.dispatcher/getAvailability2';
- }
- - function _curl_data($url){
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- $return_data = curl_exec($curl);
- curl_close($curl);
- - return $return_data;
- }
- - $data = _curl_data($json_url);
- $obj = json_decode($data);
- - if(!is_object($obj)){
- echo '返回值不正确';
- exit;
- }
- - //监控型号,这2个型号都是5欧的
- $check_ava = array('142cask9','150sk10');
- - if(!isset($obj->answer)){
- exit;
- }
- - $answer = $obj->answer;
- $availability = $answer->availability;
- - if(count($availability) reference;
- - if(!in_array($reference,$check_ava)){
- continue;
- }
- - $zones = $ava->zones;
- - foreach($zones as $zone){
- if($zone->availability == 'unavailable' || $zone->availability == 'unknown'){
- continue;
- }
- - //有存货
- $ava_array[] = $type.' - '.$reference;
- }
- }
- - if(count($ava_array) == 0){
- exit;
- }
- - $message = implode(',',$ava_array);
- - //判断是否需要发送短信 每小时只发送一次,避免短信用的太快
- $sms_log = '/var/www/html/sms/'.$type.'.sms.log';
- $need_sms = false;
- if(!is_file($sms_log)){
- $fp = fopen($sms_log,'w');
- fwrite($fp,time());
- fclose($fp);
- //需要发送
- $need_sms = true;
- }else{
- $time = file_get_contents($sms_log);
- if(time() - $time > 3600){
- //需要发送
- $need_sms = true;
- $fp = fopen($sms_log,'w');
- fwrite($fp,time());
- fclose($fp);
- }
- }
- - if($need_sms){
- /*
- //你可以给自己发送短信 或者邮件
- $phone = '13800138000';
- include('/var/www/html/sms/api/sms.inc.php');
- $mobile_phone = trim($phone);
- $mobile_code = rand(100000,999999);
- $today = date('Y-m-d');
- $create_time = time();
- $sms = new SMS();
- $msg = 'kim有货.'.$message.', 30分钟内有效.';
- $msg = iconv('UTF-8','GBK',$msg);
- $sms->sendSMS($mobile_phone,$msg,'',2);
- if($sms->getCode() == 2000) {
- echo 'Done';
- }else{
- echo 'Faild';
- }
- */
- }复制代码