<% '接口信息 account="966120" accountpass="966120888" appkey="" access_token=GetAccess_token() 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wx248505bfbab6d0c1&corpsecret=2MCilqWYC0FWjOQ894sbb-s7Lb5sVH4HHuJgOsd9l1k '{"access_token":"2qs5HAae2cno2I4_WkFwTyMMbpI0k1q0IP74qNH4f9o52Lpmebnl5aJRkeiruCA5OPfNzA2X-6vpBqPPIoeIKA","expires_in":7200} 'appUrl="http://tvadmin.v.com.cn/ECERP/aa.asp" 'Post方法 Function PostBody(appUrl,args1) Set https = Server.CreateObject("Msxml2.ServerXMLHTTP") 'Set https = Server.CreateObject("MSXML2.XMLHTTP") With https .Open "Post", appUrl, False .setRequestHeader "Content-Type","multipart/form-data" .Send args1 PostBody = .ResponseBody End With PostBody = BytesToBstr(PostBody,"utf-8") Set https = Nothing End Function 'Get方法 Function GetBody(appUrl,Origin) Set https = Server.CreateObject("Msxml2.ServerXMLHTTP") With https .Open "GET", appUrl&"?"&Origin, False .setRequestHeader "Content-Type","application/x-www-form-urlencoded" .Send "" GetBody = .ResponseBody End With GetBody = BytesToBstr(GetBody,"utf-8") Set https = Nothing End Function '获取access_token Function GetAccess_token() access_tokenID=4039 '对应数据库ID Set rs = Server.CreateObject("ADODB.Recordset") sql="select vtext,vMono from dictionary where id="&access_tokenID rs.open sql,objConn,1,1 access_token=rs("vtext") access_token_time=cdate(rs("vMono")) rs.close() If DateDiff("s",access_token_time,now())>0 then '获取新的access_token url="http://api.gpsoo.net/1/auth/access_token" '//定义要获取源代码的网址,一般是通过变量传递过来 time1=ToUnixTime(now(),0) signature=access_tokenMd5(accountpass, time1) Origin="account="&account&"&time="&time1&"&signature="&signature HTMLCODE= GetBody(url,Origin) 'Response.Write HTMLCODE access_token=replace(replace(HTMLCODE,"{""access_token"":""",""),""",""expires_in"":7200,""ret"":0,""msg"":""""}","") access_token_time=DateAdd("s",7200,now()) '写入数据库 sql="update dictionary set vtext='"&access_token&"',vMono='"&access_token_time&"' where id="&access_tokenID 'Response.Write sql objConn.Execute sql End if GetAccess_token = access_token End Function '返回结果写入数据库 Private Function API_JsonSql(method,HTMLCODE,reserve) sql="Insert into API_Json (method,Json,reserve) values ('"&method&"','"&HTMLCODE&"','"&reserve&"')" objConn.Execute sql Set rs = Server.CreateObject("ADODB.Recordset") sql="select id from API_Json where method='"&method&"' and is_Json=0 order by id desc" rs.open sql,objConn,1,1 if not rs.Eof then JsonID=rs("id") else JsonID="" end if rs.close() API_JsonSql=JsonID End Function Function BytesToBstr(body,Cset) '飘易:转换GB2312 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 Private Function BuildRequestMysign(sParaSort) '获得签名结果 key = AppSecret sign_type = "MD5" 'sParaSort="{""appkey"":"""&appKey&""",""sessionkey"":"""&sessionKey&""","&sParaSort&"}" input_charset="utf-8" BuildRequestMysign = Md5Sign(sParaSort,key,input_charset) End Function 'UNIX时间戳 Function ToUnixTime(strTime, intTimeZone) If IsEmpty(strTime) or Not IsDate(strTime) Then strTime = Now If IsEmpty(intTimeZone) or Not isNumeric(intTimeZone) Then intTimeZone = 0 ToUnixTime = DateAdd("h",-intTimeZone,strTime) ToUnixTime = DateDiff("s","1970-1-1 0:0:0", ToUnixTime) End Function '获取access_token_md5 Function access_tokenMd5(pass, time1) input_charset="utf-8" prestr = md5(pass,input_charset)&time1 access_tokenMd5 = md5(prestr,input_charset) End Function '输入参数 'method="gy.erp.vip.get" 'args1="""method"":"""&method&""",""page_no"":""1"",""page_size"":""10"",""name"":""李欣""" '签名 'key = secret 'sign_type = "MD5" 'sParaSort="{""appkey"":"""&appKey&""",""sessionkey"":"""&sessionKey&""","&args1&"}" 'input_charset="utf-8" 'sign1 = UCase(BuildRequestMysign(sParaSort)) 'sign1 = UCase(md5(key&sParaSort&key)) 'Response.Write "{""access_token"":""sV2v8S3qm9jeEyUUSD166ftctmvzbH9bZANj42bI1mMMnh1JNRpuCxWuKo-KATyhfmOZI181i1U7PH0ZeU1rXVZUoFJRNnUkp0RPYrbLdAw"",""expires_in"":7200}" %>