话说,PHP是世界上最好的语言,咳咳。但是这个最好的语言,我大概有7-8年没有去使用了,现在几乎已经不会用啦。之前学习和写的和STEEM区块链相关的程序都是用的Python。今天突然冒出个想法,写个PHP访问STEEM区块链的简单的例子。然后,写的时候才发现,各种不习惯。其实Python我也没没学两天,PHP则正经八百的用过好长时间呢,结果我觉得我完全变成PHP初学者了。好在,这个语言还算好学。于是磕磕绊绊写了一个程序,然后发现各种不优雅,简化简化简化,简化成现在这个样子了。为了演示核心流程,不包含任何错误处理之类的。
PHP is one of the popular programming languages,today, I wrote a simple PHP script to query the STEEM blockchain.
PHP程序 / The Script
闲话少叙,直接上脚本
<?
class Steemd
{
private $ch;
function __construct(){
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_URL, 'https://steemd.steemit.com');
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
}
function __destruct() {
curl_close($this->ch);
}
private function json_rpc_body($method, $params){
$request = array(
"jsonrpc" => "2.0",
"method" => $method,
"params" => $params,
"id" => 0
);
return json_encode($request);
}
public function exec($method, $params = array()) {
$data = $this->json_rpc_body($method, $params);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($this->ch);
$response = json_decode($response, true);
if (array_key_exists('error', $response)) {
var_dump($response['error']);
die();
}
return $response['result'];
}
public function get_account($account){
$result = $this->exec('get_accounts', [[$account]]);
return $result;
}
}
$steemd = new Steemd;
echo('<pre>');
print_r($steemd->exec(get_chain_properties,[]));
print_r($steemd->get_account('oflyhigh'));
echo('</pre>');
//unset($steemd);
?>
简单解释 / Explain
程序分成两部分
- Steemd类
- 测试代码
This script is divided into two parts, Steemd Class and some simple testing codes
Steemd类 / Steemd Class
使用PHP curl 来执行HTTP请求, 使用'https://steemd.steemit.com'作为请求节点。
I use curl to execute HTTP requests, use 'https://steemd.steemit.com' as RPC node.
Steemd Class 提供两个接口,exec以及get_account
There are two methods provided by Steemd Class , exec and get_account.
exec是底层接口,你可以直接调用这个接口来执行steem blockchain API 操作。
exec is low level interface, you can call it directly to perform operations to query steem blockchain.
get_account是对exe的封装,对用户更加友好,它仅仅是一个封装示例,你可以封装更多的功能。
get_account is a user friendly encapsulation for exe, it just a example, you can encapsulate more functions yourself.
测试代码 / Testing codes
就是简单测试一下而已,没啥可以说的
用print_r让结果看起来更好看
Some simple testing codes to test Steemd class and two interfaces exec and get_account
Use print_r to make the results look better.
运行结果 / Results
脚本仅供参考,使用风险自负!
This script is for reference only, use it at your own risk.
Thanks Alot Bro I Always Wanted To Know How To Use The Steemit Api With PHP And It Appears I Have To Learn Json-RPC :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哈哈其實怎麼人人都說PHP是最好的語言? 我只懂得很基本的PHP...
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哈哈哈,这是网络上的一个梗
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哈哈,查到了,所以基本上把PHP換上任何一種其他語言也可以的
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
不不,PHP才是世界上最好的语言,不服来辩 😄
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
C才是世界上最好的語言!! 😠😠
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
php里用curl调用网络资源查询最好加上timeout,要不经常会100% cpu占用。
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
谢谢
只是为了演示最基本的功能 😄
离实用十万八千里呢
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
意思是说以后你要返回世界上最好语言的大本营了? 嘿嘿
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我只是用来测试一下最最最最基本的访问流程 😄
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
O哥,確認一下,文章裡提到的exe是不是就是exec. 多謝。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哈哈,笔误笔误
已经修改过来
谢谢指正
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
不敢,多谢O哥传授秘笈
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Upvoted Resteemed and following all in this thread

Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @frankbuse,
Check out free courses on my blog! Many various courses 100% discount!
First part here!
https://steemit.com/education/@arathron/free-udemy-online-courses-1
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for this how to, i wanted to give it a try for the SEEMPI project im working on and i have installed Curl and php and saved your code in index.php but when loading the file it displays code instead of the output:
The code that on page after loading index.php is starting with:
ch = curl_init(); curl_setopt($this->ch, CURLOPT_URL, 'https://steemd.steemit.com');..............
........ending with:
');
print_r($steemd->exec(get_chain_properties,[]));
print_r($steemd->get_account('oflyhigh'));
echo('
'); //unset($steemd); ?>
Any suggestions, what am i doing wrong ?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
1.php
2.php
Try above two example php files
If 2.php works well, then change my script as it. (Add php after <? )
If both of them don't work, you need to check your HTTP server setting, add php support to it.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
PHP忘干净鸟😭
我居然把世界上最好的语言忘干净鸟😭
😭😭😭😭😭😭😭😭😭😭😭
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
php 全宇宙第一☝️
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @jubi,
Check out free courses on my blog! Many various courses 100% discount!
Please follow me to be updated!
First part here!
https://steemit.com/education/@arathron/free-udemy-online-courses-1
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @oflyhigh,
Check out free courses on my blog! Many various courses 100% discount!
Please follow me to be updated!
First part here!
https://steemit.com/education/@arathron/free-udemy-online-courses-1
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
O哥好厉害!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
😳
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @sylvia1997,
Check out many various courses on my blog! 100% discount! Remember - FIRST COME FIRST SERVED!
Please follow me to be updated!
First part here!
https://steemit.com/education/@arathron/free-udemy-online-courses-1
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
终于不用python了 php可以看懂一点。
o哥 你会的语言可真多
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我以前会N种语言,现在都忘干净了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我会说汉语,能看懂一点英语,哈哈
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
厉害!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
COOL
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
这个好像只是提取资料。PHP如何可以登录,点赞,和发帖?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
😄 我估计我是学不会了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
你要学这个吗?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
对呀:)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Ok, but I'm not as good as you when it comes to programming , just meme only
Your good thats why I give you an UpVote , I think it add more that 5$ after I click the UpVote button
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I think if steemit equipped with translation mode on post page we can read and understand all content by steemit user in different langguage. for more reason you can read here
https://steemit.com/steemit/@sogata/steemit-9-request-to-add-translation-mode-on-post-page-2017810t142621905z
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Friend of my support, for me who wrote. I need help from all friend, @yooraa, like. I will try my best in stringing words with the encouragement from esteem friend who faithful and can take me like you.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
NICE MEN
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Your post is very good. Keep adding the same posts even further. and keep voteing @ahlawat
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice nice
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
求互粉啊
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thank for sharing.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for sharing.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Powerful stuff . Keep it coming
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
都没有用过curl
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi Guys,
Check out free courses on my blog! Many various courses 100% discount!
First part here!
https://steemit.com/education/@arathron/free-udemy-online-courses-1
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for post! Chinese may be a barrier but code is universal ;)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
A good news..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
nice article. thanks for sharing i like the way you separatd the code
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great... please upvote me
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks a lot for knowledge:)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
very nice post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
great
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
php是什麼語言呀,我還停留在用perl去編程控制Modem的遠古時代呀。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
威武
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
這是無知的意思嗎?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哇!谢谢分享^^
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
The program looks good.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
upvote to my posts i also upvoted u
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
PHP 写得真6
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
php 5.6
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
现在是PHP7的世界了
不过你的代码 可以在PHP7运行没问题, 已经测试过了。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
感谢测试
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @oflyhigh!
Your post was mentioned in the hit parade in the following categories:
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice picture @oflyhigh
Please upvote me @muliadilibra
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
it's great, can be guide for beginner
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @rudalt,
Check out free courses on my blog! Many various courses 100% discount!
Please follow me to be updated!
First part here!
https://steemit.com/education/@arathron/free-udemy-online-courses-1
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit