<!--#include file="../../MainClass.asp"-->
<!--#include file="../inc.asp"-->
<%
dim rArr,SqlNowString,Fun:rArr=requestArrey("",0)
Set Fun=server.CreateObject("inc_inc_MainClass.CommonFun")
SqlNowString=fun.ifthen(databaseType=0,"now()","getdate()")
dim xmlobj,API_SinaEnable,API_SinaId,API_SinaKey,API_SinaCallBack
SET xmlobj=server.CreateObject("inc_inc_MainClass.xml")
xmlobj.load "../api.config","xmlfile"
API_SinaEnable=xmlobj.getAttributes("rs:data/z:row","API_SinaEnable",0)
API_SinaId=xmlobj.getAttributes("rs:data/z:row","API_SinaId",0)
API_SinaKey=xmlobj.getAttributes("rs:data/z:row","api_qqappkey",0)
API_SinaCallBack=xmlobj.getAttributes("rs:data/z:row","API_SinaCallBack",0)
Set xmlobj=Nothing
If cbool(API_SinaEnable)=false Then conn.die"'对不起，本站没有开启新浪微博登录功能!"
Select case rArr(0)
	case "SinaBind":SinaBind
 	case else : main
End Select
sub SinaBind
  dim ret,msg,nickname,figureurl,sex,rs
  dim resultxml:resultxml=get_user_info(2,conn.rCookie("access_token"),conn.rCookie("openid"))
  dim obj:set obj = getjson(resultxml)
  if instr(resultxml,"error")<>0 then
	if isobject(obj) Then
		conn.echo "<h3>error:</h3>" & obj.error
		conn.echo "<h3>error_code:</h3>" & obj.error_code
	else
	  conn.die "授权失效！"
	end if
  else
	if not fun.isnul(resultxml) then
	  if isobject(obj) Then
		nickname=obj.screen_name
		figureurl=obj.profile_image_url
		sex=obj.gender
		if sex="m" then 
		 sex="男" 
		elseif sex="f" then
		 sex="女"
		else
		 sex="未如"
		end if
	  End If
	  set obj=nothing
	end if
	set rs=conn.db("select top 1 {pre}name,{pre}password from {pre}user where {pre}sinaid='" & conn.rCookie("openid") & "'","execute")
	if rs.eof and rs.bof then
	   Call DoBind("用新浪微博账号登录成功",nickname,figureurl,sex,"sina",conn.rCookie("openid"),conn.rCookie("access_token"))
	else
	   Call DoLogin(rs(0),rs(1))
	end if
	set rs=nothing
end if
end sub
sub main
  response.redirect "https://api.weibo.com/oauth2/authorize?client_id=" & Api_SinaId &"&redirect_uri="&server.URLEncode(api_sinaCallBack)&"&response_type=code"
end sub
Function requestArrey(Byval url,Byval ArrI)'返回URl以"-"组成的数组.(1)声名数组的大小
  dim paras,i,num,parasArr,urlnum
  if url="" then url=request.QueryString
  urlnum=InstrRev(url,fileSuffix)
  if urlnum<>0 then paras=left(url,urlnum-1) else paras=url
  parasArr=split(paras,"/")
  num=ubound(parasArr)
  redim parasArray(ArrI)
  for i=0 to ArrI
	if i<=num then
	  parasArray(i)=parasArr(i)
	End if
  next
  requestArrey=parasArray
End Function
%>