新一代Asp调用API示例

<% '' 接口参数 Dim userID,userEmail,userPwd,apiAction, res userID = "29393" userEmail = "995226433@qq.com" userPwd = "admin995226433" '' 接口动作 apiAction = "Domain.Register" '以字典方式存储关键字和对应值 Dim oDic Set oDic = Server.CreateObject("Scripting.Dictionary") '' ********************************注册域名演示代码******************************** apiAction = "Domain.Register" '所有人 oDic.Add "r_organization", "张三公司" oDic.Add "r_organization1", "ZhangSanCompany" oDic.Add "r_manager", "张三" oDic.Add "r_industry", "S16" oDic.Add "r_name", "张三" oDic.Add "r_name1", "ZhangSan" oDic.Add "r_country", "CN" oDic.Add "r_province", "广东" oDic.Add "r_province1", "GuangDong" oDic.Add "r_city", "广州" oDic.Add "r_city1", "GuangZhou" oDic.Add "r_street", "广州某某路某某街某某号" oDic.Add "r_street1", "No.xxx, xxx Jie, xxx LU, GuangZhou" oDic.Add "r_postcode", "510000" oDic.Add "r_phone", "+86.02088881234" oDic.Add "r_phone_ext", "123" oDic.Add "r_fax", "+86.02088881234" oDic.Add "r_fax_ext", "" oDic.Add "r_email", "demo@demodomain.com" '管理联系人 oDic.Add "a_organization", "张三公司" oDic.Add "a_organization1", "ZhangSanCompany" oDic.Add "a_manager", "张三" oDic.Add "a_industry", "S16" oDic.Add "a_name", "张三" oDic.Add "a_name1", "ZhangSan" oDic.Add "a_country", "CN" oDic.Add "a_province", "广东" oDic.Add "a_province1", "GuangDong" oDic.Add "a_city", "广州" oDic.Add "a_city1", "GuangZhou" oDic.Add "a_street", "广州某某路某某街某某号" oDic.Add "a_street1", "No.xxx, xxx Jie, xxx LU, GuangZhou" oDic.Add "a_postcode", "510000" oDic.Add "a_phone", "+86.02088881234" oDic.Add "a_phone_ext", "123" oDic.Add "a_fax", "+86.02088881234" oDic.Add "a_fax_ext", "" oDic.Add "a_email", "demo@demodomain.com" '技术联系人 oDic.Add "t_organization", "张三公司" oDic.Add "t_organization1", "ZhangSanCompany" oDic.Add "t_manager", "张三" oDic.Add "t_industry", "S16" oDic.Add "t_name", "张三" oDic.Add "t_name1", "ZhangSan" oDic.Add "t_country", "CN" oDic.Add "t_province", "广东" oDic.Add "t_province1", "GuangDong" oDic.Add "t_city", "广州" oDic.Add "t_city1", "GuangZhou" oDic.Add "t_street", "广州某某路某某街某某号" oDic.Add "t_street1", "No.xxx, xxx Jie, xxx LU, GuangZhou" oDic.Add "t_postcode", "510000" oDic.Add "t_phone", "+86.02088881234" oDic.Add "t_phone_ext", "123" oDic.Add "t_fax", "+86.02088881234" oDic.Add "t_fax_ext", "" oDic.Add "t_email", "demo@demodomain.com" '付费联系人 oDic.Add "b_organization", "张三公司" oDic.Add "b_organization1", "ZhangSanCompany" oDic.Add "b_manager", "张三" oDic.Add "b_industry", "S16" oDic.Add "b_name", "张三" oDic.Add "b_name1", "ZhangSan" oDic.Add "b_country", "CN" oDic.Add "b_province", "广东" oDic.Add "b_province1", "GuangDong" oDic.Add "b_city", "广州" oDic.Add "b_city1", "GuangZhou" oDic.Add "b_street", "广州某某路某某街某某号" oDic.Add "b_street1", "No.xxx, xxx Jie, xxx LU, GuangZhou" oDic.Add "b_postcode", "510000" oDic.Add "b_phone", "+86.02088881234" oDic.Add "b_phone_ext", "123" oDic.Add "b_fax", "+86.02088881234" oDic.Add "b_fax_ext", "" oDic.Add "b_email", "demo@demodomain.com" 'Name server 可不填，系统会默认为最新的DNS服务器 oDic.Add "dns1", "" oDic.Add "dns2", "" oDic.Add "dns3", "" oDic.Add "dns4", "" '域名 ' tld 代表域名后缀，如"testdemo.com"则为".com"， "testdemo.net"则为".net"， "中文域名.中国"则为".中国" ' 英文域名，lang/encoding分别对应 ENG / ASCII ' 中文域名，lang/encoding分别对应 CHI / GBK oDic.Add "domain", "testdemo.com" oDic.Add "year", "1" oDic.Add "tld", ".com" oDic.Add "lang", "ENG" oDic.Add "encoding", "ASCII" '' ********************************查询域名演示代码******************************** apiAction = "Domain.Whois" oDic.RemoveAll oDic.Add "domain", "huiguyunhaha.com" oDic.Add "year", "1" oDic.Add "tld", ".com" oDic.Add "lang", "ENG" oDic.Add "encoding", "ASCII" 'oDic.RemoveAll 'oDic.Add "domain", "新一代.中国" 'oDic.Add "year", "1" 'oDic.Add "tld", ".中国" 'oDic.Add "lang", "CHI" 'oDic.Add "encoding", "GBK" res = doPost(oDic, userID, userEmail, userPwd, apiAction) Response.Write res '' 接口返回字符以\t分隔，请自行根据结果编写相应代码 '-----args 包含关键字和对应值的Dictionary对象 '-----userid 用户id '-----email 用户email '-----password 用户密码 '-----action 调用的动作 function doPost(args, userid, email, password, action) 'api地址 Dim strPostToUrl strPostToUrl = "http://www.gzidc.com/api.php" Dim http,postData,ptime,Result 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) 'aKeys 键值 , aItems所有键值对 Dim aItems,aKeys,i aKeys = args.Keys aItems = args.Items '构造要Post的字符串 '参数需要用urlencode进行URL编码 For i=0 To args.Count-1 postData = postData & "&" & aKeys(i) & "=" & Server.URLEncode(aItems(i)) 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 %>