Java SDK

环境准备

井通JAVA SDK的运行需要安装JAVA VM 7.0 以上版本。

下载安装

1、 通过以下链接地址下载最新版本SDK: 请点击链接下载sdk包 github下载地址:https://github.com/jingtum/jingtum-java-sdk.git

2、安装方法: JAVA SDK的使用需要用户首选安装JAVA开发环境。目前井通JAVA SDK需要J2SE开发包6.0以上版本。用户可以从 这里(http://www.oracle.com/technetwork/java/javase/downloads/)获取最新的JAVA环境. 此外,需要确认接口所使用的井通系统的服务器符合最新的配置,具体内容可参考附录中的系统配置。 安装成功Jingtum JAVA SDK后,可以在不同的开发端程序中使用; Apache Maven中,可以在项目中指定Jingtum SDK来调用井通SDK的功能函数。

程序示例

可参见https://github.com/jingtum/jingtum-java-sdk/test

产生新的井通帐号并激活

// get fingate instance
FinGate fingate = FinGate.getInstance();
// set fingate account
fingate.setAccount("snqFcH......pQYzxEEbW");
// set development mode(optional)
fingate.setMode(FinGate.DEVLOPMENT);
// set fingate parameters(optional)
fingate.setActiveAmount(25);

// method 1. create account from fingate
Wallet wallet1 = fingate.createWallet();

// activate it
fingate.activateWallet(wallet1.getAddress(), new PaymentListener() {
    @override
    public void onComplete(result) {
    }
});

查询帐号的余额信息

// get all balances
BalanceCollection bc = my_wallet.getBalance();

// get swt balance
BalanceCollection bc = my_wallet.getBalance("SWT");

// get usd balance
BalanceCollection bc = my_wallet.getBalance("USD");

使用帐号进行支付

// construct source wallet
 Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

 // prepare payment amount
 Amount amt = new Amount();
 amt.setIssuer("");
 amt.setCurrency("SWT");
 amt.setValue(1.1);

 // create payment operation
 PaymentOperation op = new PaymentOperation(wallet1);
 op.setDestAddress("jnYcyWcn......z62iMQSfaSXUx");
 op.setAmount(amt);
 op.setMemo("Test payment on 20161117");
 // if not set a client id, PaymentOperation will assign one
 op.setClientId("20611171957");
 // sync mode
 op.setValidate(true);

 // submit payment
 op.submit(new PaymentListener() {
     @override
     public void onComplete(result) {
         // process result
     }
 });

生成挂单

// construct source wallet
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

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

// submit offer
op.submit(new OfferListener() {
    @override
    public void onComplete(result) {
        // process result
    }
});

取消挂单

// construct source wallet
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

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

// submit offer cancel
op.submit(new OfferCancelListener() {
    @override
    public void onComplete(result) {
        // process result
    }
});