轻轻松松使用asp做api淘宝客(3)

2019-04-09 20:26

使用方法 :zzBokeOrder (TaoApiRecord) 结果:

zzBokeOrder=app_key12345678formatxmlsign_methodmd5timestamp2012-09-10 09:42:25v2.0 注意:我们看第四点,value无需编码,我们生成的结果里面没有中文所以不需要编码,但是文档说明里的这一点往往就是出错点,关键字查询的时候是中文这里必须要处理,淘宝官方说需要进行utf8编码处理,其实我告诉你,不管你的程序语言是utf8编码还是gb2312编码,在签名的时候数组里的关键字必须是gb2312的处理,这里就用到我们上面的YuZhe_UrlEncode编码处理函数。关键字加入数组的时候要处理,方法如下

strKeyword=YuZhe_UrlEncode(Keyword,936)?把汉字转换成gb2312格式 ArrayList \

现在我们开始生成签名,看第五点将secretcode同时拼接到参数字符串头、尾部进行md5加密,第六点转换成大写。 结果:

sign = zzbokeOrder(TaoapiRecord)

sign=ucase(md5(strsecretCode&sign&strsecretCode))

大功告成,签名生成了。那么我们就要给淘宝传递参数了。传递方式如下

http://gw.api.tbsandbox.com/router/rest?sign=5029C3055D51555112B60B33000122D5×tamp=2011-07-01+13:52:03&v=2.0&app_key=test&method=taobao.user.get&partner_id=top-apitools&format=xml&nick=???????μ?èˉ??????·17&fields=nick,location.state,location.city

注意:刚才我们说签名里的汉字问题,这里也需要注意传递的参数汉字问题。签名里是gb2312的编码。这里给淘宝发送的信息里又需要的是utf的编码。这里如意搞混淆。在做开发的是本人也是大费周章。最后还是被我发现了,所以这里我们还是通过我们的数组进行组合我用了一个函数处理 '组参+签名函数

function createStrParam()

For I = Lbound(TaoapiRecord) to Ubound(TaoapiRecord) arry=split(TaoapiRecord(I),\ If URLsignRecord=\

URLsignRecord =arry(0)&\ Else

if arry(0)=\

URLsignRecord =URLsignRecord&\ else

URLsignRecord =URLsignRecord&\ end if End If Next

createStrParam=URLsignRecord end function

结果:

timestamp=2011-07-01+13:52:03&v=2.0&app_key=test&method=taobao.user.get&partner_id=top-apitools&format=xml&nick=???????μ?èˉ??????·17&fields=nick,location.state,location.city 有了签名和传递的参数进行最终的组合,就是把获取淘宝客数据的地址http://gw.api.taobao.com/router/rest?和签名加在上面的结果里。 Httpurl=http://gw.api.taobao.com/router/rest?

timestamp=2011-07-01+13:52:03&v=2.0&app_key=test&method=taobao.user.get&partner_id=top-apitools&format=xml&nick=???????μ?èˉ??????·17&fields=nick,location.state,location.city&sign=15AS4SAD47DDUDBB23234

好了,签名和传递的参数都做好了,今天的课程也就到这里了。给的作业就是把这几个函数都整理一下,明天我们就获取获取,有能力的做成一个类文件方便调去。明天我带大家取数据了

又是一个新的开始,昨天的课程不知道大家学的如何了,今天我带大家一起获取淘宝数据。先问问大家你们有没有做昨天的作业呢?肯定有同学偷懒了。为了方便测试我已经写好了,今天就拿出来吧,免得大家说我扣。 直接上函数,没有注释…..

文件名:New_APi.asp <%

Class MainClass_TopAPi Private strGetUrl Private strVersion Private strFormat Private strSign_Method Private

TaoApiRecord,strapp_key,strsecretCode,strpid,strPage_Size,strMethod,strFields,strSort,strPage_No,strKeyword

Private Sub Class_Initialize()

strGetUrl = \ strVersion = \ strFormat=\ strSign_Method=\ TaoApiRecord =

Array(\thod=\ End Sub

Private Sub Class_Terminate() End Sub '定义的方法

Public Sub Information() End Sub

Public Property Let setapp_Key(ByVal app_Key) ArrayList \ End Property

Public Property Let setsecretCode(ByVal secretCode) strsecretCode=secretCode End Property

Public Property Let setpid(ByVal pid) ArrayList \ End Property

Public Property Let setPage_Size(ByVal Page_Size) ArrayList \ End Property

Public Property Let setMethod(ByVal method) ArrayList \ End Property

Public Property Let setFields(ByVal fields) ArrayList \ End Property

Public Property Let setSort(ByVal sort) ArrayList \ End Property

Public Property Let setPage_No(ByVal Page_No) ArrayList \ End Property

Public Property Let setCid(ByVal Cid) ArrayList \ End Property

Public Property Let setKeyword(ByVal Keyword) strKeyword=YuZhe_UrlEncode(Keyword,936) ArrayList \ End Property

'数组中增增加

Function ArrayList(tag,value) arrLenth=UBound(TaoApiRecord)

REDIM Preserve TaoApiRecord(arrlenth+1) TaoApiRecord(arrlenth+1)=tag&\ ArrayList=TaoApiRecord End Function

'============数组冒泡排序===================== Function ArraySort(ary) KeepChecking = TRUE

Do Until KeepChecking = FALSE KeepChecking = FALSE For I = 0 to UBound(ary) If I = UBound(ary) Then Exit For If ary(I) > ary(I+1) Then FirstValue = ary(I) SecondValue = ary(I+1) ary(I) = SecondValue ary(I+1) = FirstValue KeepChecking = TRUE End If Next Loop

ArraySort = ary End Function

'按要求进行排序组织传递的参数 Function zzBokeOrder(ary) zzBokeOrder=\

MyArray = ArraySort(ary)

For I = Lbound(MyArray) to Ubound(MyArray) If zzBokeOrder=\ zzBokeOrder =MyArray(I) Else

zzBokeOrder =zzBokeOrder&\ End If Next End Function

'组参+签名函数

function createStrParam()

signRecord = zzbokeOrder(TaoapiRecord)

For I = Lbound(TaoapiRecord) to Ubound(TaoapiRecord) arry=split(TaoapiRecord(I),\

If URLsignRecord=\

URLsignRecord =arry(0)&\ Else

if arry(0)=\

URLsignRecord =URLsignRecord&\ else

URLsignRecord =URLsignRecord&\ end if End If Next

sign=Replace(Replace(signRecord,\ sign=ucase(md5(strsecretCode&sign&strsecretCode)) '给taobao传递的参数

createStrParam=URLsignRecord &\

end function

'============httpget=========== dim gXmlHttpVer Function getXmlHttpVer()

dim i,xmlHttpVersions,xmlHttpVersion getXmlHttpVer=false

xmlHttpVersions=Array(\\ for i=0 to ubound(xmlHttpVersions) xmlHttpVersion=xmlHttpVersions(i)

if isInstallObj(xmlHttpVersion) then getXmlHttpVer=xmlHttpVersion:gXmlHttpVer=xmlHttpVersion: Exit Function next End Function

Function tryXmlHttp() dim

i,ah:ah=array(\HTTP.2.0\LHTTP.6.0\

\ On Error Resume Next for i=0 to UBound(ah)

SET tryXmlHttp=Server.CreateObject(ah(i))

if err.number=0 then:gXmlHttpVer=ah(i):tryXmlHttp.setTimeouts 2000,20000,20000,180000:err.clear:Exit Function:else:err.clear:end if next


轻轻松松使用asp做api淘宝客(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:厦门市业主大会及业主委员会服务手册

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: