Peter 邀请我到币问回答这个问题, 原答案在: https://www.bitask.org/question/1007
微信个人号机器人我没太了解, 不过我做过公众号 justyyuk (小赖子英国生活和资讯), 这个公众号机器人的入口就是在微信公众号控制平台里,
https://mp.weixin.qq.com/
具体位置: 开发 – 基本配置.
然后基本的问答式机器人的代码我在 github 上传了一份:
先看看效果吧:
调用 coinmarkcap 的API, 用PHP代码简单得不行了, 比如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | function GetCoinMarketCapPrice($from, $to, &$rank, &$c1h, &$c24h, &$c7d) { $from = trim($from); $to = trim(strtolower($to)); $cmd = strtolower($from); $url = 'curl -s "https://api.coinmarketcap.com/v1/ticker]https://api.coinmarketcap.com/v1/ticker/'.$from.'/?convert='.$to . '"'; $tmp = shell_exec($url); $data = json_decode($tmp, true); if ($data) { if ($data[0]['rank']) { $rank = $data[0]['rank']; } if ($data[0]['percent_change_1h']) { $c1h = $data[0]['percent_change_1h']; } if ($data[0]['percent_change_24h']) { $c24h = $data[0]['percent_change_24h']; } if ($data[0]['percent_change_7d']) { $c7d = $data[0]['percent_change_7d']; } } if ($data && count($data) && $data[0]['price_' . $to]) { $y = (float)$data[0]['price_' . $to]; $x = round($y, 2); if (abs($x) < 0.01) { return sprintf('%f', $y); } return $x; } return null; } |
function GetCoinMarketCapPrice($from, $to, &$rank, &$c1h, &$c24h, &$c7d) { $from = trim($from); $to = trim(strtolower($to)); $cmd = strtolower($from); $url = 'curl -s "https://api.coinmarketcap.com/v1/ticker]https://api.coinmarketcap.com/v1/ticker/'.$from.'/?convert='.$to . '"'; $tmp = shell_exec($url); $data = json_decode($tmp, true); if ($data) { if ($data[0]['rank']) { $rank = $data[0]['rank']; } if ($data[0]['percent_change_1h']) { $c1h = $data[0]['percent_change_1h']; } if ($data[0]['percent_change_24h']) { $c24h = $data[0]['percent_change_24h']; } if ($data[0]['percent_change_7d']) { $c7d = $data[0]['percent_change_7d']; } } if ($data && count($data) && $data[0]['price_' . $to]) { $y = (float)$data[0]['price_' . $to]; $x = round($y, 2); if (abs($x) < 0.01) { return sprintf('%f', $y); } return $x; } return null; }
我相信代码都是差不多的, 只不过接口不一样. 回到这问题, 你需要:
- 懂一门编程语言像 NodeJs , PYTHON 或者 PHP 在这里就很适合.
- 懂得调用 coinmarkcap 或者 coinbase API 之前我写过一英文技术帖.
- 懂得微信个人号或者公众号的配置.
还发现了 币问三个BUG:
- 直接插入URL有BUG
- 插入图片 直接用 网络URL 显示不了
- 代码里的 URL 被 加强制加上了 [url] [/url]
GD Star Rating
loading...
本文一共 235 个汉字, 你数一下对不对.loading...
上一篇: 兄弟俩放学回家逗邻居的猫 - 还好英国没有狂犬病
下一篇: SteemSQL 收费了 - 开银行的成本大了
扫描二维码,分享本文到微信朋友圈
