在做微信开发时候,经常要用到Access Token,官网提供的都是基于php写的,这个用asp写了,有需要可以直接复制去用,模板消息,jdk上传图片,客服消息等全需要这个:
'获取 access_token
Public Function Get_Access_Token()
sCode = Request("code")
If sCode ="" And Session("access_token")="" Then
Response.Redirect(GetAuthorization_Code)
Else
If DateDiff("s",Now,Session("access_token_expires"))> 0 Then
Exit Function
End If
End If
Dim url, params,Temp
Url="https://api.weixin.qq.com/sns/oauth2/access_token?"
params = "appid="&s_APPID
params = params & "&secret=" & s_APPSECRET
params = params & "&code=" & sCode
params = params & "&grant_type=authorization_code"
url = Url & params
Temp=RequestUrl(url,"GET","")
'Die Temp
If CheckData(Temp,"access_token") = True Then
set obj = getjson(Temp)
if isobject(obj) Then
Session("access_token") = obj.access_token
Session("access_token_expires") = DateAdd("s",obj.expires_in,Now)
Session("openid") = obj.openid
End If
set obj = Nothing
Else
Response.Write("Get_Access_Token()=>"&Temp)
Response.End()
End If
End Function
asp源码微信公众号发送客服消息原码asp写的程序
<%
url="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="&fff
body="{""touser"":""oOZeU0umT1gk9S3bGl50cc4qC0xU"",""msgtype"":""text"",""text"":{""content"":""新询价消息\n\n询价单位:
张先生(北京)\n询价时间:
"&now()&"\n产品名称:
求购一台锅炉要求安装保修\n需求数量:
1台\n\n
如果不想接收此询盘信息,请点击进入后,注意底部“信息开关”进入关闭接收询盘信息即可。""}}"
'发送纯文字body="{""touser"":""oOZeU0umT1gk9S3bGl50cc4qC0xU"",""msgtype"":""text"",""text"":{""content"":""本次登录的动态密码为:"&pwd&"(2分钟内有效)""}}"
'发送图文消息body="{""touser"":""oOZeU0umT1gk9S3bGl50cc4qC0xU"",""msgtype"":""link"",""link"":{""title"":""中国联通"",""description"":""中国电信"",""url"":""http://wx.tmwcd.com"",""thumb_url"":""http://wx.tmwcd.com/images/card.jpg""}}"
%>
获取微信公众号access_token源码asp写的源码
<%
Call Wx.C_A("wx_token")'调用函数,如果当前的token有效则不动,否则重新获取并写入缓存
Wx.Echo "Token:"&Application("wx_token")(0)'输出当前的token
Wx.Echo "有效期:"&Application("wx_token")(1)'输出token时效时间
%>