• 本帖最后由 neverno 于 2012-3-18 11:56 编辑 *

没啥技术含量的蛋疼东西。

buyvm要放货了,tw上@他问了下,15刀、25刀年付都有货。
具体北京时间什么时候?看最后演示的页面有倒计时。

用的是他家官方json API,不是之前这里的直接抓取页面判断,邮件需要SMTP。
最后也附上用直接抓取页面判断的方法,修改一下,能用于监控其它的到货通知,不仅是buyvm
。

SAE专属:http://sae.sina.com.cn
===============================
核心代码(自行修改)

"

或- - fetch('http://www.doesbuyvmhavestock.com/automation.json');

  • $f->clean();
  • $json = json_decode($json);
  • $pid = explode(',',$pid);
  • for($i = 0 ; $i setOpt(array( 'from' => $mailfrom ));
  • $mail->setOpt(array( 'to' => $mailto ));
  • $mail->setOpt(array( 'cc' => $mailtocc ));
  • $mail->setOpt(array( 'smtp_host' => $mailsmtp ));
  • $mail->setOpt(array( 'smtp_port' => $mailsmtpport ));
  • $mail->setOpt(array( 'smtp_username' => $mailfrom ));
  • $mail->setOpt(array( 'smtp_password' => $mailpassword ));
  • $mail->setOpt(array( 'subject' => $mailtitle ));
  • $mail->setOpt(array( 'content' => $mailcontent ));
  • $mail->send();
  • if ( $mail->errno() != 0 ) {
  • $mail->setOpt(array( 'subject' => 'error:'.$mail->errmsg() ));
  • $mail->setOpt(array( 'content' => 'code:'.$mail->errno().'

'.$mail->errmsg() ));

  • $mail->send();
  • }
  • }
  • - function checkstock($id) {
  • global $json;
  • for($i = 0 ; $i pid == $id && $json[$i]->qty != 0){
  • sendm('BuyVM '.$json[$i]->name.' 有货啦!','还有 '.$json[$i]->qty.' 个,赶紧去抢吧,地址:https://my.frantech.ca/cart.php?a=add&pid='.$json[$i]->pid);
  • break;
  • }
  • }
  • }
  • - ?>
  • 复制代码保存为任意PHP

添加sae计划任务:
config.yaml(自行修改,默认间隔2分钟)- - name: {项目名}

  • version: {版本号}
  • cron:
  • - description: {描述}
  • url: {文件路径,如index.php}
  • schedule: every 2 mins, offset 5
  • timezone: Beijing
  • 复制代码演示

"

===================================
抓取页面的方法可用于BuyVM以外的监控- fetch($addr);

  • if ($f->httpCode() == 200) {
  • if (!strpos($content,'Out of Stock')) sendm($mailt,$mailc);
  • }
  • if ($f->errno() != 0) echo $f->errmsg();
  • $f->clean();
  • ?>复制代码