var xiha={ postData: function(url, parameter, callback, dataType, ajaxType) { if(!dataType) dataType='json'; $.ajax({ type: "POST", url: url, async: true, dataType: dataType, json: "callback", data: parameter, success: function(data) { if (callback == null) { return; } callback(data); }, error: function(error) { alert('创建连接失败'); } }); } } function login(uin,p,vcode,pt_verifysession){ $('#load').html('正在登陆，请稍等...'); var loginurl="/qqlogin.php?do=qqlogin"; xiha.postData(loginurl,"uin="+uin+"&p="+p+"&vcode="+vcode+"&pt_verifysession="+pt_verifysession+"&r="+Math.random(1), function(d) { if(d.saveOK ==0){ $('#load').html('SID/SKEY获取成功'); $('#addsubmit').attr('do','update'); $('#addsubmit').val('提交到更新页面'); $('.sid').show(); $('#sid').val(d.sid); $('#skey').val(d.skey); save(d.uin,d.sid,d.skey); $('#load').html('SID获取成功，请稍等...'); save(d.uin,d.sid,d.skey); }else if(d.saveOK ==4){ $('#load').html('验证码错误，请重新登录。'); $('#addsubmit').attr('do','submit'); $('.code').hide(); }else if(d.saveOK ==3){ $('#load').html('您输入的帐号或密码不正确，请重新输入密码！'); $('#addsubmit').attr('do','submit'); $('.code').hide(); }else{ alert(d.msg); $('#addsubmit').attr('do','submit'); } }); } function save(uin,sid,skey){ $('#load').html('正在存入数据库，请稍等...'); var loginurl="{:U('Ajax/addsave')}"; var pwd=$('#pwd').val(); xiha.postData(loginurl,"uin="+uin+"&sid="+sid+"&skey="+skey+"&pwd="+pwd, function(d) { if(d.saveOK ==0){ $('#load').html(d.msg+'！马上进入设置功能'); }else{ alert(d.msg); } }); } function getvc(uin,sig){ $('#load').html('获取验证码，请稍等...'); var getvcurl="/qqlogin.php?do=getvc"; xiha.postData(getvcurl,'uin='+uin+'&sig='+sig+'&r='+Math.random(1), function(d) { if(d.saveOK ==0){ $('#load').html('请输入验证码'); $('#codeimg').attr('vc',d.vc); $('#codeimg').html(''); $('#addsubmit').attr('do','code'); $('.code').show(); }else{ alert(d.msg); } }); } function dovc(uin,code,vc){ $('#load').html('验证验证码，请稍等...'); var getvcurl="/qqlogin.php?do=dovc"; xiha.postData(getvcurl,'uin='+uin+'&ans='+code+'&sig='+vc+'&r='+Math.random(1), function(d) { if(d.rcode ==0){ var pwd=$('#pwd').val(); p=getmd5(uin,pwd,d.randstr.toUpperCase()); login(uin,p,d.randstr.toUpperCase(),d.sig); }else{ $('#load').html('验证码错误，重新生成验证码，请稍等...'); getvc(uin,vc); } }); } $(document).ready(function(){ $('#addsubmit').click(function(){ var self=$(this); $('#load').html('登录中，请稍候...'); var uin=$('#uin').val(), pwd=$('#pwd').val(); if(self.attr('do') == 'code'){ var vcode=$('#code').val(), vc=$('#codeimg').attr('vc'); dovc(uin,vcode,vc); }else if(self.attr('do') == 'update'){ var sid=$('#sid').val(), skey=$('#skey').val(); window.location.href="{:U('set')}?qid={$Think.get.qid}&sid="+sid+"&skey="+skey; }else{ if (self.attr("data-lock") === "true") return; else self.attr("data-lock", "true"); var checkvcurl="/qqlogin.php?do=checkvc"; xiha.postData(checkvcurl,'uin='+uin+'&r='+Math.random(1), function(d) { if(d.saveOK ==0){ var strs= new Array(); //定义一数组 strs=d.data.split(","); if(strs[0]==0){ pt_verifysession=strs[3]; p=getmd5(uin,pwd,strs[2]); login(strs[1],p,strs[2],pt_verifysession); }else{ getvc(uin,strs[2]); } }else{ alert(d.msg); $('#load').html(''); } self.attr("data-lock", "false"); }); } }); });