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
fa6be74b
Commit
fa6be74b
authored
Jul 13, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
爬取交易状态
parent
7245a9c9
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
194 additions
and
2 deletions
+194
-2
CoinController.php
api/controllers/CoinController.php
+20
-2
BrowerBusiness.php
common/business/BrowerBusiness.php
+32
-0
Brower.php
common/service/brower/Brower.php
+18
-0
BrowerFactory.php
common/service/brower/BrowerFactory.php
+33
-0
BrowerInterface.php
common/service/brower/BrowerInterface.php
+25
-0
BtcBrower.php
common/service/brower/BtcBrower.php
+30
-0
EthBrower.php
common/service/brower/EthBrower.php
+32
-0
README.md
common/service/brower/README.md
+4
-0
No files found.
api/controllers/CoinController.php
View file @
fa6be74b
...
...
@@ -14,6 +14,7 @@ use api\base\BaseController;
use
common\models\pwallet\Coin
;
use
common\business\CoinBusiness
;
use
common\business\ExchangeBusiness
;
use
common\business\BrowerBusiness
;
/**
* 币种信息管理控制器
...
...
@@ -71,8 +72,8 @@ class CoinController extends BaseController
throw
new
Exception
(
'8'
,
'币种不存在'
);
}
$result
=
(
array
)
$miner_fee
->
getAttributes
();
$result
[
'min'
]
=
(
float
)
$result
[
'min'
];
$result
[
'max'
]
=
(
float
)
$result
[
'max'
];
$result
[
'min'
]
=
(
float
)
$result
[
'min'
];
$result
[
'max'
]
=
(
float
)
$result
[
'max'
];
return
$result
;
}
...
...
@@ -101,4 +102,20 @@ class CoinController extends BaseController
return
ExchangeBusiness
::
SearchByName
(
$page
,
$limit
,
$condition
);
}
}
/**
* 返回交易状态
*
* @return mixed
*/
public
function
actionTransaction
()
{
$request
=
Yii
::
$app
->
request
;
$name
=
$request
->
post
(
'name'
,
''
);
$txhash
=
$request
->
post
(
'txhash'
,
''
);
if
(
$name
&&
$txhash
)
{
return
BrowerBusiness
::
getTransStatus
(
$name
,
$txhash
);
}
return
false
;
}
}
\ No newline at end of file
common/business/BrowerBusiness.php
0 → 100644
View file @
fa6be74b
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 上午10:21
*/
namespace
common\business
;
use
common\service\brower\BrowerFactory
;
class
BrowerBusiness
{
/**
* 获取交易信息
*
* @param string $name 区块链浏览器
* @param string $txhash 交易hash
* @return mixed|string|boolean
*/
public
static
function
getTransStatus
(
string
$name
,
string
$txhash
)
{
$status
=
BrowerFactory
::
getInstance
(
$name
)
->
getStatus
(
$txhash
);
if
(
$status
)
{
return
[
'code'
=>
0
,
'status'
=>
$status
];
}
else
{
return
[];
}
}
}
\ No newline at end of file
common/service/brower/Brower.php
0 → 100644
View file @
fa6be74b
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 上午10:01
*/
namespace
common\service\brower
;
class
Brower
implements
BrowerInterface
{
public
function
getStatus
(
string
$txhash
)
{
return
false
;
}
}
\ No newline at end of file
common/service/brower/BrowerFactory.php
0 → 100644
View file @
fa6be74b
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 上午9:56
*/
namespace
common\service\brower
;
class
BrowerFactory
{
public
static
$instances
;
/**
* @param $name
* @return BrowerInterface
*/
public
static
function
getInstance
(
$name
)
{
$name
=
strtolower
(
$name
);
if
(
!
isset
(
self
::
$instances
[
$name
])
||
!
(
self
::
$instances
[
$name
]
instanceof
BrowerInterface
))
{
$className
=
__NAMESPACE__
.
'\\'
.
ucfirst
(
$name
)
.
'Brower'
;
if
(
class_exists
(
$className
)
&&
(
new
\ReflectionClass
(
$className
))
->
isSubclassOf
(
BrowerInterface
::
class
))
{
self
::
$instances
[
$name
]
=
new
$className
();
}
else
{
self
::
$instances
[
$name
]
=
new
Brower
();
}
}
return
self
::
$instances
[
$name
];
}
}
\ No newline at end of file
common/service/brower/BrowerInterface.php
0 → 100644
View file @
fa6be74b
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 上午9:51
*/
namespace
common\service\brower
;
/**
* Interface BrowerInterface
* 区块链浏览器接口
*
* @package common\service\brower
*/
interface
BrowerInterface
{
/**
* @param string $txhash
* @return mixed|string|boolean 交易状态
*/
public
function
getStatus
(
string
$txhash
);
}
\ No newline at end of file
common/service/brower/BtcBrower.php
0 → 100644
View file @
fa6be74b
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 上午10:17
*/
namespace
common\service\brower
;
use
common\helpers\Curl
;
class
BtcBrower
extends
Brower
{
private
$base_uri
=
'https://btc.com/'
;
public
function
getStatus
(
string
$txhash
)
{
$uri
=
$this
->
base_uri
.
$txhash
;
$content
=
(
new
Curl
())
->
get
(
$uri
,
true
);
if
(
$content
)
{
preg_match_all
(
'/<dt> Confirmations<\/dt>(.*?)<dd>(.*?)<\/dd>/is'
,
$content
,
$matchs
);
if
(
isset
(
$matchs
[
2
][
0
]))
{
return
(
int
)
trim
(
$matchs
[
2
][
0
]);
}
}
return
0
;
}
}
\ No newline at end of file
common/service/brower/EthBrower.php
0 → 100644
View file @
fa6be74b
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 上午10:19
*/
namespace
common\service\brower
;
use
common\helpers\Curl
;
class
EthBrower
extends
Brower
{
private
$base_uri
=
'https://etherscan.io/'
;
public
function
getStatus
(
string
$txhash
)
{
$uri
=
$this
->
base_uri
.
'tx/'
.
$txhash
;
$ch
=
new
Curl
();
$content
=
$ch
->
get
(
$uri
,
true
);
if
(
$content
)
{
if
(
strpos
(
$content
,
'Success'
)
!==
false
)
{
return
'Success'
;
}
elseif
(
strpos
(
$content
,
'Fail'
)
!==
false
)
{
return
'Fail'
;
}
}
return
false
;
}
}
\ No newline at end of file
common/service/brower/README.md
0 → 100644
View file @
fa6be74b
#### 说明 ####
提供区块链浏览器爬取交易状态的功能
\ No newline at end of file
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