2014-03-12 82 views

回答

0

要創建您可以使用類似這樣的地址:

app.js:

api = require('blockchain') 
app.post('/api/blockchain/createAddress', api.blockchainCreateAddress); 

blockchain.js:

exports.blockchainCreateAddress = function(req, res) { 

    var btc_address = '<you-destination-btc-address>'; 
    var api_url = 'https://blockchain.info/api/receive'; 
    var callback_url = '<your-callback-url>'; 

    var url = api_url + '?method=create&address=' + btc_address + '&callback=' + encodeURIComponent(callback_url); 

    if (btc_address) 
    { 
     https.get(url, function(resp) { 

      console.log("Calling Blockchain API at " + url) 

      var body = ''; 

      resp.on('data', function(chunk) { 
       body += chunk; 
      }); 

      resp.on('end', function() { 
       try 
       { 
        console.log('Blockchain returns: ' + body); 

        res.json(JSON.parse(body)); 
       } 
       catch(e) 
       { 
        msg.error = e; 
       }   

      }); 
     }).on('error', function(e) { 
      msg.error = e; 
     }); 
    } 
}; 

這是第一部分,區塊鏈會用一些數據迴應你,你應該存儲input_addre ss退回併發送付款給公衆(向公衆公開)。

將付款發送給input_address後,您應該創建一個新的模塊來處理區塊鏈回調。

創建這樣的事情,繼續按照商務部在https://blockchain.info/api/api_receive(實現回調)

app.js

[...] 
app.get('<your-callback-path>/:value/:input_address/:confirmations/:transaction_hash/:input_transaction_hash/:destination_address', api.blockchainCallback); 
[...] 

blockchain.js:

exports.blockchainCallback = function(req, res) { 
    // Go on and save/store the payment 
    // remember to send *ok* result string when you are done 
    res.send("*ok*"); 
}); 

希望這可以幫助您。

+0

你有工作嗎? –