Taobao.items.search
http://open.taobao.com/dev/index.php/API2.0:Taobao.items.search
TucueClientUtil.cs 文件:
using System;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Configuration;
usingSystem.IO;
usingSystem.Text.RegularExpressions;
usingTucue.Top.Api.Util;
usingSystem.Diagnostics;
usingSystem.Net;
namespaceTucue.Top.Api
{
publicclassTucueClientUtil
{
publicstaticITucueClientGetSandboxTopClient()
{
GetAppkeyScret();
returnnewTucueRestClient("http://gw.api.taobao.com/router/rest?",appKey,appSecret);
}
publicstaticITucueClientGetProductTopClient()
{
GetAppkeyScret();
returnnewTucueRestClient("http://gw.api.taobao.com/router/rest?",appKey,appSecret,"xml");
}
privatestaticvoidGetAppkeyScret()
{
try
{
appKey=ConfigurationManager.AppSettings["appKey"].ToString();
appSecret=ConfigurationManager.AppSettings["appSecret"].ToString();
}
catch(Exceptione)
{
Trace.WriteLine(e.Message.ToString());
}
}
///<summary>
///获取测试环境下的用户会话授权码。
///</summary>
///<paramname="nick">用户昵称</param>
///<returns>用户会话授权码</returns>
publicstaticstringGetSandboxSessionKey(stringnick)
{
IDictionary<string,string>authCodeParams=newDictionary<string,string>();
authCodeParams.Add("appkey","sns");
authCodeParams.Add("nick",nick);
stringauthCodeRsp=WebUtils.DoPost(TOP_AUTHORIZE_URL,authCodeParams);
stringauthCodePattern="<inputtype=\"text\"id=\"autoInput\"value=\"(.+?)\"style=\".+?\">";
MatchauthCodeResult=Regex.Match(authCodeRsp,authCodePattern);
stringauthCode=authCodeResult.Groups[1].Value;
IDictionary<string,string>sessionParams=newDictionary<string,string>();
sessionParams.Add("authcode",Uri.UnescapeDataString(authCode));
stringsessionRsp=WebUtils.DoGet(TOP_CONTAINER_URL,sessionParams);
stringsessionPattern="&top_session=(\\w+?)&";
MatchsessionResult=Regex.Match(sessionRsp,sessionPattern);
stringsessionKey=sessionResult.Groups[1].Value;
returnsessionKey;
}
privatestaticstringappKey="12008052";
privatestaticstringappSecret="5de0727f2d66808ebe481c2b31705e02";
privateconststringTOP_AUTHORIZE_URL="http://open.taobao.com/isv/authorize.php";
privateconststringTOP_CONTAINER_URL="http://container.sandbox.taobao.com/container";
}
}