<!--#include file="../../MainClass.asp"-->
<!--#include file="../inc.asp"-->
<%
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_SinaKey",0)
API_SinaCallBack=xmlobj.getAttributes("rs:data/z:row","API_SinaCallBack",0)
Set xmlobj=Nothing
call sina_callback()
function sina_callback()
  if REQUEST("code")="" then conn.die "error access!"
  Dim token_url,result
  token_url = "https://api.weibo.com/oauth2/access_token"
  result = getRemoteContent(token_url,"client_id=" & API_SinaId &"&client_secret=" &API_SinaKey&"&grant_type=authorization_code&redirect_uri=" & server.URLEncode(API_SinaCallBack) &"&code="&CheckXSS(REQUEST("code")),"text","post")
	dim obj:set obj = getjson(result)
	if instr(result,"error")<>0 then
		if isobject(obj) Then
		  conn.echo "<h3>error:</h3>" & obj.error
		  conn.echo "<h3>error_code:</h3>" & obj.error_code
		  conn.echo "<h3>msg:</h3>" & obj.error_description
		End If
		set obj=nothing
		conn.die ""
	Else
	  if isobject(obj) Then
		dim arr:set arr=parse_str(result)
		conn.wCookie "access_token", obj.access_token
		conn.wCookie "openid", obj.uid
	 End If
	 set obj=nothing
  End If
End Function
response.write "<div style='margin-top:90px;color:#666;font-size:16px;text-align:center;'>正在登录中，请稍候！！！如果长时间没有反应请<a href=""index.asp?SinaBind"" style='color:red' target=""_blank"">点此跳转</a><script>top.location.href='index.asp?SinaBind';</"&"script>。</div>"
%>
<script language="javascript" type="text/javascript" runat="server">
function getjson(str){
  try{eval("var jsonStr=("+str+")");}
  catch(ex){var jsonStr=null;}
  return jsonStr;
}
</script>
