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

2019-04-09 20:26

'================================================== 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 = \d = cstr(day(s_Time)) If len(d) = 1 Then d = \h = cstr(hour(s_Time)) If len(h) = 1 Then h = \mi = cstr(minute(s_Time)) If len(mi) = 1 Then mi = \s = cstr(second(s_Time)) If len(s) = 1 Then s = \' yyyy-mm-dd hh:mm:ss

Format_Time = y & \End Function

2、整个获取过程中我们传递给淘宝的数据是utf-8格式的,所以我们对传递的汉字部分(关键字,淘宝用户名)进行编码转换。函数如下

'================================================== '函 数 名: YuZhe_UrlEncode

'功 能: 将指定字符进行指定格式进行编码 '参 数: iStrCode 目标字符

' iPageCode 指定编码 65001-UTF-8或936-GB2312

'================================================== Function YuZhe_UrlEncode(iStrCode, iPageCode) Dim StrUrlEncode

StrUrlEncode = \初始化变量

If iPageCode <> SetPageCode Then '如果指定要编码的类型与当前页面编码不一至,则临时设置处理该函数时的页面编码类型 Session.CodePage = iPageCode

StrUrlEncode = Server.UrlEncode(iStrCode)

Session.CodePage = SetPageCode '还原页面编码为默认 Else

StrUrlEncode = Server.UrlEncode(iStrCode) End If

YuZhe_UrlEncode = StrUrlEncode End Function

3、在asp获取淘宝客数据的时候我们使用的是httpget方式获取。这个比较简单我直接提供函数了。

'============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(\P.2.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

End Function dim gXmlHttpObj

Function getRemoteContent(Byval returnType) '组参

url=strGetUrl&createStrParam()

if not isObject(gXmlHttpObj) then:set gXmlHttpObj=tryXmlHttp():end if gXmlHttpObj.open \On error resume next gXmlHttpObj.send()

if err.number = -2147012894 then dim des

select case gXmlHttpObj.readyState Case 1

des=\\Case 2:des=\Case 3:des=\Case else:des=\end select

htm = htm& gXmlHttpVer&\\

\EE;\

\0;的服务商\response.end else

select case returnType case \

getRemoteContent=gXmlHttpObj.responseText case \

getRemoteContent=gXmlHttpObj.responseBody end select end if End Function

好了,今天的内容就到这里了。整理上面的三个函数以后了解一下签名的生成方式。明天我们进入签名程序

又是一天的开始,今天大家要打起精神来看了,api的签名是个难点。很多站长都是在这里出错的。今天我来带大家一起研究下签名函数。 首先我们来看一下开放平台给的签名说明:

调用接口(API)时需要对请求参数进行签名验证,TOP服务器也会对该请求参数进行验证是否合法的。根据参数名称将你的所有请求参数按照字母先后顺序排序:key + value .... key + value对除签名和图片外的所有请求参数按key做的升序排列, value无需编码。例如:将foo=1,bar=2,baz=3 排序为bar=2,baz=3,foo=1参数名和参数值链接后,得到拼装字符串bar2baz3foo1,将secretcode同时拼接到参数字符串头、尾部进行md5加密后,再转化成大写,格式是:byte2hex (md5(secretkey1value1key2value2...secret))。 通过上面的说明我们知道其中有几个重要点: 1、 请求参数按照字母先后顺序 2、 请求参数按key做的升序排列 3、 参数名和参数值链接拼装为字符串 4、 value无需编码

5、 将secretcode同时拼接到参数字符串头、尾部进行md5加密后

6、 转化成大写

以上6点中第一点和第二点可以可以一起看。在php中使用的是数组的形式添加和排序,那么我们在这里也使用数组的形式来做,这样相对就简单了。有key有value,这是一个二维数组。如下:

TaoApiRecord=Array(\\\

\)

这个数组我已经添加几个系统级参数在里面,timestamp直接讨厌了函数Format_Time。在开发中我们的appkey一级nick或pid都是变化的,更多的是其他相关的参数需要添加如这个数组里面,那么如何添加呢?很简单写一个函数在数组中添加一项。函数如下: '数组中增增加

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

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

使用方法 :ArrayList \结果:

TaoApiRecord=Array(\\\

\“app_key=12345678\ ) ……

以此类推把我们需要的参数都加入到数组中。接下来就是对数组进行排序。通用简单的一个函数处理。如下:

'============数组冒泡排序===================== 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

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

TaoApiRecord=Array(“app_key=12345678\ \\

\\)

到了在这里,第一条第二条已经完成,现在开始拼装字符串,对数组进行解析按照要求参数名和参数值链接拼装为字符串需要如下函数: '按要求进行排序组织传递的参数

Function zzBokeOrder(ary) zzBokeOrder=\

MyArray = ArraySort(ary)

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

zzBokeOrder =zzBokeOrder&MyArray(I) End If Next End Function


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

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

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

马上注册会员

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