mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-13 07:01:20 +08:00
比特币支付:生成支付地址
This commit is contained in:
12
core/bitcoin.coffee
Normal file
12
core/bitcoin.coffee
Normal file
@@ -0,0 +1,12 @@
|
||||
request = require 'request'
|
||||
|
||||
config = require './config'
|
||||
|
||||
exports.genAddress = (blockchain_secret, callback) ->
|
||||
callback_url = "#{config.web.url}/bitcoin/blockchain_callback?secret=#{blockchain_secret}"
|
||||
url = "https://blockchain.info/api/receive?method=create&address=#{config.bitcoin.forward_to}&callback=#{encodeURI(callback_url)}"
|
||||
|
||||
request url, (err, res, body) ->
|
||||
body = JSON.parse body
|
||||
|
||||
callback body.input_address
|
||||
@@ -1,5 +1,6 @@
|
||||
module.exports =
|
||||
web:
|
||||
url: 'http://rp3.rpvhost.net'
|
||||
port: 3000
|
||||
|
||||
debug:
|
||||
@@ -43,6 +44,9 @@ module.exports =
|
||||
|
||||
mongodb: 'mongodb://localhost/RootPanel'
|
||||
|
||||
bitcoin:
|
||||
forward_to: '1FjhhWrzAvb9YD4tVdbE6wrSoHSwxMJoWe'
|
||||
|
||||
plugins:
|
||||
mysql:
|
||||
connection:
|
||||
|
||||
@@ -20,6 +20,7 @@ bindRouters = (app) ->
|
||||
app.use '/ticket', require './router/ticket'
|
||||
app.use '/wiki', require './router/wiki'
|
||||
app.use '/public', require './router/public'
|
||||
app.use '/bitcoin', require './router/bitcoin'
|
||||
|
||||
app.get '/', (req, res) ->
|
||||
res.redirect '/panel/'
|
||||
|
||||
@@ -3,6 +3,7 @@ crypto = require 'crypto'
|
||||
|
||||
db = require '../db'
|
||||
config = require '../config'
|
||||
bitcoind = require '../bitcoin'
|
||||
|
||||
mBalance = require './balance'
|
||||
|
||||
@@ -26,6 +27,9 @@ sample =
|
||||
QQ: '184300584'
|
||||
|
||||
attribute:
|
||||
bitcoin_deposit_address: '13v2BTCMZMHg5v87susgg86HFZqXERuwUd'
|
||||
blockchain_secret: '53673f434686b535a6cec7b73a60ce045477f066f30eded55a9b972ccafddb2a'
|
||||
|
||||
services: ['shadowsocks']
|
||||
plans: ['all']
|
||||
|
||||
@@ -54,7 +58,7 @@ sample =
|
||||
]
|
||||
|
||||
exports.sha256 = (data) ->
|
||||
if not data
|
||||
unless data
|
||||
return null
|
||||
return crypto.createHash('sha256').update(data).digest('hex')
|
||||
|
||||
@@ -66,29 +70,33 @@ exports.hashPasswd = (passwd, passwd_salt) ->
|
||||
|
||||
exports.register = (username, email, passwd, callback) ->
|
||||
passwd_salt = exports.randomSalt()
|
||||
blockchain_secret = exports.randomSalt()
|
||||
|
||||
exports.insert
|
||||
_id: db.ObjectID()
|
||||
username: username
|
||||
passwd: exports.hashPasswd(passwd, passwd_salt)
|
||||
passwd_salt: passwd_salt
|
||||
email: email
|
||||
signup_at: new Date()
|
||||
group: []
|
||||
setting:
|
||||
avatar_url: "//ruby-china.org/avatar/#{crypto.createHash('md5').update(email).digest('hex')}?s=58"
|
||||
attribute:
|
||||
services: []
|
||||
plans: []
|
||||
balance: 0
|
||||
last_billing_at: new Date()
|
||||
arrears_at: null
|
||||
resources_limit: []
|
||||
bitcoin.genAddress blockchain_secret, (address) ->
|
||||
exports.insert
|
||||
_id: db.ObjectID()
|
||||
username: username
|
||||
passwd: exports.hashPasswd(passwd, passwd_salt)
|
||||
passwd_salt: passwd_salt
|
||||
email: email
|
||||
signup_at: new Date()
|
||||
group: []
|
||||
setting:
|
||||
avatar_url: "//ruby-china.org/avatar/#{crypto.createHash('md5').update(email).digest('hex')}?s=58"
|
||||
attribute:
|
||||
bitcoin_deposit_address: address
|
||||
blockchain_secret: blockchain_secret
|
||||
services: []
|
||||
plans: []
|
||||
balance: 0
|
||||
last_billing_at: new Date()
|
||||
arrears_at: null
|
||||
resources_limit: []
|
||||
|
||||
plugin: {}
|
||||
tokens: []
|
||||
, (err, result) ->
|
||||
callback err, result?[0]
|
||||
plugin: {}
|
||||
tokens: []
|
||||
, (err, result) ->
|
||||
callback err, result?[0]
|
||||
|
||||
exports.updatePasswd = (account, passwd, callback) ->
|
||||
passwd_salt = exports.randomSalt()
|
||||
|
||||
10
core/router/bitcoin.coffee
Normal file
10
core/router/bitcoin.coffee
Normal file
@@ -0,0 +1,10 @@
|
||||
express = require 'express'
|
||||
async = require 'async'
|
||||
|
||||
config = require '../config'
|
||||
plugin = require '../plugin'
|
||||
|
||||
module.exports = exports = express.Router()
|
||||
|
||||
exports.get '/blockchain_callback', (req, res) ->
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"middleware-injector": "*",
|
||||
"tmp": "*",
|
||||
"mysql": "*",
|
||||
"moment": "*"
|
||||
"moment": "*",
|
||||
"request": "*"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user