免費,開源的數字貨幣收款插件

雖然區塊鏈蓬勃發展,可是程序員要在網站上支持數字貨幣收款依然很是困難。不管是比特幣,仍是eos都須要安裝全節點軟件才能比較穩定的作到查詢收款服務。然而目前的區塊鏈全節點都耗費大量硬盤空間和系統資源,僅僅爲了爲了數字貨幣收款進行投入是不划算的。mysql

這裏介紹一個收款插件git

優勢:

  1. 無需依賴外部庫,由於是go語言編寫的。
  2. 無需外部數據庫,默認數據庫使用sqlite3,熟練工能夠本身修改支持mysql和postgre。
  3. 開發者使用http請求就能夠建立支付通道,查詢支付狀態。
  4. 收到支付有推送,方便編寫業務代碼。
  5. 無需安裝複雜的比特幣全節點,以太坊全節點,eos全節點就能夠收款。
  6. 體積小巧

步驟:

1. 建立一個Mixin Messenger帳戶.

訪問 mixin.one/messenger 下載對應手機端App。程序員

中國大陸用戶能夠訪問 a.app.qq.com/o/simple.js… 下載github

2. 激活開發者帳號

登錄 developer.mixin.one ,用App掃碼登陸golang

這個 教程對於新開發者頗有用。sql

Clone, build, run

git clone https://github.com/myrual/mixin-network-snapshot-golang
cd mixin-network-snapshot-golang
複製代碼
  1. 編輯一部分配置信息
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.
)
複製代碼
  1. 編譯
go build mixin_snap.go
複製代碼
  1. 運行
./mixin_snap
複製代碼
  1. 數據庫 同一目錄下會生成一個test.db 的sqlite3文件。

如何使用

如何接受數字貨幣付款

爲了接受比特幣,EOS支付,開發者須要用http POST方法訪問 localhost:8080/payment,參數放在body裏面。 body裏面應該有 惟一標示字符串,回掉URL,以及回掉過時時間。 惟一標示字符串能夠是任意字符,uuid也能夠。 程序收到用戶的付款以後會用http post方法訪問回掉本機Callback url。 回掉機制有有效期,過了有效期,回掉機制會中止。若是回掉有效期參數爲60, 那麼回掉機制會在60分鐘後過時。 curl例子shell

curl -d '{"reqid":"value8", "callback":":9090/", "expiredafter":60}' -H "Content-Type: application/json" 127.0.0.1:8080/payment
複製代碼

這條指令指示程序爲value8建立一個支付地址,若是在60分鐘內收到用戶支付,那麼程序會http post方式訪問 localhost:9090/,同時帶有參數。數據庫

這條指令的返回結果是json

