Fan-BAPI SDK调用示例[下载]


//定义缓存目录和引入文件
define("DIR_RUNTIME","runtime/");
define("DIR_ERROR","runtime/");
define("SECACHE_SIZE","15M");

include "ObApiClient.php";

//初始化	
$ob = new ObApiClient();
$ob->api_url = "https://api-gw.fan-b.com/";
$ob->api_key = "demo_api_key";
$ob->api_secret = "";
$ob->api_version ="";
$ob->secache_path ="/tmp/";
$ob->secache_time ="86400";
$ob->cache = true;
$ob->lang = "cn";
	
示例:获取jd API数据调用代码如下:


$result['jd'] = $ob->exec(
     array(
     'api_type' =>'jd',
     'api_name' =>'item_get',
     'api_params'=>array('num_iid'=>29186819959)
     )
    );

用时:0.49770秒


示例:获取taobao API数据调用代码如下:


$result['taobao'] = $ob->exec(
     array(
     'api_type' =>'taobao',
     'api_name' =>'item_get',
     'api_params'=>array('num_iid'=>557216270522)
     )
    );

用时:0.49771秒


示例:获取1688 API数据调用代码如下:


$result['1688'] = $ob->exec(
     array(
     'api_type' =>'1688',
     'api_name' =>'item_get',
     'api_params'=>array('num_iid'=>564876975705)
     )
    );

用时:0.49771秒


示例:获取amazon API数据调用代码如下:


$result['amazon'] = $ob->exec(
     array(
     'api_type' =>'amazon',
     'api_name' =>'item_get',
     'api_params'=>array('num_iid'=>'B00GW94B1W-cn')//B016LO4UTA
     )
    );

用时:0.49772秒


示例:获取mls API数据调用代码如下:


$result['mls'] = $ob->exec(
     array(
     'api_type' =>'mls',
     'api_name' =>'item_get',
     'api_params'=>array('num_iid'=>'1gmuw4o')
     )
    );

用时:0.49772秒


示例:获取translate API数据调用代码如下:


$result['translate'] = $ob->exec(
     array(
     'api_type' =>'translate',
     'api_name' =>'t_json',
     'api_params'=>array('text'=>'["Hello world","I\'m come!"]','sl'=>'en','tl'=>'zh-CN')
     )
    );

用时:0.49773秒