<!--#include File="config.asp"-->
<!--#include File="md5.asp"-->
<%
'===============================================
'函 数 名：CreateData()
'函数用途：API签名函数
'版权所有：我要溜溜吧
'===============================================
Function CreateData(ByVal signtype,ByVal parent_cid,ByVal num_iids,ByVal snick,ByVal keyword,ByVal cid,ByVal credit,ByVal lprice,ByVal ssort,ByVal page_no,ByVal page_size)
If signtype = 2 Then 
   Dim sort,start_credit,end_credit,start_price,end_price
   Select Case ssort
    Case 1
     sort = "commissionRate_desc"
    Case 2
     sort = "price_desc"
    Case 3
     sort = "credit_desc"
    Case 4
     sort = "price_asc"
    Case 5
     sort = "commissionNum_desc"
    Case Else
     sort = "default"
   End Select 
   Select Case credit
    Case 1
     start_credit = "1crown"
     end_credit = "5goldencrown" 
    Case 2
     start_credit = "1diamond"
     end_credit = "5diamond"
    Case 3
     start_credit = "1heart"
     end_credit = "5heart"
    Case Else
     start_credit = "5diamond"
     end_credit = "5goldencrown"
   End Select 
   Select Case lprice
    Case 1
     start_price = "0"
     end_price = "100"
    Case 2
     start_price = "101"
     end_price = "500"
    Case 3
     start_price = "501"
     end_price = "1000"
    Case 4
     start_price = "1001"
     end_price = "2000"
    Case 5
     start_price = "2001"
     end_price = "9999999"
    Case Else
     start_price = ""
     end_price = ""
   End Select 
End if
Dim sign,appdata
Select Case signtype
   Case 1   '商品分类
    timestamp=Format_Time("1970-01-01 00:00:00")
    sign = UCase(md5(App_Secret&"api_key"&App_Key&"fields"&sfields1&"format"&Format&"method"&Method1&"parent_cid"&parent_cid&"sign_method"&Sign_Method&"timestamp"&timestamp&"v"&V&""&App_Secret))
    appdata = "api_key="&App_Key&"&fields="&sfields1&"&format="&Format&"&method="&Method1&"&parent_cid="&parent_cid&"&sign_method="&Sign_Method&"&timestamp="&UrlEncode_GBToUtf8(timestamp)&"&v="&V&"&sign="&sign&""
   Case 2   '查询淘宝客推广商品
    sign=UCase(md5(App_Secret&"api_key"&App_Key&"cid"&cid&"end_credit"&end_credit&"end_price"&end_price&"fields"&sfields2&"format"&Format&"keyword"&keyword&"method"&Method2&"nick"&Nick&"page_no"&page_no&"page_size"&page_size&"sign_method"&Sign_Method&"sort"&sort&"start_credit"&start_credit&"start_price"&start_price&"timestamp"&timestamp&"v"&V&""&App_Secret))
    appdata="api_key="&App_Key&"&keyword="&UrlEncode_GBToUtf8(keyword)&"&cid="&cid&"&sort="&sort&"&start_credit="&start_credit&"&end_credit="&end_credit&"&start_price="&start_price&"&end_price="&end_price&"&page_no="&page_no&"&page_size="&page_size&"&fields="&sfields2&"&format="&Format&"&method="&Method2&"&nick="&UrlEncode_GBToUtf8(Nick)&"&sign_method="&Sign_Method&"&timestamp="&UrlEncode_GBToUtf8(timestamp)&"&v="&V&"&sign="&sign&""
   Case 3   '淘宝客商品详情查询
    sign = UCase(md5(App_Secret&"api_key"&App_Key&"fields"&sfields3&"format"&Format&"method"&Method3&"nick"&Nick&"num_iids"&num_iids&"sign_method"&Sign_Method&"timestamp"&timestamp&"v"&V&""&App_Secret))
    appdata = "api_key="&App_Key&"&fields="&sfields3&"&format="&Format&"&method="&Method3&"&nick="&Nick&"&num_iids="&num_iids&"&sign_method="&Sign_Method&"&timestamp="&UrlEncode_GBToUtf8(timestamp)&"&v="&V&"&sign="&sign&""
   Case 4   '得到单个用户
    sign = UCase(md5(App_Secret&"api_key"&App_Key&"fields"&sfields4&"format"&Format&"method"&Method4&"nick"&snick&"sign_method"&Sign_Method&"timestamp"&timestamp&"v"&V&""&App_Secret))
    appdata = "api_key="&App_Key&"&fields="&sfields4&"&format="&Format&"&method="&Method4&"&nick="&UrlEncode_GBToUtf8(snick)&"&sign_method="&Sign_Method&"&timestamp="&UrlEncode_GBToUtf8(timestamp)&"&v="&V&"&sign="&sign&""
   Case 5   '获取卖家店铺的基本信息
    sign = UCase(md5(App_Secret&"api_key"&App_Key&"fields"&sfields5&"format"&Format&"method"&Method5&"nick"&snick&"sign_method"&Sign_Method&"timestamp"&timestamp&"v"&V&""&App_Secret))
    appdata = "api_key="&App_Key&"&fields="&sfields5&"&format="&Format&"&method="&Method5&"&nick="&UrlEncode_GBToUtf8(snick)&"&sign_method="&Sign_Method&"&timestamp="&UrlEncode_GBToUtf8(timestamp)&"&v="&V&"&sign="&sign&""
