PHP SDK

环境准备

井通SDK PHP的运行需要PHP支持 JSON(PHP 5.2.x 以上版本)和安装 CURL 扩展程序库。 此外,需要确认接口所使用的井通系统的服务器符合最新的配置,具体内容可参考附录中的系统配置。 在Ubuntu 14下查询当前安装的软件依赖包,使用

apt-cache search php5

可以搜索安装的php5程序库。 以下命令在Ubuntu 14下自动安装curl扩展程序库。

sudo apt-get install php5-curl

ECDSA文件需要(GNU Multiple Precision (GMP) Arithmetic Library).

sudo apt-get install php5-gmp

下载安装

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

请点击链接下载sdk包 github下载地址:https://github.com/jingtum/jingtum-php-sdk.git

2、使用composer安装方法: 首先保证系统安装了composer。如果没有,则需要安装Composer工具,具体可以参考 Composer 的说明。

curl -sS https://getcomposer.org/installer | php

在当前目录下的composer.json中加入PHP SDK的程序信息,如:

"require": {
 "jingtum/jingtum-php-sdk": "dev-master"
}

运行以下命令安装:

php composer.phar install

程序示例

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

产生新的井通帐号

//Set the FinGate instance
$fin_gate = FinGate::getInstance();

//Set the work mode
$fin_gate->setMode(FinGate::DEVELOPMENT);

//Set up the FinGate account
$fin_gate->setAccount('sha4eGoQu......V3YQ4');

//Create the wallet from FinGate
$wallet1 = $fin_gate->createWallet();

//active the wallet
$fin_gate->activeWallet($wallet1->getAddress(), 'call_back_func');

查询帐号的余额信息

//Set the FinGate instance
$fin_gate = FinGate::getInstance();

//Set the work mode
$fin_gate->setMode(FinGate::DEVELOPMENT);

//Setup a test wallet
$wallet = new Wallet('sha4eGoQu......V3YQ4');

//Get the balance
$res = $wallet->getBalance();

使用帐号进行支付

//Set the FinGate instance
$fin_gate = FinGate::getInstance();

//Set the work mode
$fin_gate->setMode(FinGate::DEVELOPMENT);

//Setup two wallets for testing
$wallet2 = new Wallet('sha4eGoQu......V3YQ4');

$wallet3 = new Wallet('snwjtucx9......MhFiK9');

//A payment obj for testing
$op = new PaymentOperation($wallet2);

//Create the payment amount
$pay_value = 0.01;
$amt1 = new Amount($pay_value, 'SWT', '');

//Set the destination address
$op->setDestAddress($wallet3->getAddress());

//Set the amount to pay
$op->setAmount($amt1);

//Optional settings
$client_id = "JTtest".time();
$op->setClientID($client_id);//optional, if not provided, SDK will generate an internal one
$op->setMemo("SWT PAYMENT for testing".$client_id);//memo used in the payment
$op->setValidate(false);//setup the syn mode, default is true

$op->submit('call_back_func');

生成挂单

//Set the FinGate instance
$fin_gate = FinGate::getInstance();

//Set the work mode
$fin_gate->setMode(FinGate::DEVELOPMENT);

$wallet1 = new Wallet('snwjtucx9......MbVz8hFiK9');

$op = new OrderOperation($wallet1);
$op->setType($op->SELL);
$op->setPair("SWT/CNY:janxMdr...GewMMeHa9f");
$op->setAmount(1000.00 );
$op->setValidate(true);

$op->submit('call_back_func');

取消挂单

//Set the FinGate instance
$fin_gate = FinGate::getInstance();

//Set the work mode
$fin_gate->setMode(FinGate::DEVELOPMENT);

$wallet1 = new Wallet('snwjtucx9......MbVz8hFiK9');
$op = new CancelOrderOperation($wallet);

$op->setOrderNum(54);
$op->setValidate('true');

$op->submit('call_back_func');