%
'接口信息
If weixinID="" Then weixinID=1
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from GBR.dbo.weixinAPP where id="&weixinID
'Response.Write sql &"
"
rs.open sql,objConn,1,1
wx_Name = rs("wx_Name")
APPID = rs("APPID")
APPSECRET = rs("APPSECRET")
token = rs("token")
access_token = rs("access_tokenID")
access_token_time= rs("access_tokenTime")
jsapi_ticket = rs("jsapi_ticketID")
jsapi_ticket_time= rs("jsapi_ticketTime")
mch_id = rs("mch_id")
mch_key = rs("mch_key")
mch_customs = rs("mch_customs")
mch_customs_no = rs("mch_customs_no")
OriginalID=rs("OriginalID")
rs.close()
If InStr(jsapi_ticket,"40001")>0 Or InStr(access_token,"40001")>0 Then
access_token_time=now()-1
jsapi_ticket_time=now()-1
End If
'access_token_time="2016-10-1 10:00:00"
If weixinID="10" Then
access_token=GetAccess_token_qy(weixinID,access_token,access_token_time)
Else
access_token=GetAccess_token(weixinID,access_token,access_token_time)
End If
'--------------------------UNIX时间戳---------------------begin
'ToUnixTime(now(), +8)
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
'--------------------------UNIX时间戳---------------------end
'把UNIX时间戳转换为标准时间---------------------begin
Function FromUnixTime(intTime, intTimeZone)
If IsEmpty(intTime) or Not IsNumeric(intTime) Then
FromUnixTime = Now()
Exit Function
End If
If IsEmpty(intTime) or Not IsNumeric(intTimeZone) Then intTimeZone = 0
FromUnixTime = DateAdd("s", intTime, "1970-01-01 00:00:00")
FromUnixTime = DateAdd("h", intTimeZone, FromUnixTime)
End Function
'把UNIX时间戳转换为标准时间---------------------end
'获取access_token
Function GetAccess_token(weixinID,access_token,access_token_time)
If DateDiff("s",access_token_time,now())>0 Then
'获取新的access_token
url="https://api.weixin.qq.com/cgi-bin/token" '//定义要获取源代码的网址,一般是通过变量传递过来
Origin="grant_type=client_credential&appid="&APPID&"&secret="&APPSECRET
HTMLCODE= GetBody(url,Origin)
access_token=replace(HTMLCODE,"{""access_token"":""","")
access_token=Left(access_token,InStr(access_token,""",""")-1)
access_token_time=DateAdd("s",7000,now())
'写入数据库
sql="update GBR.dbo.weixinAPP set access_tokenID='"&access_token&"',access_tokenTime='"&access_token_time&"' where id="&weixinID
objConn.Execute sql
End if
GetAccess_token = access_token
End Function
'获取jsapi_ticket
Function Getjsapi_ticket(weixinID,jsapi_ticket,jsapi_ticket_time)
If DateDiff("s",jsapi_ticket_time,now())>0 then
'获取新的jsapi_ticket
url="https://api.weixin.qq.com/cgi-bin/ticket/getticket" '//定义要获取源代码的网址,一般是通过变量传递过来
Origin="access_token="&access_token&"&type=jsapi"
HTMLCODE= GetBody(url,Origin)
jsapi_ticket=replace(replace(HTMLCODE,"{""errcode"":0,""errmsg"":""ok"",""ticket"":""",""),""",""expires_in"":7200}","")
jsapi_ticket_time=DateAdd("s",7000,now())
'写入数据库
sql="update GBR.dbo.weixinAPP set jsapi_ticketID='"&jsapi_ticket&"',jsapi_ticketTime='"&jsapi_ticket_time&"' where id="&weixinID
objConn.Execute sql
End if
Getjsapi_ticket = jsapi_ticket
End Function
'获取企业号access_token
Function GetAccess_token_qy(weixinID,access_token,access_token_time)
If DateDiff("s",access_token_time,now())>0 Then
'获取新的access_token
url="https://qyapi.weixin.qq.com/cgi-bin/gettoken" '//定义要获取源代码的网址,一般是通过变量传递过来
Origin="corpid="&APPID&"&corpsecret="&APPSECRET
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_time=DateAdd("s",(expires_in-100),now())
'写入数据库
sql="update GBR.dbo.weixinAPP set access_tokenID='"&access_token&"',access_tokenTime='"&access_token_time&"' where id="&weixinID
objConn.Execute sql
End if
GetAccess_token_qy = access_token
End Function
'获取企业号jsapi_ticket
Function Getjsapi_ticket_qy(weixinID,jsapi_ticket,jsapi_ticket_time)
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)
If InStr(HTMLCODE,"""errmsg"":""ok""")>=1 Then
jsapi_ticket=replace(replace(HTMLCODE,"{""errcode"":0,""errmsg"":""ok"",""ticket"":""",""),""",""expires_in"":7200}","")
jsapi_ticket_time=DateAdd("s",7000,now())
'写入数据库
sql="update GBR.dbo.weixinAPP set jsapi_ticketID='"&jsapi_ticket&"',jsapi_ticketTime='"&jsapi_ticket_time&"' where id="&weixinID
objConn.Execute sql
End If
End if
Getjsapi_ticket_qy = jsapi_ticket
End Function
'获取用户OpenID
Function GetOpenID(code)
'获取OpenID
url="https://api.weixin.qq.com/sns/oauth2/access_token" '//定义要获取源代码的网址,一般是通过变量传递过来
Origin="appid="&APPID&"&secret="&APPSECRET&"&code="&code&"&grant_type=authorization_code"
HTMLCODE= GetBody(url,Origin)
If InStr(HTMLCODE,"""openid"":""")>0 then
OpenID=Mid(HTMLCODE,InStr(HTMLCODE,"""openid"":""")+10)
OpenID=Mid(OpenID,1,InStr(OpenID,""",""")-1)
Else
OpenID=""
End If
GetOpenID = OpenID
End Function
'获取用户OpenID2
Function GetOpenID2(code)
'获取OpenID
url="https://api.weixin.qq.com/sns/oauth2/access_token" '//定义要获取源代码的网址,一般是通过变量传递过来
Origin="appid="&APPID&"&secret="&APPSECRET&"&code="&code&"&grant_type=authorization_code"
HTMLCODE= GetBody(url,Origin)
GetOpenID2 = HTMLCODE
End Function
'获取用户OpenID_CX 小程序专用
Function GetOpenID_CX(code)
'获取OpenID
url="https://api.weixin.qq.com/sns/jscode2session" '//定义要获取源代码的网址,一般是通过变量传递过来
Origin="appid="&APPID&"&secret="&APPSECRET&"&js_code="&code&"&grant_type=authorization_code"
HTMLCODE= GetBody(url,Origin)
GetOpenID_CX = HTMLCODE
End Function
'获取code
Function GetCode(state)
redirectUrl = "http://"&Request.ServerVariables("SERVER_NAME")&Request.ServerVariables("URL")
state=state&"|N"
url="https://open.weixin.qq.com/connect/oauth2/authorize"
Origin="appid="&APPID&"&redirect_uri="&redirectUrl&"&response_type=code&scope=snsapi_base&state="&state&"#wechat_redirect"
Response.Redirect url&"?"&Origin
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
'Post方法
Function PostBody(appUrl,args1)
Set PBrs = Server.CreateObject("ADODB.Recordset")
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")
Set https = Nothing
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
'微信支付统一下单
Function PostXML(pUrl, pXml)
PostXML = ""
Dim https, ResponseBody
Set https = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
https.setOption(3) = "LOCAL_MACHINE\My\MMPay"
Dim xmlDoc
Set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.3.0")
xmlDoc.async = false
xmlDoc.loadXML pXml
With https
.Open "POST", pUrl, False
.setRequestHeader "Content-Type","application/xml;charset=UTF-8"
.Send xmlDoc 'pXml
PostXML = .ResponseText
End With
Set https = Nothing
End Function
%>