<!--#include virtual="/inc/odbc1.asp"-->
|
<%
|
'接口信息
|
corpid="wx248505bfbab6d0c1"
|
corpsecret="tdud7WVJrd4nuslafQP34xqYVcoaRmIU919C3VH4QHo"
|
|
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 PBrs = Server.CreateObject("ADODB.Recordset")
|
sql="select id from API_Json where DATEDIFF (ss,Json_time,GETDATE())<=30 and Json='"&args1&"'"
|
PBrs.open sql,objConn,1,1
|
If PBrs.Eof Then
|
Set https = Server.CreateObject("Msxml2.ServerXMLHTTP")
|
|
'Set https = Server.CreateObject("MSXML2.XMLHTTP")
|
With https
|
.Open "Post", appUrl, False
|
.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
|
.Send args1
|
PostBody = .ResponseBody
|
End With
|
PostBody = BytesToBstr(PostBody,"utf-8")
|
JsonID = API_JsonSql(appUrl,args1,reserve)
|
Set https = Nothing
|
End If
|
PBrs.close()
|
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=1 '对应数据库ID
|
corpid="wx248505bfbab6d0c1"
|
corpsecret="2MCilqWYC0FWjOQ894sbb-s7Lb5sVH4HHuJgOsd9l1k"
|
Set rstoken = Server.CreateObject("ADODB.Recordset")
|
sql="select vtext,vMono from dictionary where id="&access_tokenID
|
rstoken.open sql,objConn,1,1
|
access_token=rstoken("vtext")
|
access_token_time=cdate(rstoken("vMono"))
|
rstoken.close()
|
If DateDiff("s",access_token_time,now())>0 then
|
'获取新的access_token
|
url="https://qyapi.weixin.qq.com/cgi-bin/gettoken" '//定义要获取源代码的网址,一般是通过变量传递过来
|
Origin="corpid="&corpid&"&corpsecret="&corpsecret
|
HTMLCODE= GetBody(url,Origin)
|
'Response.Write url&"?"&Origin
|
str="["&HTMLCODE&"]"
|
set obj = getjson(str)
|
access_token = obj.get(0).access_token
|
expires_in = obj.get(0).expires_in
|
'access_token=replace(replace(HTMLCODE,"{""access_token"":""",""),""",""expires_in"":7200}","")
|
access_token_time=DateAdd("s",500,now())
|
'写入数据库
|
sql="update dictionary set vtext='"&access_token&"',vMono='"&access_token_time&"' where id="&access_tokenID
|
|
objConn.Execute sql
|
End if
|
GetAccess_token = access_token
|
End Function
|
|
'强行重新获取access_token和jsapi_ticket(调度分派)
|
Function GetAccess_token_New()
|
access_tokenID=1 '对应数据库ID
|
corpid="wx248505bfbab6d0c1"
|
corpsecret="2MCilqWYC0FWjOQ894sbb-s7Lb5sVH4HHuJgOsd9l1k"
|
'获取新的access_token
|
url="https://qyapi.weixin.qq.com/cgi-bin/gettoken" '//定义要获取源代码的网址,一般是通过变量传递过来
|
Origin="corpid="&corpid&"&corpsecret="&corpsecret
|
HTMLCODE= GetBody(url,Origin)
|
str="["&HTMLCODE&"]"
|
set obj = getjson(str)
|
access_token = obj.get(0).access_token
|
expires_in = obj.get(0).expires_in
|
'access_token=replace(replace(HTMLCODE,"{""access_token"":""",""),""",""expires_in"":7200}","")
|
access_token_time=DateAdd("s",500,now())
|
'写入数据库
|
sql="update dictionary set vtext='"&access_token&"',vMono='"&access_token_time&"' where id="&access_tokenID
|
objConn.Execute sql
|
|
'获取新的jsapi_ticket
|
jsapi_ticketID=4036 '对应数据库ID
|
url="https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket" '//定义要获取源代码的网址,一般是通过变量传递过来
|
Origin="access_token="&access_token
|
HTMLCODE= GetBody(url,Origin)
|
str="["&HTMLCODE&"]"
|
set obj = getjson(str)
|
jsapi_ticket = obj.get(0).ticket
|
expires_in = obj.get(0).expires_in
|
jsapi_ticket_time=DateAdd("s",500,now())
|
'access_token=replace(replace(HTMLCODE,"{""access_token"":""",""),""",""expires_in"":7200}","")
|
access_token_time=DateAdd("s",500,now())
|
'写入数据库
|
sql="update dictionary set vtext='"&jsapi_ticket&"',vMono='"&jsapi_ticket_time&"' where id="&jsapi_ticketID
|
objConn.Execute sql
|
|
GetAccess_token_New = access_token
|
End Function
|
|
'获取jsapi_ticket
|
Function Getjsapi_ticket()
|
jsapi_ticketID=4036 '对应数据库ID
|
Set rstoken = Server.CreateObject("ADODB.Recordset")
|
sql="select vtext,vMono from dictionary where id="&jsapi_ticketID
|
rstoken.open sql,objConn,1,1
|
jsapi_ticket=rstoken("vtext")
|
jsapi_ticket_time=cdate(rstoken("vMono"))
|
rstoken.close()
|
If DateDiff("s",jsapi_ticket_time,now())>0 then
|
'获取新的jsapi_ticket
|
url="https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket" '//定义要获取源代码的网址,一般是通过变量传递过来
|
Origin="access_token="&access_token
|
HTMLCODE= GetBody(url,Origin)
|
jsapi_ticket=replace(replace(HTMLCODE,"{""errcode"":0,""errmsg"":""ok"",""ticket"":""",""),""",""expires_in"":7200}","")
|
jsapi_ticket_time=DateAdd("s",500,now())
|
'写入数据库
|
sql="update dictionary set vtext='"&jsapi_ticket&"',vMono='"&jsapi_ticket_time&"' where id="&jsapi_ticketID
|
objConn.Execute sql
|
End if
|
Getjsapi_ticket = jsapi_ticket
|
End Function
|
|
'获取access_token_1000004(合作报表)
|
Function GetAccess_token_1000004()
|
corpid="wx248505bfbab6d0c1"
|
corpsecret="6fuEHzsvx0KGuZyjoDic9W1YNsbOzWP65_rj3s3gm-E"
|
access_tokenID=5698 '对应数据库ID
|
Set rstoken = Server.CreateObject("ADODB.Recordset")
|
sql="select vtext,vMono from dictionary where id="&access_tokenID
|
rstoken.open sql,objConn,1,1
|
access_token=rstoken("vtext")
|
access_token_time=cdate(rstoken("vMono"))
|
rstoken.close()
|
If DateDiff("s",access_token_time,now())>0 then
|
'获取新的access_token
|
url="https://qyapi.weixin.qq.com/cgi-bin/gettoken" '//定义要获取源代码的网址,一般是通过变量传递过来
|
Origin="corpid="&corpid&"&corpsecret="&corpsecret
|
HTMLCODE= GetBody(url,Origin)
|
str="["&HTMLCODE&"]"
|
set obj = getjson(str)
|
access_token = obj.get(0).access_token
|
expires_in = obj.get(0).expires_in
|
'access_token=replace(replace(HTMLCODE,"{""access_token"":""",""),""",""expires_in"":7200}","")
|
access_token_time=DateAdd("s",500,now())
|
'写入数据库
|
sql="update dictionary set vtext='"&access_token&"',vMono='"&access_token_time&"' where id="&access_tokenID
|
objConn.Execute sql
|
End if
|
GetAccess_token_1000004 = access_token
|
End Function
|
|
'获取access_token(通讯录同步专用 https://work.weixin.qq.com/wework_admin/frame#apps/contactsApi)
|
Function GetAccess_token_contactsApi()
|
corpid="wx248505bfbab6d0c1"
|
corpsecret="TjLL-dIOllJ_-WeF8N90DVzWn02vva4Xuf3PlytgDSo"
|
access_tokenID=6557 '对应数据库ID
|
Set rstoken = Server.CreateObject("ADODB.Recordset")
|
sql="select vtext,vMono from dictionary where id="&access_tokenID
|
rstoken.open sql,objConn,1,1
|
access_token=rstoken("vtext")
|
access_token_time=cdate(rstoken("vMono"))
|
rstoken.close()
|
If DateDiff("s",access_token_time,now())>0 then
|
'获取新的access_token
|
url="https://qyapi.weixin.qq.com/cgi-bin/gettoken" '//定义要获取源代码的网址,一般是通过变量传递过来
|
Origin="corpid="&corpid&"&corpsecret="&corpsecret
|
HTMLCODE= GetBody(url,Origin)
|
'Response.Write url&"?"&Origin
|
str="["&HTMLCODE&"]"
|
set obj = getjson(str)
|
access_token = obj.get(0).access_token
|
expires_in = obj.get(0).expires_in
|
'access_token=replace(replace(HTMLCODE,"{""access_token"":""",""),""",""expires_in"":7200}","")
|
access_token_time=DateAdd("s",500,now())
|
'写入数据库
|
sql="update dictionary set vtext='"&access_token&"',vMono='"&access_token_time&"' where id="&access_tokenID
|
objConn.Execute sql
|
End if
|
GetAccess_token_contactsApi = 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 rsAPI = Server.CreateObject("ADODB.Recordset")
|
sql="select id from API_Json where method='"&method&"' and is_Json=0 order by id desc"
|
rsAPI.open sql,objConn,1,1
|
if not rsAPI.Eof then
|
JsonID=rsAPI("id")
|
else
|
JsonID=""
|
end if
|
rsAPI.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
|
|
'输入参数
|
'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}"
|
%>
|
|