asp网站微信登录源码

<%
'==================================
'=类 名 称:微信登录
'=功 能:微信登录 For ASP
'=作 者:79657181
'=微 信: 18611436777
'=日 期:2014-3
'==================================
'转载时请保留以上内容!!
Class WxAPI
Private APPID
Private APPSECRET
Private CALLBACK_URL
Private SCOPE

Private Sub Class_Initialize      
    APPID = weixin_Appid'APP ID
    APPSECRET = weixin_Appsecret'APP KEY
    CALLBACK_URL = anco_site_http&"/reg/user2.asp"'REDIRECT_URI
	SCOPE ="snsapi_userinfo" '授权项snsapi_userinfo,snsapi_base
                                            
End Sub
'Microsoft.XMLHTTP
'Get方法请求url,获取请求内容

Private Function RequestUrl(url)
Set XmlObj = Server.CreateObject(“Microsoft.XMLHTTP”)
XmlObj.open “GET”,url, false
XmlObj.send
If XmlObj.Readystate=4 Then
RequestUrl = XmlObj.responseText
Else
Response.Write(“xmlhttp请求超时!”)
Response.End()
End If
Set XmlObj = nothing
End Function

Private Function CheckData(data,str)
	If Instr(data,str)>0 Then
	   CheckData = True
	Else
	   CheckData = False
	End If
End Function


'生成登录地址
Public Function GetAuthorization_Code()
	Dim url, params
	url = "https://open.weixin.qq.com/connect/oauth2/authorize"
	params = "appid="&APPID
	params = params & "&redirect_uri=" & server.URLEncode(CALLBACK_URL)
	params = params & "&response_type=code"
	params = params & "&scope="&SCOPE
	params = params & "&state=123#wechat_redirect"
	url = url & "?" & params
	GetAuthorization_Code = (url)
End Function


'获取 access_token
Public Function GetAccess_Token(sCode)
	Dim url, params,Temp
	Url="https://api.weixin.qq.com/sns/oauth2/access_token"
	params = "appid="&APPID
	params = params & "&secret=" & APPSECRET
	params = params & "&code=" & sCode
	params = params & "&grant_type=authorization_code"
	url = Url & "?" & params
	Temp=RequestUrl(url)
	If CheckData(Temp,"access_token") = True Then
	   set obj = getjson(Temp)
	   if isobject(obj) Then
	       GetAccess_Token = Array(obj.access_token,obj.openid)
	   End If
	  set obj = Nothing
	Else
	   Response.Write("获取 access_token 时发生错误,错误信息:"&Temp) 
	   Response.End()
	End If
End Function

'检测是否合法登录!
Public Function CheckLogin()
	Dim Code,mState
	Session("Code")=Trim(Request.QueryString("code"))
	If Code<>"" Then
		CheckLogin = True
	Else
		CheckLogin = False
	End If
End Function

'获取用户信息,得到一个json格式的字符串
Public Function GetUserInfo()
	Dim url, params, result
	url = "https://api.weixin.qq.com/sns/userinfo?"
	params = params & "&access_token=" & Access_Token
	params = params & "&openid=" & Openid
	params = params & "&lang=zh_CN"
	url = url & "?" & params
	Temp = RequestUrl(url)
	If CheckData(Temp,"nickname") = False Then
	    set obj = getjson(Temp)
	   if isobject(obj) Then
	       ret = obj.errcode
		   msg = obj.errmsg
	   End If
	  set obj = Nothing
	   Response.Write("获取用户信息时发生错误,错误代码:"&ret&" , 错误描述:"&msg) 
	   Response.End()
	End If
	GetUserInfo = Temp
End Function



'获取用户名字,性别,从json字符串里截取相关字符
Public Function GetUserName(json)
    Dim nickname,sex,headimgurl,obj
	set obj = getjson(json)
	   if isobject(obj) Then
	       nickname = obj.nickname
		   sex = obj.sex
		   headimgurl = obj.headimgurl
	   End If
	  set obj = Nothing
    GetUserName = Array(nickname,sex,headimgurl)
End Function

End Class
%>

你可能感兴趣的:(asp微信登陆)