代码写的垃圾。属于半成品代码,但是肯定是能用的。。。
比较蛋疼的问题是pushbullet会有40秒左右的消息延迟。。我也正在寻找其他替代软件。。。
功能:
每隔5秒检测kimsufi指定独服是否有货,先注册pushbullet.com,记录access token,手机上装pushbullet app并把提醒打开。有货的话会把消息push到手机上的pushbullet端.手机会弹出提示。脚本暂时一次只检测一个产品,可以复制几份脚本,修改里面的:
$rows=curl_get(KS2); //此处需要改成需要检测的名称
和
ishave("KS2",$rows); //必须要和上面的名称一样,但要加上双引号
两处产品信息,达到同时检测的效果。
执行方法:
cmd或者bash下
php jiankong.php
vps上可以开几个screen监控:
apt-get install screen screen -S jiankongks1 php jiankong.php
多开几个screen或者设置nohup后台运行。。
以下是完整代码:
<?php define("Token", "这里是在pushbullet.com申请到的access token"); define("KS1", "https://www.kimsufi.com/en/order/kimsufi.cgi?hard=150sk10"); define("KS2", "https://www.kimsufi.com/en/order/kimsufi.cgi?hard=150sk20"); define("KS22", "https://www.kimsufi.com/en/order/kimsufi.cgi?hard=150sk22"); define("KS3", "https://www.kimsufi.com/en/order/kimsufi.cgi?hard=150sk30"); define("KS4", "https://www.kimsufi.com/en/order/kimsufi.cgi?hard=150sk40"); define("KS5", "https://www.kimsufi.com/en/order/kimsufi.cgi?hard=150sk50"); //push消息函数 function pushmsg($product,$url) { $curl = curl_init('https://api.pushbullet.com/v2/pushes'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HTTPHEADER, ['Access-Token: '.Token]); curl_setopt($curl, CURLOPT_POSTFIELDS, ["type" => "link", "title" => "Kimsufi-".$product."上货!", "body" => "You have new comment(s)!", "url" => $url]); $response = curl_exec($curl); // print_r($response); } function curl_get($url) { $UGA="AdsBot-Google v3 ( http://www.google.com/adsbot.html)"; $ch = curl_init(); $headers = array(); $headers[] = "Accept: */*"; $headers[] = "Cache-Control: max-age=0"; $headers[] = "Connection: keep-alive"; $headers[] = "Keep-Alive: 300"; $headers[] = "Cookie: caches="; $headers[] = "Accept-Charset: utf-8;ISO-8859-1;iso-8859-2;q=0.7,*;q=0.7"; $headers[] = "Accept-Language: en-us,en;q=0.5"; $headers[] = "Pragma: "; curl_setopt($ch, CURLOPT_USERAGENT, $UGA); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $datas=curl_exec($ch); curl_close($ch); return $datas; } /* function ishave($str) { if(strstr($str,"Choose your Dedicated Server")) { echo "no server...\n"; } else if(strstr($str,"The fastest delivery time in Europe")) { echo "there are Europe server!!!!!!!\n"; } } */ function ishave($product,$str) { switch($product) { case "KS1": if(strstr($str,"Choose your Dedicated Server")) { break; } else { // echo $pruduct."有货!!!".KS1."\n"; pushmsg($product,KS1); break; } case "KS2": if(strstr($str,"Choose your Dedicated Server")) { break; } else { // echo $pruduct."有货!!!".KS2."\n"; pushmsg($product,KS2); break; } case "KS22": if(strstr($str,"Choose your Dedicated Server")) { break; } else { // echo $pruduct."有货!!!".KS22."\n"; pushmsg($product,KS22); break; } case "KS3": if(strstr($str,"Choose your Dedicated Server")) { break; } else { // echo $pruduct."有货!!!".KS3."\n"; pushmsg($product,KS3); break; } case "KS4": if(strstr($str,"Choose your Dedicated Server")) { break; } else { // echo $pruduct."有货!!!".KS4."\n"; pushmsg($product,KS4); break; } case "KS5": if(strstr($str,"Choose your Dedicated Server")) { break; } else { // echo $pruduct."有货!!!".KS5."\n"; pushmsg($product,KS5); break; } default: break; } } while(TRUE) { $stime=microtime(true); $rows=curl_get(KS2); //此处需要改成需要检测的名称 $etime=microtime(true); $total=$etime-$stime; ishave("KS2",$rows); //必须要和上面的名称一样,但要加上双引号 echo "excute time:".$total."\n"; $stime=0; sleep(5); } ?>