用php如何获取当前Steem用户的Voting Power
再来一篇,这篇代码是获取指定用户当前的 Voting Power
,不废话直接上代码。
<?php
function postData($data) {
$url = 'https://api.steemit.com';
$options = array(
'http' =>
array(
'header' => "Content-Type: application/json\r\n".
"Content-Length: ".strlen($data)."\r\n".
"User-Agent:SteemTools/1.0\r\n",
'method' => 'POST',
'content' => $data,
)
);
$context = stream_context_create($options);
try {
$result = file_get_contents($url, false, $context);
$r = json_decode($result, true);
$result = $r['result'];
} catch (\Exception $e) {
return false;
}
return $result;
}
function getAccountVotingPower($username) {
$data = postData('{"jsonrpc":"2.0", "method":"condenser_api.get_accounts", "params":[["'.trim($username).'"]], "id":1}');
$user = $data[0];
$last_vote_time = $user['last_vote_time'];
var_dump(strtotime($last_vote_time));
$voting_power = $user['voting_power'];
var_dump($voting_power);
$vpow = $voting_power + (10000 * (time() - strtotime($last_vote_time)) / 432000);
return number_format(min($vpow, 10000) / 100, 2);
}
var_dump(getAccountVotingPower('ety001'));
完工!
欢迎使用 SteemEditor 来编写文章,获取 @steemeditor.bot 的大力点赞!
欢迎使用 SteemMention 获取最新的 Steem 回复提醒。
感谢你的阅读,我是中文区见证人之一,欢迎通过 SteemConnect 来给我投票,或者打开 https://steemit.com/~witnesses/ 页面,输入 ety001 进行投票。
中文区的见证人目前有:
支持一下他们(按字母顺序),一人可以有30票:
Thank you for reading. I'm a witness. I would really appreciate your witness vote! You can vote by SteemConnect. Or open https://steemit.com/~witnesses page, input ety001 to vote.