新一代Asp调用API示例

<% '' 接口参数 Dim userID,userEmail,userPwd,apiAction, res userID = 10000 userEmail = "demo@demo.com" userPwd = "123456" '' 接口动作 apiAction = "Domain.Register" '以数组方式存储关键字和对应值 Dim aData '' ********************************注册域名演示代码******************************** apiAction = "Domain.Register" '' 域名信息 aData = Array(_ "r_organization", "张三公司",_ "r_organization1", "ZhangSanCompany",_ "r_manager", "张三",_ "r_industry", "S16",_ "r_name", "张三",_ "r_name1", "ZhangSan",_ "r_country", "CN",_ "r_province", "广东",_ "r_province1", "GuangDong",_ "r_city", "广州",_ "r_city1", "GuangZhou",_ "r_street", "广州某某路某某街某某号",_ "r_street1", "No.xxx, xxx Jie, xxx LU, GuangZhou",_ "r_postcode", "510000",_ "r_phone", "+86.02088881234",_ "r_phone_ext", "123",_ "r_fax", "+86.02088881234",_ "r_fax_ext", "",_ "r_email", "demo@demodomain.com",_ "a_organization", "张三公司",_ "a_organization1", "ZhangSanCompany",_ "a_manager", "张三",_ "a_industry", "S16",_ "a_name", "张三",_ "a_name1", "ZhangSan",_ "a_country", "CN",_ "a_province", "广东",_ "a_province1", "GuangDong",_ "a_city", "广州",_ "a_city1", "GuangZhou",_ "a_street", "广州某某路某某街某某号",_ "a_street1", "No.xxx, xxx Jie, xxx LU, GuangZhou",_ "a_postcode", "510000",_ "a_phone", "+86.02088881234",_ "a_phone_ext", "123",_ "a_fax", "+86.02088881234",_ "a_fax_ext", "",_ "a_email", "demo@demodomain.com",_ "t_organization", "张三公司",_ "t_organization1", "ZhangSanCompany",_ "t_manager", "张三",_ "t_industry", "S16",_ "t_name", "张三",_ "t_name1", "ZhangSan",_ "t_country", "CN",_ "t_province", "广东",_ "t_province1", "GuangDong",_ "t_city", "广州",_ "t_city1", "GuangZhou",_ "t_street", "广州某某路某某街某某号",_ "t_street1", "No.xxx, xxx Jie, xxx LU, GuangZhou",_ "t_postcode", "510000",_ "t_phone", "+86.02088881234",_ "t_phone_ext", "123",_ "t_fax", "+86.02088881234",_ "t_fax_ext", "",_ "t_email", "demo@demodomain.com",_ "b_organization", "张三公司",_ "b_organization1", "ZhangSanCompany",_ "b_manager", "张三",_ "b_industry", "S16",_ "b_name", "张三",_ "b_name1", "ZhangSan",_ "b_country", "CN",_ "b_province", "广东",_ "b_province1", "GuangDong",_ "b_city", "广州",_ "b_city1", "GuangZhou",_ "b_street", "广州某某路某某街某某号",_ "b_street1", "No.xxx, xxx Jie, xxx LU, GuangZhou",_ "b_postcode", "510000",_ "b_phone", "+86.02088881234",_ "b_phone_ext", "123",_ "b_fax", "+86.02088881234",_ "b_fax_ext", "",_ "b_email", "demo@demodomain.com",_ "dns1", "",_ "dns2", "",_ "dns3", "",_ "dns4", "",_ "domain", "testdemo.com",_ "year", "1",_ "tld", ".com",_ "lang", "ENG",_ "encoding", "ASCII"_ ) '域名 ' tld 代表域名后缀，如"testdemo.com"则为".com"， "testdemo.net"则为".net"， "中文域名.中国"则为".中国" ' 英文域名，lang/encoding分别对应 EN G /ASCII ' 中文域名，lang/encoding分别对应 CHI / GBK '' ********************************查询域名演示代码******************************** 'apiAction = "Domain.Whois" 'aData = Array(_ ' "domain", "testdemo.com",_ ' "year", "1",_ ' "tld", ".com",_ ' "lang", "ENG",_ ' "encoding", "ASCII"_ ') res = doPost(aData, userID, userEmail, userPwd, apiAction) Response.Write res '' 接口返回字符以\t分隔，请自行根据结果编写相应代码 '-----args 包含关键字和对应值的数组 '-----userid 用户id '-----email 用户email '-----password 用户API接口密码(非平台登陆密码) '-----action 调用的动作 function doPost(args, userid, email, password, action) 'api地址 Dim strPostToUrl strPostToUrl = "http://www.gzidc.com/api.php" dim http,postData,ptime,Result dim i,aLen aLen = UBound(args) Dim vNow,vYear,vMonth,vDay,vHour,vMinute,vSecond vNow = Now vYear = Year(vNow) vMonth = Month(vNow) if vMonth<10 then vMonth="0" & vMonth vDay = Day(vNow) if vDay<10 then vDay="0" & vDay vHour = Hour(vNow) if vHour<10 then vHour="0" & vHour vMinute = Minute(vNow) if vMinute<10 then vMinute="0" & vMinute vSecond = Second(vNow) if vSecond<10 then vSecond="0" & vSecond ptime = vYear & vMonth & vDay & vHour & vMinute & vSecond postData = "c_vtime="&ptime postData = postData & "&c_agentid="&userid postData = postData & "&c_action="&action postData = postData & "&c_email="&email postData = postData & "&c_validatestr="& md5(userid&password&email&ptime) '构造要Post的字符串 '参数需要用urlencode进行URL编码 For i=0 To aLen-1 postData = postData & "&" & args(i) & "=" & Server.URLEncode(args(i+1)) i = i + 1 Next '构造post字符串完毕 'response.write postData set http = Server.CreateObject("MSXML2.XMLHTTP") '以异步方式发送数据 http.open "POST",strPostToUrl,false http.setRequestHeader "Content-Type","application/x-www-form-urlencoded" http.send(postData) 'Result为api接口的响应信息 'responseBody： 结果返回为无符号整数数组。 'responseStream： 结果返回为IStream流。 'responseText ： 结果返回为字符串。 'responseXML： 结果返回为XML格式数据。 'Result = http.ResponseText '' 如果出现返回中文乱码，可以尝试换为下面这段代码 Result = BytesToBstr(http.responseBody, "GBK") set http = Nothing doPost = Result 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 %>