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
add65b5c
Commit
add65b5c
authored
Jul 13, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
爬取交易状态DCR,BTY
parent
fa6be74b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
17 deletions
+110
-17
BrowerBusiness.php
common/business/BrowerBusiness.php
+2
-6
Brower.php
common/service/brower/Brower.php
+21
-1
BrowerInterface.php
common/service/brower/BrowerInterface.php
+2
-1
BtcBrower.php
common/service/brower/BtcBrower.php
+7
-6
BtyBrower.php
common/service/brower/BtyBrower.php
+40
-0
DcrBrower.php
common/service/brower/DcrBrower.php
+34
-0
EthBrower.php
common/service/brower/EthBrower.php
+4
-3
No files found.
common/business/BrowerBusiness.php
View file @
add65b5c
...
@@ -21,11 +21,6 @@ class BrowerBusiness
...
@@ -21,11 +21,6 @@ class BrowerBusiness
*/
*/
public
static
function
getTransStatus
(
string
$name
,
string
$txhash
)
public
static
function
getTransStatus
(
string
$name
,
string
$txhash
)
{
{
$status
=
BrowerFactory
::
getInstance
(
$name
)
->
getStatus
(
$txhash
);
return
$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
View file @
add65b5c
...
@@ -10,8 +10,27 @@ namespace common\service\brower;
...
@@ -10,8 +10,27 @@ namespace common\service\brower;
class
Brower
implements
BrowerInterface
class
Brower
implements
BrowerInterface
{
{
const
TRANS_OK
=
1
;
//交易成功
const
TRANS_FAIL
=
2
;
//交易失败
const
TRANS_PADDING
=
3
;
//交易状态未知
const
ERROR
=
4
;
//接口返回错误
public
static
$msg
=
[
self
::
TRANS_OK
=>
'SUCCEED'
,
self
::
TRANS_FAIL
=>
'FAIL'
,
self
::
TRANS_PADDING
=>
'UNKNOW'
,
self
::
ERROR
=>
'ERROR'
,
];
public
function
getStatus
(
string
$txhash
)
public
function
getStatus
(
string
$txhash
)
{
{
return
false
;
return
[
'code'
=>
self
::
ERROR
,
'msg'
=>
'Coin not supported!'
];
}
public
function
StatusReturn
(
$code
,
$msg
=
''
)
{
if
(
$msg
)
{
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
return
[
'code'
=>
$code
,
'msg'
=>
self
::
$msg
[
$code
]];
}
}
}
}
\ No newline at end of file
common/service/brower/BrowerInterface.php
View file @
add65b5c
...
@@ -18,7 +18,7 @@ interface BrowerInterface
...
@@ -18,7 +18,7 @@ interface BrowerInterface
{
{
/**
/**
* @param string $txhash
* @param string $txhash
* @return
mixed|string|boolean
交易状态
* @return
array
交易状态
*/
*/
public
function
getStatus
(
string
$txhash
);
public
function
getStatus
(
string
$txhash
);
}
}
\ No newline at end of file
common/service/brower/BtcBrower.php
View file @
add65b5c
...
@@ -12,18 +12,18 @@ use common\helpers\Curl;
...
@@ -12,18 +12,18 @@ use common\helpers\Curl;
class
BtcBrower
extends
Brower
class
BtcBrower
extends
Brower
{
{
private
$base_uri
=
'https://
btc.com
/'
;
private
$base_uri
=
'https://
chain.api.btc.com/v3/tx
/'
;
public
function
getStatus
(
string
$txhash
)
public
function
getStatus
(
string
$txhash
)
{
{
$uri
=
$this
->
base_uri
.
$txhash
;
$uri
=
$this
->
base_uri
.
$txhash
;
$content
=
(
new
Curl
())
->
get
(
$uri
,
tru
e
);
$content
=
(
new
Curl
())
->
get
(
$uri
,
fals
e
);
if
(
$content
)
{
if
(
$content
)
{
preg_match_all
(
'/<dt> Confirmations<\/dt>(.*?)<dd>(.*?)<\/dd>/is'
,
$content
,
$matchs
);
if
(
$content
[
'err_no'
])
{
if
(
isset
(
$matchs
[
2
][
0
]))
{
return
$this
->
StatusReturn
(
self
::
ERROR
,
$content
[
'err_msg'
]);
return
(
int
)
trim
(
$matchs
[
2
][
0
]);
}
}
return
$this
->
StatusReturn
(
self
::
TRANS_OK
);
}
}
return
0
;
return
$this
->
StatusReturn
(
self
::
ERROR
)
;
}
}
}
}
\ No newline at end of file
common/service/brower/BtyBrower.php
0 → 100644
View file @
add65b5c
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 下午3:00
*/
namespace
common\service\brower
;
use
common\helpers\Curl
;
class
BtyBrower
extends
Brower
{
private
$base_uri
=
'https://mainnet.bityuan.com/api'
;
public
function
getStatus
(
string
$txhash
)
{
$ch
=
new
Curl
();
$ch
->
setHeader
(
'Content-Type'
,
'application/json'
);
$post
=
[
'jsonrpc'
=>
'2.0'
,
'id'
=>
1
,
'method'
=>
'Chain33.QueryTransaction'
,
'params'
=>
[[
'hash'
=>
$txhash
]]
];
$post
=
json_encode
(
$post
);
$ch
->
setOption
(
CURLOPT_POSTFIELDS
,
$post
);
$result
=
$ch
->
post
(
$this
->
base_uri
,
false
);
if
(
$result
)
{
if
(
$result
[
'result'
])
{
return
$this
->
StatusReturn
(
self
::
TRANS_OK
);
}
elseif
(
$result
[
'error'
])
{
return
$this
->
StatusReturn
(
self
::
ERROR
,
$result
[
'error'
]);
}
}
return
$this
->
StatusReturn
(
self
::
ERROR
);
}
}
\ No newline at end of file
common/service/brower/DcrBrower.php
0 → 100644
View file @
add65b5c
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 下午4:33
*/
namespace
common\service\brower
;
use
common\helpers\Curl
;
class
DcrBrower
extends
Brower
{
private
$base_uri
=
'https://mainnet.decred.org/api/tx/'
;
public
function
getStatus
(
string
$txhash
)
{
$uri
=
$this
->
base_uri
.
$txhash
;
$content
=
(
new
Curl
())
->
get
(
$uri
,
true
);
$result
=
json_decode
(
$content
,
true
);
if
(
$result
)
{
if
(
isset
(
$result
[
'confirmations'
])
&&
$result
[
'confirmations'
]
>
0
)
{
return
$this
->
StatusReturn
(
self
::
TRANS_OK
);
}
else
{
return
$this
->
StatusReturn
(
self
::
TRANS_PADDING
);
}
}
return
$this
->
StatusReturn
(
self
::
ERROR
,
$content
);
}
}
\ No newline at end of file
common/service/brower/EthBrower.php
View file @
add65b5c
...
@@ -21,11 +21,11 @@ class EthBrower extends Brower
...
@@ -21,11 +21,11 @@ class EthBrower extends Brower
$content
=
$ch
->
get
(
$uri
,
true
);
$content
=
$ch
->
get
(
$uri
,
true
);
if
(
$content
)
{
if
(
$content
)
{
if
(
strpos
(
$content
,
'Success'
)
!==
false
)
{
if
(
strpos
(
$content
,
'Success'
)
!==
false
)
{
return
'Success'
;
return
$this
->
StatusReturn
(
self
::
TRANS_OK
)
;
}
elseif
(
strpos
(
$content
,
'Fail'
)
!==
false
)
{
}
elseif
(
strpos
(
$content
,
'Fail'
)
!==
false
)
{
return
'Fail'
;
return
$this
->
StatusReturn
(
self
::
TRANS_FAIL
)
;
}
}
}
}
return
false
;
return
$this
->
StatusReturn
(
self
::
ERROR
,
'txHash not exists'
)
;
}
}
}
}
\ 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