Commit cdcf8bd2 authored by rlgy's avatar rlgy

返回数据格式规范

parent 35a7af46
......@@ -58,7 +58,7 @@ class CoinBTYService extends Coin implements CoinInterface
{
$key = $this->cache_key_prifx . $this->sid . 'all';
$result = Yii::$app->cache->get($key);
if ($result === false) {
if ($result === false||YII_ENV_DEV) {
$url = 'https://zb2api.licai.cn/api/data/Ticker?sort=cname';
$ch = new Curl();
$content = $ch->get($url, false);
......@@ -95,7 +95,7 @@ class CoinBTYService extends Coin implements CoinInterface
public function setPrice($price)
{
return $this->price = "¥$price";
return $this->price = $price;
}
public function getDollar()
......@@ -110,7 +110,7 @@ class CoinBTYService extends Coin implements CoinInterface
public function setDollar($dollar)
{
$this->dollar = "≈\$$dollar";
$this->dollar = $dollar;
}
public function getHigh()
......
......@@ -50,7 +50,9 @@ class CoinService extends Coin implements CoinInterface
}
$pattern = '/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is';
preg_match_all($pattern, $this->content, $matchs, PREG_SET_ORDER);
$this->setPrice($matchs[0][1]);
$price = $matchs[0][1];
$price = str_replace(['¥', ','], '', $price);
$this->setPrice($price);
Yii::$app->cache->set($this->cache_key_prifx . $this->sid . '_price', $this->price,
Yii::$app->params['curl_cache_time']['quotation']);
} else {
......@@ -80,7 +82,7 @@ class CoinService extends Coin implements CoinInterface
preg_match_all('/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is', $this->content,
$matchs,
PREG_SET_ORDER);
$this->setDollar($matchs[0][1]);
$this->setDollar(str_replace(['$', '≈', ','], '', $matchs[0][1]));
Yii::$app->cache->set($this->cache_key_prifx . $this->sid . '_usd', $this->dollar,
Yii::$app->params['curl_cache_time']['quotation']);
} else {
......@@ -556,6 +558,7 @@ class CoinService extends Coin implements CoinInterface
$result = array_map(function ($value) {
return trim($value);
}, $result);
Yii::$app->cache->set($key, $result, Yii::$app->params['curl_cache_time']['quotation']);//set cache
return $result;
} catch (\Exception $exception) {
......
......@@ -66,7 +66,7 @@ class CoinYCCService extends Coin implements CoinInterface
public function getPrice()
{
return "0.2";
return "0.2";
}
public function setPrice($price)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment