<!--#include file="config.asp"-->
<%
response.Charset="utf-8"
if session("state")="" or request.QueryString("state")<>session("state") then
	Response.Write "登录出错，非法操作！"
	Response.End()
end if
session("state")=""
Set MyOAuth = OAUTH20(appid,appkey,url_callback)
Ret = MyOAuth.getAccessToken("https://graph.qq.com/oauth2.0/token",request.QueryString("code"))
if left(lcase(ret),8)="callback" then
	Set Info = GetJSON(Ret)
	if Info.mo__ then
		Response.Write "登录出错：" & Info.error & "=>" & Info.error_description
	else
		Response.Write "登录出错：" & Info.desc
	end if
else
	set H = jo.HashTable()
	H.FromRequest 2,Ret
	if H.Items("access_token")<>"" then
		Ret = MyOAuth.SendData("https://graph.qq.com/oauth2.0/me","GET","access_token=" & H.Items("access_token") ,"text")
		Set Info = GetJSON(Ret)
		if Info.mo__ then
			Response.Write Info.client_id & "=>" & Info.openid & "<br />"
			session("openid") = Info.openid
			'https://graph.qq.com/user/get_user_info
			
			'以上为oauth2.0相关，下面是API相关
			'获取用户信息
			Set UserInfo = OAUTH20(appid,appkey,url_callback)
			UserInfo.Set "openid",Info.openid
			UserInfo.Set "oauth_consumer_key",appid
			UserInfo.Set "access_token",H.Items("access_token")
			Ret = UserInfo.SendData("https://graph.qq.com/user/get_user_info","GET",UserInfo.APISTring("utf-8","=","&") ,"text")
			Set Info = GetJSON(Ret)
			if Info.mo__ and Info.ret=0 then
				Response.Write "<img src=""" & Info.figureurl & """ />" & Info.nickname
				session("openidnn") = Info.nickname
			else
				Response.Write "登录出错：" & Info.desc
			end if
		else
			Response.Write "登录出错：" & Info.desc
		end if
	else
		Response.Write "登录出错"
	end if
end If
response.Redirect "/LstUserqq.asp"
%>