|
难道传说中的乐善好施就是我?
#Readme !
1.微信推送: 只支持微信推送,更换自己的key,需要到https://pushbear.ftqq.com/admin/#/申请一下key。替换代码里的push_key字符。
2.脚本所在目录要要有可写权限,window系统忽略不计;linux系统,可以执行
touch cache.txt
chmod 777 cache.txt
3.linux 可以配合crontab 做定时任务,如
* * * * * /usr/bin/php -f /path/to/script/file
4. Window 可用Window部分启动代码代替Linux系统的代码。 用浏览器访问一次后,就把页面关闭即可。
- <?php
- /**
- #Readme !
- 1.微信推送: 只支持微信推送,更换自己的key,需要到https://pushbear.ftqq.com/admin/#/申请一下key。替换代码里的push_key字符。
- 2.脚本所在目录要要有可写权限,window系统忽略不计;linux系统,可以执行
- touch cache.txt
- chmod 777 cache.txt
- 3.linux 可以配合crontab 做定时任务,如
- * * * * * /usr/bin/php -f /path/to/script/file
- 4. Window 可用Window部分启动代码代替Linux系统的代码。 用浏览器访问一次后,就把页面关闭即可。
- **/
- #Window系统的代码
- // ignore_user_abort(1);
- // set_time_limit(0);
- // $hh = new Helper();
- // while(true)
- // {
- // $hh->Start(); //启动监控
- // sleep(30); //休眠三十秒
- // }
- #linux系统的代码
- $hh = new Helper();// {
- $hh->Start(); //启动监控// }
- class Helper{
- //------------------------------------------------------------------------------
- // 配置-改
- //------------------------------------------------------------------------------
- public $push_key="1410-dfe93ab971cc199ed74b961822b92f13";
-
- //start
- function Start()
- {
- $key = '"price":"22.';
- $stamp =time() . random_int(100,999);
- $data = file_get_contents('https://www.hetzner.com/a_hz_serverboerse/live_data.json?m='.$stamp);
- if(!$this->cache_check($data))
- {
- $this->cache_add($data);
- if(strpos($data,$key))
- {
- echo "NEW PRODUCT";
- $this->send('HZ-22上新','22欧上新');
- }
- }
- }
- //message send
- function send($title, $desp ) {
- $title =urlencode($title)."_".rand(0,99999);
- $desp =urlencode($desp);
- file_get_contents("https://pushbear.ftqq.com/sub?sendkey=".$this->push_key."&text=$title&desp=$desp");
- }
- //cache add
- function cache_add($content)
- {
- $content=md5($content);
- file_put_contents("cache.txt",$content);
- }
- //cache delete
- function cache_check($content)
- {
- $content=md5($content);
- $str = file_get_contents("cache.txt");
- if(strpos($str,$content))
- return true;
- else
- return false;
- }
- }
复制代码 |
|