'获取openid
set rs=server.CreateObject("adodb.recordset")
sql="select Appid,AppSecret from config"
rs.open sql,conn,1,1
Appid=rs("Appid")
AppSecret=rs("AppSecret")
rs.close
Set rs=nothing
url="https://api.weixin.qq.com/sns/oauth2/access_token?appid="&Appid&"&secret="&AppSecret&"&code="&code&"&grant_type=authorization_code"
method="GET":dataStr=""
set obj=jsonObjByUrl(url,method,dataStr)
OPENID=obj.openid
'判断token是否过期,没过期从数据库中读取,过期则重新获取token,此处如果需要可以保存refrashtoken用于刷新accesstoken
set rs=server.CreateObject("adodb.recordset")
sql="select openid,access_token,datediff('s',lasttime,now()) as minites from access_token where openid='"&OPENID&"'"
rs.open sql,conn,1,1
totalnum=rs.recordcount
minites=rs("minites")
token=rs("access_token")
rs.close
Set rs=nothing
If totalnum>0 And minites<7200 then
ACCESS_TOKEN=token
Else
url1="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="&Appid&"&secret="&AppSecret
set obj1=jsonObjByUrl(url1,method,dataStr)
ACCESS_TOKEN=obj1.access_token
If totalnum<=0 Then
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载