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
125b33b8
Commit
125b33b8
authored
Nov 13, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
时时彩获取高度
parent
92125b20
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
179 additions
and
2 deletions
+179
-2
LotteryBusiness.php
common/business/LotteryBusiness.php
+2
-1
ChainService.php
common/service/chain33/ChainService.php
+176
-0
LotteryController.php
console/controllers/LotteryController.php
+1
-1
No files found.
common/business/LotteryBusiness.php
View file @
125b33b8
...
...
@@ -8,6 +8,7 @@
namespace
common\business
;
use
common\service\chain33\ChainService
;
use
common\service\chain33\LotteryService
;
use
Yii
;
...
...
@@ -111,7 +112,7 @@ class LotteryBusiness
*/
public
static
function
getLastHeader
()
{
$service
=
new
Lottery
Service
();
$service
=
new
Chain
Service
();
$result
=
$service
->
getLastHeader
();
return
$result
;
}
...
...
common/service/chain33/ChainService.php
0 → 100644
View file @
125b33b8
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-18 10:28:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace
common\service\chain33
;
use
Yii
;
use
common\helpers\Curl
;
/**
* chain33 区块链接口
*/
class
ChainService
{
public
static
function
urlBuild
()
{
$config
=
Yii
::
$app
->
params
[
'chain'
];
$scheme
=
$config
[
'scheme'
]
??
'http'
;
$host
=
$config
[
'host'
]
??
'127.0.0.1'
;
$port
=
(
string
)
$config
[
'port'
]
??
''
;
if
(
$port
)
{
return
$scheme
.
'://'
.
$host
.
':'
.
$port
;
}
else
{
return
$scheme
.
'://'
.
$host
;
}
}
public
static
function
jsonRpcBuild
(
$params
=
[],
$method
=
'Chain33.Query'
)
{
$data
=
[
'jsonrpc'
=>
'2.0'
,
'id'
=>
0
,
'method'
=>
$method
,
'params'
=>
[],
];
if
(
!
empty
(
$params
))
{
$data
[
'params'
][]
=
$params
;
}
return
json_encode
(
$data
);
}
public
function
send
(
$params
=
[],
$method
=
'Chain33.Query'
)
{
$ch
=
new
Curl
();
$jsonrpc
=
self
::
jsonRpcBuild
(
$params
,
$method
);
$ch
->
setHeader
(
'Content-Type'
,
'application/json'
);
$ch
->
setRawPostData
(
$jsonrpc
);
$result
=
$ch
->
post
(
self
::
urlBuild
(),
false
);
if
(
!
$result
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
$ch
->
errorText
];
}
if
(
0
==
$result
[
'id'
]
&&
empty
(
$result
[
'error'
]))
{
$result
[
'code'
]
=
$result
[
'id'
];
unset
(
$result
[
'id'
]);
return
$result
;
}
else
{
return
[
'code'
=>
-
1
,
'msg'
=>
$result
[
'error'
]];
}
}
/**
* 获取地址下的所有token资产
*
* @param string|array $address
* @param string $symbol
* @return array
*/
public
function
getAccountTokenAssets
(
$address
,
$symbol
)
{
if
(
!
is_array
(
$address
))
{
$address
=
[
$address
];
}
$params
=
[
"addresses"
=>
$address
,
"execer"
=>
"user.p.guodun.token"
,
"tokenSymbol"
=>
$symbol
];
return
$this
->
send
(
$params
,
'Chain33.GetTokenBalance'
);
}
/**
* 提币
*
* @param $from
* @param $to
* @param $amount
* @param string $note
* @param bool $isToken
* @param string $tokenSymbol
* @return array
*/
public
function
extractToken
(
$from
,
$to
,
$amount
,
$note
=
''
,
$isToken
=
true
,
$tokenSymbol
=
''
)
{
$params
=
[
"from"
=>
$to
,
"to"
=>
$from
,
"amount"
=>
-
$amount
,
"note"
=>
$note
,
"isToken"
=>
$isToken
?
true
:
false
,
"tokenSymbol"
=>
strtoupper
(
$tokenSymbol
)
];
return
$this
->
send
(
$params
,
'Chain33.SendToAddress'
);
}
/**
* token 转账
*
* @param $from
* @param $to
* @param $amount
* @param string $note
* @param bool $isToken
* @param string $tokenSymbol
* @return array
*/
public
function
transToken
(
$from
,
$to
,
$amount
,
$note
=
''
,
$isToken
=
true
,
$tokenSymbol
=
''
)
{
$params
=
[
"from"
=>
$from
,
"to"
=>
$to
,
"amount"
=>
$amount
,
"note"
=>
$note
,
"isToken"
=>
$isToken
?
true
:
false
,
"tokenSymbol"
=>
strtoupper
(
$tokenSymbol
)
];
return
$this
->
send
(
$params
,
'Chain33.SendToAddress'
);
}
/**
* 获取最新的区块
*/
public
function
getLastHeader
()
{
return
$this
->
send
([],
'Chain33.GetLastHeader'
);
}
/**
* 获取区块hash
*
* @param integer $height
* @return array
*/
public
function
getBlockHashByHeight
(
$height
)
{
return
$this
->
send
([
'height'
=>
$height
],
'Chain33.GetBlockHash'
);
}
public
function
getTxByAddr
(
$addr
,
$flag
,
$count
,
$direction
,
$height
,
$index
)
{
$params
=
[
'addr'
=>
$addr
,
'flag'
=>
$flag
,
'count'
=>
$count
,
'direction'
=>
$direction
,
'height'
=>
$height
,
'index'
=>
$index
];
return
$this
->
send
(
$params
,
'Chain33.GetTxByAddr'
);
}
/**
* @param array $hashes
* @return array
*/
public
function
getTxByHashes
(
array
$hashes
)
{
$params
=
[
'hashes'
=>
$hashes
,
];
return
$this
->
send
(
$params
,
'Chain33.GetTxByHashes'
);
}
}
console/controllers/LotteryController.php
View file @
125b33b8
...
...
@@ -40,7 +40,7 @@ class LotteryController extends Controller
}
$lottery_current_result
=
$lottery_current_info
[
'result'
];
//获取最新的区块高度
$last_header
=
Chain33
Business
::
getLastHeader
();
$last_header
=
Lottery
Business
::
getLastHeader
();
if
(
$last_header
[
'code'
]
!=
0
)
{
echo
'获取区块高度失败: '
.
$last_header
[
'msg'
]
.
PHP_EOL
;
sleep
(
2
);
...
...
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