起始頁面為Login.aspx,固定調試端口為49441。需要配合自己淘寶開放平臺的應用的回調頁面URL來調整。
ashx代碼:
(說明:代碼中ITopClient為淘寶接口TopSdk.dll中的類,此例子使用的ItemsOnsaleGetRequest是用于獲取銷售中的商品,response.Body是獲取到的數據信息)
復制代碼代碼如下:
public class OnsaleGet : IHttpHandler
{</p><p> public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
ITopClient client = new DefaultTopClient(Config.ServerURL, Config.Appkey, Config.Secret);</p><p> ItemsOnsaleGetRequest req = new ItemsOnsaleGetRequest();
req.Fields = "approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id";
ItemsOnsaleGetResponse response = client.Execute(req, Config.Top_session);</p><p>
if (response.IsError)
{
context.Response.Write("[錯誤:查詢函數執行失敗]");
}
else
{
context.Response.Write(response.Body);
}</p><p> }</p><p> public bool IsReusable
{
get
{
return false;
}
}
}
前端SL獲取數據信息的方法
復制代碼代碼如下:
void GetList()
{
string absolutePath = HtmlPage.Document.DocumentUri.AbsoluteUri;
string address = absolutePath.Substring(0, absolutePath.LastIndexOf('/'))
+ "/TaoBaoHandler/OnsaleGet.ashx";</p><p> Uri uri = new Uri(address);</p><p> WebClient client = new WebClient();
client.DownloadStringCompleted += (sender, e) =>
{
if (e.Error == null)
{
System.Xml.Linq.XElement.Parse(e.Result);//字符串轉為xml
ItemsOnsaleGetResponse list = SerializeHelper.DeserializeFromString<ItemsOnsaleGetResponse>(e.Result);//反序列化
if (list != null)
{
if (list.Items != null && list.Items.Count > 0)
{
MessageBox.Show(list.Items[0].NumIid.ToString());
}
}
else
{
}
}
else
{
MessageBox.Show(e.Error.Message);
新聞熱點
疑難解答