Node.JS SDK

环境准备

井通NODE.JS SDK的运行需要安装NODEJS v4.5 以上版本。

下载安装

1、 通过以下链接地址下载最新版本SDK:

请点击链接下载sdk包

github下载地址:https://github.com/jingtum/jingtum-js-sdk.git

2、安装方法: 安装好NODEJS后,最好通过npm工具来安装Node SDK.此外,需要确认接口所使用的井通系统的服务器符合最新的配置,具体内容可参考附录中的系统配置。

npm install jingtum-sdk

安装成功Jingtum-sdk后,可以在程序中使用;

var JingtumSDK = require('jingtum-sdk');

来调用井通SDK的功能函数。

程序示例

可参见https://github.com/jingtum/jingtum-js-sdk/examples下的示例。

产生新的井通帐号

var wallet1 = fingate.createWallet();

//or
    var Wallet = JingtumSDK.Wallet;
    var walletNew = new Wallet('shNK......5kK');

查询帐号的余额信息

var Wallet = require('jingtum-sdk').Wallet;
// construct one wallet
var my_wallet = new Wallet('shNKNxg......AKBFy5W5kK');

// get all balances
my_wallet.getBalance(function (err, data) {
    // process balance
});

// get swt balance
my_wallet.getBalance('SWT', function(err, data) {
    // process balance
});

// get usd balance
my_wallet.getBalance('USD', function(err, data) {
    // process balance
});

使用帐号进行支付

// create payment operation
var op = new JingtumSDK.PaymentOperation(wallet1);
op.setDestAddress('jp53t......DucnwVk');
op.setAmount(amt);
op.setMemo("Test payment on 20161117");

// if not set, PaymentOperation will assign one
op.setClientId("20611171957");
// sync mode
op.setValidate(true);

// submit payment
op.submit(function (err, res) {
    if(err) { console.log(err); return; }
    console.log(res);
});

生成挂单

// construct source wallet
var JingtumSDK = require('jingtum-sdk');
var Wallet = JingtumSDK.Wallet;

var wallet1 = new Wallet('shNK......y5W5kK');

// create offer operation
var op = new JingtumSDK.OrderOperation(wallet1);
op.setType(op.SELL);
op.setPair("SWT/CNY:janxMdr...GewMMeHa9f");
op.setAmount(1000.00);
op.setPrice(0.0005);
// sync mode
op.setValidate(true);

// submit payment
op.submit(function (err, res) {
    if(err) { console.log(err); return; }
    console.log(res);
});

取消挂单

// construct source wallet
var JingtumSDK = require('jingtum-sdk');
var Wallet = JingtumSDK.Wallet;

var wallet1 = new Wallet('shNK......y5W5kK');

// create offer cancel operation
var op = new JingtumSDK.CancelOrderOperation(wallet1);
op.setSequence(54);
op.setValidate(true);

// submit offer cancel
op.submit(function (err, res) {
    if(err) { console.log(err); return; }
    console.log(res);
});