End Select 
CreateData = appdata
End Function 
'===============================================
'函 数 名：Format_Time(s_Time)
'函数用途：API时间格式化函数
'版权所有：我要溜溜吧
'===============================================
Function Format_Time(s_Time)
    Dim y, m, d, h, mi, s
    Format_Time = ""
    If IsDate(s_Time) = False Then Exit Function
    y = cstr(year(s_Time))
    m = cstr(month(s_Time))
    If len(m) = 1 Then m = "0" & m
    d = cstr(day(s_Time))
    If len(d) = 1 Then d = "0" & d
    h = cstr(hour(s_Time))
    If len(h) = 1 Then h = "0" & h
    mi = cstr(minute(s_Time))
    If len(mi) = 1 Then mi = "0" & mi
    s = cstr(second(s_Time))
    If len(s) = 1 Then s = "0" & s
    Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
End Function
'===============================================
'函 数 名：httpGet(url,data)
'函数用途：API获取数据函数
'版权所有：我要溜溜吧
'===============================================
Function httpGet(url,data)
	Set http=Server.CreateObject("Micro"&"soft.XML"&"HTTP")
	 On Error Resume Next
	 http.Open "GET",url + "?" + data,False 
	 http.send()
	 if Err then
	 Err.Clear
	 Response.Write("没有找到网页!<br>"&url + "?" + data)
	 Response.End()
	 End if
	 getHTTPPage=bytesToBSTR(Http.responseBody,"utf-8")
	set http=nothing 
	httpGet=getHTTPPage
End Function

Function BytesToBstr(body,Cset)
dim objstream 
set objstream = Server.CreateObject("adodb.stream") 
objstream.Type = 1 
objstream.Mode =3 
objstream.Open 
objstream.Write body 
objstream.Position = 0 
objstream.Type = 2 
objstream.Charset = Cset 
BytesToBstr = objstream.ReadText 
objstream.Close 
set objstream = nothing 
End Function

'============================
'过程名：listshow()
'作用：按条件获取商品数据
'============================
Function listshow(ByVal showcid,ByVal credit,ByVal lprice,ByVal ssort,ByVal showpage_no,ByVal showpage_size)
Dim dataparam,tmpshow
Dim num_iid,title,snick,pic_url,click_url,price,shop_click_url,seller_credit_score,item_location
Dim jj,rss
     jj = 0
     tmpshow = ""
     dataparam = CreateData(2,"","","","",""&showcid&"",credit,lprice,ssort,showpage_no,showpage_size)
     xcontent=httpGet(Url,dataparam)
     Set xml=Server.CreateObject("Microsoft.XMLDOM")
     xml.Async=False
     xml.ValidateOnParse=False
     xml.LoadXml(xcontent)
     If xml.ReadyState>2 Then
         Set item=xml.getElementsByTagName("taobaoke_item")
         If item.Length > 0 Then 
             For i=0 To (item.Length-1)
                 Set num_iid=item.Item(i).getElementsByTagName("num_iid")
                 Set title=item.Item(i).getElementsByTagName("title")
                 Set snick=item.Item(i).getElementsByTagName("nick")
                 Set pic_url=item.Item(i).getElementsByTagName("pic_url")
                 Set click_url=item.Item(i).getElementsByTagName("click_url")
                 Set price=item.Item(i).getElementsByTagName("price")
                 Set shop_click_url=item.Item(i).getElementsByTagName("shop_click_url")                
                 Set seller_credit_score=item.Item(i).getElementsByTagName("seller_credit_score")
                 Set item_location=item.Item(i).getElementsByTagName("item_location")
				 
                 tmpshow = tmpshow&"<dl><dt>"
				 tmpshow = tmpshow&"<p class='productlist_photo'><a href='"&click_url.Item(0).Text&"' target='_blank'>"
                 tmpshow = tmpshow&"<img src='"&pic_url.Item(0).Text&"_170x170.jpg' alt='"&title.Item(0).Text&"' /></a></p>"
                 tmpshow = tmpshow&"<p class='productlist_name'><a target='_blank' href="&click_url.Item(0).Text&">"&title.Item(0).Text&"</a></p>"
                 tmpshow = tmpshow&"<p class='productlist_price'><a href='"&shop_click_url.Item(0).Text&"' target='_blank'><img src='toshop.gif' align='absbottom' border='0' /></a> <b>￥"&price.Item(0).Text&"</b></p>"
                 'tmpshow = tmpshow&"<p class='productlist_name'>本月销售："&seller_credit_score.Item(0).Text&"件</p>"
				 tmpshow = tmpshow&"</dt></dl>"
                 Next 
             End If
         End If
         listshow = tmpshow
End Function
%>