<!--#include file="config.asp"-->
<%	
''' EYCMS 支付宝登录处理
''' ==================================================================

	sub callback()
		dim is_success:is_success=eycms.enhtml(eycms.fget("is_success",0))
		dim notify_id:notify_id=eycms.enhtml(eycms.fget("notify_id",0))
		dim real_name:real_name=eycms.enhtml(eycms.fget("real_name",0))
		dim token:token=eycms.enhtml(eycms.fget("token",0))
		dim user_id:user_id=eycms.enhtml(eycms.fget("user_id",0))
		dim sign:sign=eycms.enhtml(eycms.fget("sign",0))

		if eycms.strlen(notify_id)=0 or eycms.strlen(real_name)=0 or eycms.strlen(token)=0 or eycms.strlen(user_id)=0 or eycms.strlen(sign)=0 then
			eycms.echo "非法参数传递，无法登录"
			exit sub
		end if
		dim states'检查远程状态
		states=eycms.gethttp("http://notify.alipay.com/trade/notify_query.do?partner="&alipay_appid&"&notify_id="&notify_id,"")
		dim thissign
		thissign=MD5_32("is_success="&is_success&"&notify_id="&notify_id&"&real_name="&real_name&"&token="&token&"&user_id="&user_id&alipay_appkey)
		if not(thissign=sign and states="true") then
			eycms.echo "登录验证失败，无法登录"
			exit sub
		else
			eycms.setsession "alipay_user_id",user_id
			dim gourl:gourl=eycms.loadsession("api_backurl")
			dim data:data=eycms.db.dbload(1,"n.userid,u.logintimes","ey_user_bind n left join ey_user u on n.userid=u.id","n.openid='"&user_id&"' and n.opentype='alipay'","")
			if ubound(data)<0 then
				eycms.setsession "api_backurl",""
				eycms.go "bind.asp?api_backurl="&gourl&"&nickname="&server.urlencode(real_name)
				exit sub
			else
				eycms.db.dbupdate "ey_user","id="&data(0,0)&"",array(array("logintimes",data(1,0)+1,0,0))
				eycms.resetuserinfo("u.id="&data(0,0)&"")
				eycms.setsession "alipay_token",""
				eycms.setsession "api_backurl",""
				if eycms.strlen(gourl)=0 then gourl=webroot
				eycms.go gourl
			end if
		end if
	end sub

	callback()
%>
