亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

淘寶開(kāi)放平臺(tái)開(kāi)發(fā)文檔 / 平臺(tái)技術(shù)-Java SDK使用說(shuō)明

平臺(tái)技術(shù)-Java SDK使用說(shuō)明

環(huán)境依賴(lài)

使用示例

獲取淘寶當(dāng)前系統(tǒng)時(shí)間

DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret");
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.execute(request);
if (response.isSuccess()) {
    System.out.println(response.getBody());
}

獲取單筆交易詳情

DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret");
TradeFullinfoGetRequest req = new TradeFullinfoGetRequest();
req.setFields("tid,type,status,payment,orders");
req.setTid(123456789L);
TradeFullinfoGetResponse rsp = client.execute(req, sessionKey);
System.out.println(rsp.getBody());

監(jiān)聽(tīng)實(shí)時(shí)消息通知

TmcClient client = new TmcClient("app_key", "app_secret", "default");
client.setMessageHandler(new MessageHandler() {  
    public void onMessage(Message message, MessageStatus status) {  
        try {  
            System.out.println(message.getContent());  
            System.out.println(message.getTopic());
        } catch (Exception e) {  
            e.printStackTrace();  
            status.fail();// 消息處理失敗回滾,服務(wù)端需要重發(fā)  
        }  
    }  
});  
client.connect("ws://mc.api.taobao.com/");

批量調(diào)用API

BatchTaobaoClient client = new BatchTaobaoClient("http://gw.api.taobao.com/router/batch", "appkey", "appsecret");
TaobaoBatchRequest batch = new TaobaoBatchRequest();
TimeGetRequest timeRequest = new TimeGetRequest();
AppipGetRequest ipRequest = new AppipGetRequest();
batch.addRequest(timeRequest).addRequest(ipRequest);
TaobaoBatchResponse response = client.execute(batch);
System.out.println(response.getBody());

服務(wù)地址

API服務(wù)地址

QQ截圖20170213154503.png

消息服務(wù)地址

QQ截圖20170213154526.png

高級(jí)功能

不解釋響應(yīng)字符串為對(duì)象(這時(shí)候XxxResponse包含的對(duì)象為null)

DefaultTaobaoClient.setNeedEnableParser(false)

采用精簡(jiǎn)化的JSON結(jié)構(gòu)返回,去除多余JSON節(jié)點(diǎn)

DefaultTaobaoClient.setUseSimplifyJson(true)

取消API調(diào)用日志打點(diǎn)

DefaultTaobaoClient.setNeedEnableLogger(false)

忽略HTTPS證書(shū)檢查(建議只在測(cè)試環(huán)境打開(kāi))

DefaultTaobaoClient.setIgnoreSSLCheck(true)

取消響應(yīng)GZIP壓縮功能(GZIP壓縮功能可以顯著的減少網(wǎng)絡(luò)傳輸,強(qiáng)烈建議不要取消)

DefaultTaobaoClient.setUseGzipEncoding(false)

設(shè)置HTTP連接超時(shí)和讀超時(shí)時(shí)間(網(wǎng)絡(luò)環(huán)境差的情況下可以適當(dāng)增大)

// HTTP連接默認(rèn)超時(shí)時(shí)間為:3秒
// HTTP響應(yīng)讀默認(rèn)超時(shí)時(shí)間為:15秒
DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", connectTimeout, readTimeout)

API調(diào)用出錯(cuò)自動(dòng)重試(一般情況下ISP類(lèi)的錯(cuò)誤是可以重試成功的)

AutoRetryTaobaoClient client = new AutoRetryTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret");
client.setMaxRetryCount(3);
client.setRetryWaitTime(100L);
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.execute(request);
if (response.isSuccess()) {
    System.out.println(response.getBody());
}

API調(diào)用就近路由(根據(jù)API發(fā)起調(diào)用所在地選擇就近的TOP機(jī)房進(jìn)行調(diào)用)

ClusterTaobaoClient client = new ClusterTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret");
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.execute(request);
System.out.println(response.getBody());

注意事項(xiàng)

  • TaobaoClient的實(shí)現(xiàn)類(lèi)都是線(xiàn)程安全的,所以沒(méi)有必要每次API請(qǐng)求都新建一個(gè)TaobaoClient實(shí)現(xiàn)類(lèi)
  • 創(chuàng)建TaobaoClient實(shí)現(xiàn)類(lèi)的實(shí)例時(shí),指定format=json,相比xml格式,可以減少數(shù)據(jù)傳輸量,提升API請(qǐng)求效率

FAQ

  • 關(guān)于此文檔暫時(shí)還沒(méi)有FAQ