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

Dokumen pembangunan platform terbuka Taobao / 平臺(tái)技術(shù)-.NET SDK使用說(shuō)明

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

環(huán)境依賴

  • .NET Framework 2.0 及以上 (不支持Windows Phone平臺(tái))

使用示例

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

ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
TimeGetRequest req = new TimeGetRequest();
TimeGetResponse rsp = client.Execute(req);
Console.WriteLine(rsp.Body);

獲取單筆交易詳情

ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
TradeFullinfoGetRequest req = new TradeFullinfoGetRequest();
req.Fields = "tid,type,status,payment,orders";
req.Tid = 123456789L;
TradeFullinfoGetResponse rsp = client.Execute(req, sessionKey);
Console.WriteLine(rsp.Body);

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

TmcClient client = new TmcClient("app_key", "app_secret", "default"); 
client.OnMessage += (s, e) => 
{ 
    try 
    { 
        Console.WriteLine(e.Message.Content); 
        Console.WriteLine(e.Message.Topic);
        // 默認(rèn)不拋出異常則認(rèn)為消息處理成功 
    } 
    catch (Exception exp) 
    { 
        Console.WriteLine(exp.StackTrace); 
        e.Fail(); // 消息處理失敗回滾,服務(wù)端需要重發(fā) 
    } 
}; 
client.Connect("ws://mc.api.taobao.com/");

批量調(diào)用API

BatchTopClient client = new BatchTopClient("http://gw.api.taobao.com/router/batch", "appkey", "appsecret", "json");
TimeGetRequest timeRequest = new TimeGetRequest();
AppipGetRequest ipRequest = new AppipGetRequest();
TopBatchRequest batch = new TopBatchRequest();
batch.AddRequest(timeRequest).AddRequest(ipRequest);
TopBatchResponse rsp = client.Execute(batch);
Console.WriteLine(rsp.Body);

服務(wù)地址

API服務(wù)地址

QQ截圖20170213154955.png

消息服務(wù)地址

QQ截圖20170213155016.png

高級(jí)功能

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

DefaultTopClient.SetDisableParser(true)

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

DefaultTopClient.SetUseSimplifyJson(true)

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

DefaultTopClient.SetDisableTrace(true)

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

DefaultTopClient.SetIgnoreSSLCheck(true)

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

DefaultTopClient.SetUseGzipEncoding(false)

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

// HTTP等待請(qǐng)求開(kāi)始返回的超時(shí)時(shí)間:默認(rèn)20秒
DefaultTopClient.SetTimeout(20000L)
// HTTP等待讀取數(shù)據(jù)完成的超時(shí)時(shí)間:默認(rèn)60秒
DefaultTopClient.SetReadWriteTimeout(60000L)

修改日志打點(diǎn)存儲(chǔ)路徑

DefaultTopLogger.FilePath = "c:/tmp/topsdk.log";

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

AutoRetryTopClient client = new AutoRetryTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
client.SetMaxRetryCount(3);
client.SetRetryWaitTime(100L);
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.Execute(request);
if (!response.IsError) {
    Console.WriteLine(response.Body);
}

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

ClusterTopClient client = new ClusterTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.Execute(request);
Console.WriteLine(response.Body);

注意事項(xiàng)

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

FAQ

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