Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
67804f29
Commit
67804f29
authored
Jul 09, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口数据格式修改
parent
45fa6c80
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
20 deletions
+20
-20
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+6
-6
CoinBTYService.php
common/service/coin/CoinBTYService.php
+5
-5
CoinService.php
common/service/coin/CoinService.php
+9
-9
No files found.
common/business/ExchangeBusiness.php
View file @
67804f29
...
...
@@ -77,9 +77,9 @@ class ExchangeBusiness
}
//格式化行情数据
foreach
(
$quotation
as
$key
=>
$item
)
{
$quotation
[
$key
]
=
sprintf
(
"%0.4f"
,
(
double
)
$item
);
$quotation
[
$key
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
double
)
$item
);
}
$quotation
[
'rmb'
]
=
sprintf
(
"%0.2f"
,
6.6
*
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.2f"
,
6.6
*
$quotation
[
'last'
]);
return
$quotation
;
}
...
...
@@ -131,10 +131,10 @@ class ExchangeBusiness
//使用Coin服务
$coinServer
=
CoinFactory
::
createCoin
(
$row
[
'name'
],
$row
[
'id'
],
$row
[
'sid'
]);
$rows
[
$key
][
'sid'
]
=
ucfirst
(
$rows
[
$key
][
'sid'
]);
$rows
[
$key
][
'rmb'
]
=
sprintf
(
"%0.2f"
,
$coinServer
->
getPrice
()
);
$rows
[
$key
][
'last'
]
=
sprintf
(
"%0.4f"
,
$coinServer
->
getDollar
()
);
$rows
[
$key
][
'low'
]
=
sprintf
(
"%0.2f"
,
$coinServer
->
getLow
()
);
$rows
[
$key
][
'high'
]
=
sprintf
(
"%0.2f"
,
$coinServer
->
getHigh
()
);
$rows
[
$key
][
'rmb'
]
=
$coinServer
->
getPrice
(
);
$rows
[
$key
][
'last'
]
=
$coinServer
->
getDollar
(
);
$rows
[
$key
][
'low'
]
=
$coinServer
->
getLow
(
);
$rows
[
$key
][
'high'
]
=
$coinServer
->
getHigh
(
);
$coinServer
->
__destruct
();
}
$rows
[
$key
]
=
array_merge
(
$rows
[
$key
],
$quotation
);
...
...
common/service/coin/CoinBTYService.php
View file @
67804f29
...
...
@@ -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
||
YII_ENV_DEV
)
{
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
=
(
float
)
sprintf
(
"%0.2f"
,
$price
)
;
}
public
function
getDollar
()
...
...
@@ -110,7 +110,7 @@ class CoinBTYService extends Coin implements CoinInterface
public
function
setDollar
(
$dollar
)
{
$this
->
dollar
=
$dollar
;
$this
->
dollar
=
(
float
)
sprintf
(
"%0.4f"
,
$dollar
)
;
}
public
function
getHigh
()
...
...
@@ -125,7 +125,7 @@ class CoinBTYService extends Coin implements CoinInterface
public
function
setHigh
(
$high
)
{
return
$this
->
high
=
$high
;
return
$this
->
high
=
(
float
)
sprintf
(
"%0.4f"
,
$high
)
;
}
public
function
getLow
()
...
...
@@ -140,7 +140,7 @@ class CoinBTYService extends Coin implements CoinInterface
public
function
setLow
(
$low
)
{
$this
->
low
=
$low
;
$this
->
low
=
(
float
)
sprintf
(
"%0.4f"
,
$low
)
;
}
public
function
getChange
()
...
...
common/service/coin/CoinService.php
View file @
67804f29
...
...
@@ -66,7 +66,7 @@ class CoinService extends Coin implements CoinInterface
*/
public
function
setPrice
(
$price
)
{
$this
->
price
=
$price
;
$this
->
price
=
(
float
)
sprintf
(
"%0.2f"
,
$price
)
;
}
/**
...
...
@@ -96,7 +96,7 @@ class CoinService extends Coin implements CoinInterface
*/
public
function
setDollar
(
$dollar
)
{
$this
->
dollar
=
$dollar
;
$this
->
dollar
=
(
float
)
sprintf
(
"%0.4f"
,
$dollar
)
;
}
/**
...
...
@@ -155,7 +155,7 @@ class CoinService extends Coin implements CoinInterface
*/
public
function
setHigh
(
$high
)
{
$this
->
high
=
$high
;
$this
->
high
=
(
float
)
sprintf
(
"%0.2f"
,
$high
)
;
}
/**
...
...
@@ -184,7 +184,7 @@ class CoinService extends Coin implements CoinInterface
*/
public
function
setLow
(
$low
)
{
$this
->
low
=
$low
;
$this
->
low
=
(
float
)
sprintf
(
"%0.2f"
,
$low
)
;
}
/**
...
...
@@ -525,7 +525,7 @@ class CoinService extends Coin implements CoinInterface
//价格与涨幅
$pattern
=
'/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is'
;
preg_match_all
(
$pattern
,
$content
,
$matchs
,
PREG_SET_ORDER
);
$result
[
'price'
]
=
sprintf
(
"%0.2f"
,
(
float
)
str_replace
([
'¥'
],
''
,
$matchs
[
0
][
1
]));
$result
[
'price'
]
=
(
float
)
sprintf
(
"%0.2f"
,
(
float
)
str_replace
([
'¥'
],
''
,
$matchs
[
0
][
1
]));
// $result['change'] = $matchs[0][3];
//最高最低值
...
...
@@ -538,7 +538,7 @@ class CoinService extends Coin implements CoinInterface
preg_match_all
(
'/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is'
,
$content
,
$matchs
,
PREG_SET_ORDER
);
$result
[
'dollar'
]
=
sprintf
(
"%0.4f"
,
(
double
)
str_replace
([
'$'
,
'≈'
],
''
,
$matchs
[
0
][
1
]));
$result
[
'dollar'
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
double
)
str_replace
([
'$'
,
'≈'
],
''
,
$matchs
[
0
][
1
]));
// $result['btc'] = $matchs[0][3];
// //爬取市值与排名
...
...
@@ -555,9 +555,9 @@ class CoinService extends Coin implements CoinInterface
$result
[
'circulate_count'
]
=
$matches
[
0
][
1
];
$result
[
'publish_count'
]
=
$matches
[
0
][
2
];
$result
=
array_map
(
function
(
$value
)
{
return
trim
(
$value
);
},
$result
);
//
$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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment