虽然区块链蓬勃发展,但是程序员要在网站上支持数字货币收款依然非常困难。无论是比特币,还是eos都需要安装全节点软件才能比较稳定的做到查询收款服务。然而目前的区块链全节点都耗费大量硬盘空间和系统资源,仅仅为了为了数字货币收款进行投入是不划算的。
这里介绍一个收款插件。
优点:
- 无需依赖外部库,因为是go语言编写的。
- 无需外部数据库,默认数据库使用sqlite3,熟练工可以自己修改支持mysql和postgre。
- 开发者使用http请求就可以创建支付通道,查询支付状态。
- 收到支付有推送,方便编写业务代码。
- 无需安装复杂的比特币全节点,以太坊全节点,eos全节点就可以收款。
- 体积小巧
前期准备一 Mixin Messenger账户
中国大陆iOS和安卓用户前往该地址下载App并注册账户。
大陆以外地区Apple ID和Google Play用户请前往 地址下载app并注册账户。
成为开发者并且创建app
访问开发者中心,点击右上角图标,用Mixin Messenger app的照相机扫描屏幕上的二维码,然后开始创建 App。 创建App流程可以参考这个教程
Clone 代码
git clone https://github.com/myrual/mixin-network-snapshot-golang
cd mixin-network-snapshot-golang
修改参数
在mixin_snap.go里面找到如下代码片段
const (
userid = "3c5fd587-5ac3-4fb6-b294-423ba3473f7d"
sessionid = "42848ded-0ffd-45eb-9b46-094d5542ee01"
private_key = `-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDACTrT4uaB9el9qe0MUOsFrm8kpaDI9PowauMB1Ha25mpfL+5h
MFqISLS5z2P89nAsXBg+KyQ2gAVA6rBwW/ZqOc1PKiJhhLBS80nzo3ayfv7OlzNG
IxMyqD5izCCtPixnqpuTePoPWq4CNZlxop0VYklsWEfU0U0qqMBgmtqYfQIDAQAB
AoGAR8crZed5oTn5fC73m5LjRcxdXqVJ49MtcMuC7jwr41FckRepUkpwjGAgrRMH
nJXAd9Q0e4hEkNppHEqciGLXR1dQfZnaM1Gnv7mD3oSgHaH+4qAMnNOCpvwW4Eu3
yp9b1UGj9SvM3D2BrpA+MGf0E/yEJzpRcT956W6SPYYSegECQQDm4uTK+teoxr1Z
agJZuCta+IhMzpxIWMob+JN/Huf7OnRcIa9JpXngg4tHOUWmZCDQdqeJMpaQc8SQ
44hba015AkEA1OyJswNIhdmvVp5P1zgREVVRK6JloYwmAtj+Qo4pWJ117LqH4w+b
491r4AeLEGh8VrZ4k6Hp+Cm783S2jTAWJQJARbWdlHdV45xVkQiDuyjy1h2RsXb0
EpfUNcvAZLIlImIMvcBh1x+CA7pTs+Zj1BAJJEee37qJYQXDBGfeRJPKKQJAVG+c
x42Ew/eoTZwoIzvLoOkJcFlNHjwaksSER9ZiVQ7URdVOr99vvXQAJG45Wn9k12oy
9LCfvNan/wqIngK0tQJBAL1Wc02seEbMeWyt5jycJEhn6G8F18s9S1v0GXb4U/7/
6Y87P3TmDLcEuCXkrbZQaCX7jVLu0BkDw8To58TWjh0=
-----END RSA PRIVATE KEY-----`
ADMIN_MessengerID = ""//this is your mixin messenger id, you can find your id in contact page.
)
将app创建过程中的那些参数替换到这里。 ADMIN_MessengerID是你的Mixin Messenger ID,你可以在Mixin Messenger里面的联系人页面看到。
编译
go build mixin_snap.go
运行
./mixin_snap
实际上由于是基于go语言编写的,你可以在一台linux 机器上编译,然后把执行文件传输到实际工作的服务器上运行。
如何创建一个eos和xlm的充值地址
生成一个独一无二的字符串作为支付id,然后设定一个收到支付的时候回掉URL。
curl -d '{"reqid":"value8", "callback":":9090/"}' -H "Content-Type: application/json" 127.0.0.1:8080/payment
这个curl指令起到的效果是: 将value8作为支付id传给支付插件,同时要求这个支付id收到支付的时候,程序要访问 本机的9090端口的根URL。
一般情况下,这个指令会立刻收到如下回复,你可以看到EOS和XLM的充值地址已经在里面了。
{"Reqid":"value9",
"Payment_methods":[
{"Name":"XLM","PublicKey":"","AccountName":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y","AccountTag":"39819a44ac87dd2c"},
{"Name":"EOS","PublicKey":"","AccountName":"eoswithmixin","AccountTag":"7648a59ae0eaee11d5d7f90c0f334eb1"}],
"Payment_records":null,"Balance":null}
如何查询支付状态
curl -X GET 'http://localhost:8080/payment?reqid=value8'
如果支付还没有完成,那么结果如下
{"Reqid":"value6","Payment_methods":[{"Name":"XLM","PublicKey":"","AccountName":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y","AccountTag":"dfc6af4e022c3a11"},
{"Name":"EOS","PublicKey":"","AccountName":"eoswithmixin","AccountTag":"d457cab41245ca0531f64947d1bb958a"}],
"Payment_records":null,"Balance":null}
如果支付已经确认,那么结果如下
{"Reqid":"value8",
"Payment_methods":[{"Name":"XLM","PublicKey":"","AccountName":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y","AccountTag":"62d0d256dcf15608"}
,{"Name":"EOS","PublicKey":"","AccountName":"eoswithmixin","AccountTag":"7481cd36f77953f129c194d3444ae2ff"}],
"Payment_records":[{"Amount":"0.1","AssetId":"","created_at":"2019-06-20T02:00:39.650472961Z","snapshot_id":"570233aa-3c91-45cd-a6ec-0e9724165300"}
,{"Amount":"0.01","AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d","created_at":"2019-06-20T02:33:50.152539755Z","snapshot_id":"88859d4d-5bee-4fb5-aef6-ac01dc3a43c6"}
,{"Amount":"0.01","AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d","created_at":"2019-06-20T02:37:05.870885973Z","snapshot_id":"6530f455-3238-491a-a9c5-bbcb52bcc306"}
,{"Amount":"0.001","AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d","created_at":"2019-06-20T02:40:53.251365044Z","snapshot_id":"f2c8a751-3d30-472e-bf76-924787f341b9"},
{"Amount":"0.001","AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d","created_at":"2019-06-20T02:59:28.854380284Z","snapshot_id":"3ebfd5a3-bd29-4e32-bd06-2506bee3da99"},
{"Amount":"-0.122","AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d","created_at":"2019-06-20T03:00:17.249302744Z","snapshot_id":"0bfe6f6b-1ff8-4144-9786-52d6a6459b19"}],
"Balance":null}
充值确认回掉URL
该程序能在收到充值确认的时候,根据你设定的callbackurl来发起http post访问。URL如下
"http://127.0.0.1"+callbackurl
json body如下
{"Reqid":"value8","Callbackurl":":9090/","Paymentrecord":{"Amount":"0.01","AssetId":"56e63c06-b506-4ec5-885a-4a5ac17b83c1","created_at":"2019-06-20T07:33:06.445471337Z","snapshot_id":"a6603374-509b-4015-a192-c63bfa8def5f"}}
资金提取
- 该程序在充值确认完毕之后会自动把该充值地址对应钱包的所有的资金都立刻自动转移到你的Mixin Messenger账户
- 你也可以手动发起一条指令来要求程序把所有账户的钱都转移到你的Mixin messenger账户
curl -X POST -H "Content-Type: application/json" 127.0.0.1:8080/moneygohome
数据备份
默认只用了sqlite,所以只需备份执行目录下的test.db
支持的数字货币范围
理论上所有Mixin Network上支持的数字货币都可以接受,但是由于部分数字货币充值确认很慢,因此代码默认支持EOS和XLM,因为这两个货币都可以3分钟确认完毕。
如果想支持更多货币,只需要修改如下代码
const (//目前主要的数字货币
BTC_ASSET_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
EOS_ASSET_ID = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d"
USDT_ASSET_ID = "815b0b1a-2764-3736-8faa-42d694fa620a"
ETC_ASSET_ID = "2204c1ee-0ea2-4add-bb9a-b3719cfff93a"
XRP_ASSET_ID = "23dfb5a5-5d7b-48b6-905f-3970e3176e27"
XEM_ASSET_ID = "27921032-f73e-434e-955f-43d55672ee31"
ETH_ASSET_ID = "43d61dcd-e413-450d-80b8-101d5e903357"
DASH_ASSET_ID = "6472e7e3-75fd-48b6-b1dc-28d294ee1476"
DOGE_ASSET_ID = "6770a1e5-6086-44d5-b60f-545f9d9e8ffd"
LTC_ASSET_ID = "76c802a2-7c88-447f-a93e-c29c9e5dd9c8"
SIA_ASSET_ID = "990c4c29-57e9-48f6-9819-7d986ea44985"
ZEN_ASSET_ID = "a2c5d22b-62a2-4c13-b3f0-013290dbac60"
ZEC_ASSET_ID = "c996abc9-d94e-4494-b1cf-2a3fd3ac5714"
BCH_ASSET_ID = "fd11b6e3-0b87-41f1-a41f-f0e9b49e5bf0"
XIN_ASSET_ID = "c94ac88f-4671-3976-b60a-09064f1811e8"
CNB_ASSET_ID = "965e5c6e-434c-3fa9-b780-c50f43cd955c"
XLM_ASSET_ID = "56e63c06-b506-4ec5-885a-4a5ac17b83c1"
TRON_ASSET_ID = "25dabac5-056a-48ff-b9f9-f67395dc407c"
........
)
.......
.......
// 想要支持哪个,就把那个放在这个slice里面
default_asset_id_group := []string{XLM_ASSET_ID, EOS_ASSET_ID}
充值到账时间列表
Asset | estimate confirmation duration |
---|---|
波场 | 5 分钟 |
比特币 | 1 小时 |
USDT | 1 小时 |
欢迎用Mixin Messenger App 联系我。
有疑问加站长微信联系(非本文作者)