本文主要是介绍asp微信写的jssdk代码,很多朋友在网上找,今天贡献出来,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
想实现微信公众号的jssdk功能,如果你的代码是asp写的,那么有福音了,用下面的代码就行了:
<!--#include file="php_MD5.asp" -->
<!--#include file="JSON.asp" -->
<%
Set Rs = SqlHelper("Select * From [sys_config] Where ID=1","")
If Not Rs.Eof ThenAppId = Rs("AppID")AppSecret = Rs("appsecret")If Rs("access_token")<>"" And DateDiff("s",Now,Rs("access_token_expires"))>0 ThenSession("Token") = Rs("access_token")Session("Ticket") = Rs("ticket")ElseCall Get_Token()Call Get_Ticket()End If
End IfPrivate Function RequestUrl(url)Set XmlObj = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")XmlObj.open "GET",url, falseXmlObj.sendIf XmlObj.Readystate=4 ThenRequestUrl = XmlObj.responseTextElseResponse.Write("xmlhttp请求超时!") Response.End()End IfSet XmlObj = nothingEnd FunctionPublic Function MakeRandNum()RandomizeDim width : width = 6 '随机数长度,默认6位width = 10 ^ (width - 1)MakeRandNum = Int((width*10 - width) * Rnd() + width)End FunctionPublic Function MakeRandStr(intLength) Dim strSeed, seedLength, pos, Str, i strSeed = "abcdefghijklmnopqrstuvwxyz123456789" seedLength = Len(strSeed) Str = "" Randomize For i = 1 To intLength Str = Str + Mid(strSeed, Int(seedLength * Rnd) + 1, 1) Next MakeRandStr = Str End Function Public Function GetDateTime()Dim sTime,sResultsTime=now()sResult = year(sTime)&right("0" & month(sTime),2)&right("0" & day(sTime),2)&right("0" & hour(sTime),2)&right("0" & minute(sTime),2)&right("0" & second(sTime),2)GetDateTime = sResultEnd FunctionPublic Function Get_Token()Dim url, params,TempUrl="https://api.weixin.qq.com/cgi-bin/token?"params = "grant_type=client_credential"params = params & "&appid="&AppIdparams = params & "&secret="&AppSecreturl = Url & paramsTemp=RequestUrl(url)If CheckData(Temp,"access_token") = True Thenset obj = getjson(Temp)if isobject(obj) ThenSession("Token") = obj.access_tokenCall SqlHelper("Update [sys_config] set access_token=?,access_token_expires=? Where ID=1",Array(obj.access_token,DateAdd("s",obj.expires_in,Now)))End Ifset obj = NothingElseResponse.Write("获取 Token 时发生错误,错误信息:"&Temp) Response.End()End IfEnd FunctionPublic Function Get_Ticket()Dim url, params,TempUrl="https://api.weixin.qq.com/cgi-bin/ticket/getticket?"params = "access_token="&Session("Token")params = params & "&type=jsapi"url = Url & paramsTemp=RequestUrl(url)If CheckData(Temp,"ticket") = True Thenset obj = getjson(Temp)if isobject(obj) ThenSession("Ticket") = obj.ticketCall SqlHelper("Update [sys_config] set ticket=? Where ID=1",Array(obj.ticket))End Ifset obj = NothingElseResponse.Write("获取 Ticket 时发生错误,错误信息:"&Temp) Response.End()End IfEnd FunctionFunction Get_Sign()Dim Str,urlurl = "http://"&request.ServerVariables("HTTP_HOST")&request.ServerVariables("URL")If Trim(Request.QueryString)<>"" Thenurl = url&"?"&Trim(Request.QueryString)End If Str = "jsapi_ticket="&Session("Ticket")&"&noncestr="&nonceStr&"×tamp="×tamp&"&url="&urlGet_Sign = SHA1(Str)End FunctionFunction CheckData(data,str)If Instr(data,str)>0 ThenCheckData = TrueElseCheckData = FalseEnd IfEnd Function
'保存图片 Function SaveRemoteFile(LocalFileName,RemoteFileUrl)SaveRemoteFile=Truedim Ads,Http,GetRemoteDataSet Http = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")With Http.Open "Get", RemoteFileUrl, False, "", "".SendIf .Readystate<>4 thenSaveRemoteFile=FalseExit FunctionEnd IfGetRemoteData = .ResponseBodyEnd WithSet Http = NothingSet Ads = Server.CreateObject("Adodb.Stream")With Ads.Type = 1.Open.Write GetRemoteData.SaveToFile server.MapPath(LocalFileName),2.Cancel().Close()End WithSet Ads=nothingEnd Function%>
重新发布
这篇关于asp微信写的jssdk代码,很多朋友在网上找,今天贡献出来的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!