全程基本用在线 sdk。不写历程直接看最终成果就好。
kvdb 又慢又不稳,郁闷,只能用下面这个东西。(怪不得文档里面老是去查$ret)
其实精华就是这个 kvget 函数。。。
代码如下
<?php /* so price is actually target price. $vcodepricepair = "code price"; $vphonepwd = "phone pwd"; "vphone" => $vphones = "phone pwd,phone pwd"; $phone => $vlist = "code price,code price"; */ function kvget ($kv, $key) { $ret = false; while(!$ret) $ret = $kv->get("$key"); return $ret; } $kv = new SaeKVClient(); $ret = false; while (!$ret) $ret = $kv->init(); $vphones = kvget($kv, 'vphones'); $vphonepwds = explode(",", $vphones); foreach($vphonepwds as $vphonepwd) { //decode $phonepwd = explode(" ", $vphonepwd); $phone = $phonepwd[0]; $pwd = $phonepwd[1]; $vlist = $kv->get($phone); $list = explode(",", $vlist); foreach ($list as $vcodepricepair) { //decode $codepricepair = explode(" ", $vcodepricepair); $code = $codepricepair[0]; $price = $codepricepair[1]; //get data $url = "http://api.liqwei.com/stock/?code=$code"; $data = file_get_contents($url); $elements = explode(",", $data); $cprice = $elements[1]; // current price //send msg if ($price >= $cprice - 0.05 || $price <= $cprice + 0.05) { $url = "http://sms.bber.info/api.php?phone=$phone&pwd=$pwd&to=$phone&msg=$code,$cprice"; fopen("$url", 'r'); } } }
http://sms.bber.info/ 为 飞信网页版 和 api
参见 http://3haku.net/2010/11/25/php%E9%A3%9E%E4%BF%A1-pafetion-%E5%BC%80%E6%BA%90%E5%95%A6.html
hq.sinajs.cn 为 sina 财经 api,日,sina自己不让抓自己!
http://api.liqwei.com/stock/?code=sh:600028 用这个了
KVDB 限制如下
set (line 136)
更新key对应的value
bool set (string $key, string $value)
- string $key: 长度小于256字节
- string $value: 长度小于4MB