{"Reqid":"value8","Payment_methods":[{"Name":"XLM","PaymentAddress":"","PaymentAccount":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y","PaymentMemo":"3f8db42022b5bc32"},{"Name":"EOS","PaymentAddress":"","PaymentAccount":"eoswithmixin","PaymentMemo":"302c37ebff05ccf09dd7296053d1924a"},{"Name":"ETH","PaymentAddress":"0x365DA43BC7B22CD4334c3f35eD189C8357D4bEd6","PaymentAccount":"","PaymentMemo":""}],"Payment_records":null,"Balance":null}
複製代碼

Payment_methods裏面的結果是給客戶看的,這個例子有三個支付方法。瀏覽器

有兩種風格的支付:

  1. 比特幣/以太坊: PaymentAddress 不是空,PaymentAccount 和 PaymentMemo是空。這種狀況下,你只須要給用戶展現資產名字 以太坊和PaymentAddress,客戶只須要向以太坊地址付款。
  2. EOS/行星 : PaymentAddress 是空, PaymentAccount 和 PaymentMemo 都有內容。這種狀況下,你須要給用戶展現資產名字,收款帳戶和收款備註,而且嚴肅的提醒用戶同時填寫收款帳戶和收款備註,客戶若是忘記填寫備註,會致使不能到帳,並且沒法退款。

檢查收款狀態

經過參數 reqid 訪問 localhost:8080/payment 能夠查詢收款狀態和記錄。

例子:

curl -X GET 'http://localhost:8080/payment?reqid=value8'
複製代碼

若是客戶尚未支付,那麼結果是這樣的

{"Reqid":"value8","Payment_methods":[{"Name":"XLM","PaymentAddress":"","PaymentAccount":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y","PaymentMemo":"3f8db42022b5bc32"},{"Name":"EOS","PaymentAddress":"","PaymentAccount":"eoswithmixin","PaymentMemo":"302c37ebff05ccf09dd7296053d1924a"},{"Name":"ETH","PaymentAddress":"0x365DA43BC7B22CD4334c3f35eD189C8357D4bEd6","PaymentAccount":"","PaymentMemo":""}],"Payment_records":null,"Balance":null}
複製代碼

paymnet_records 是空

若是客戶已經支付了,結果是這樣的。

{"Reqid":"value8","Payment_methods":[{"Name":"XLM","PaymentAddress":"","PaymentAccount":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y","PaymentMemo":"3f8db42022b5bc32"},{"Name":"EOS","PaymentAddress":"","PaymentAccount":"eoswithmixin","PaymentMemo":"302c37ebff05ccf09dd7296053d1924a"},{"Name":"ETH","PaymentAddress":"0x365DA43BC7B22CD4334c3f35eD189C8357D4bEd6","PaymentAccount":"","PaymentMemo":""}],"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}
複製代碼

payment_records 有支付信息. 其中一個支付信息以下

{"Amount":"0.01","AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
"created_at":"2019-06-20T02:37:05.870885973Z","snapshot_id":"6530f455-3238-491a-a9c5-bbcb52bcc306"}
複製代碼

這是一條來自客戶的支付:

  • 數量 0.01
  • 資產id 6cfe566e-4aad-470b-8c9a-2fd35b49c68d,是 EOS 主網token
  • 支付生成於 UTC 2019-06-20T02:37:05.870885973
  • 該支付在Mixin Network內的惟一標示號 6530f455-3238-491a-a9c5-bbcb52bcc306,你能夠在瀏覽器裏面驗證這筆交易 mixin.one/snapshots/6…

回掉URL

在有效期內收到用戶付款,程序會訪問本地的回掉URL。

"http://127.0.0.1"+callbackurl
複製代碼

http訪問方法是POST,參數在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"}}
複製代碼

全部資產都屬於開發者本身麼?

  1. 全部資產都會自動被轉移到你指定的帳戶, 免手續費,1秒到帳。
  2. 在該程序重啓,或者意外退出以後,你能夠手動發指令要求程序把全部資產都轉移到你指定的帳戶。

例子:

curl -X POST -H "Content-Type: application/json" 127.0.0.1:8080/moneygohome
複製代碼

結果以下

total 20 account will send all balance to admin
複製代碼

支付的確認時間

  1. EOS: 3 分鐘
  2. Stellar: 2 分鐘
  3. Bitcoin/USDT: 60 分鐘
  4. Litecoin/Ethererum/DOGE: 120 分鐘

什麼是確認時間?大部分數字貨幣從用戶發起轉帳請求,到收款方確認這筆付款不能回滾須要一點時間。

爲何這麼長?這是Mixin Network 自己的設定,你如今改不了。

支持哪些資產

理論上Mixin Network支持的均可以接受。如今支持 BTC, USDT, BCH, 以太坊和 ERC20, ETC, EOS 以及EOS上發的token, DASH, Litecoin, Doge, Horizen, MGD, NEM, XRP, XLM, 波場和波場上發的TRC10, Zcash.

目前的代碼庫默認支持的資產

如今代碼裏面默認支持的資產是EOS和恆星,由於他們均可以3分鐘完成支付確認。

想要支持更多的幣,把對應資產的變量放到 default_asset_id_group 裏面就能夠.

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"
	........
)
.......
.......

	// to support more asset, just add them in the following array
	default_asset_id_group := []string{XLM_ASSET_ID, EOS_ASSET_ID}
複製代碼

下一步的開發任務:

  1. 全部的資產能夠自動提取到開發者本身的冷錢包,而不是隻能轉移到Mixin Messenger帳戶。
  2. 能夠把收到的資產經過去中心化交易所自動轉換成USDT或者比特幣。
  3. 支持Mixin Messenger用戶付款。
  4. 能夠提供資產對應的美圓價格。

Mixin 收款插件問答羣

相關文章
相關標籤/搜索