最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

asp写的一个openid登录技巧方法

日期:04-17    来源:中国设计秀    作者:cnwebshow.com

以前好像看到sipo说asp写openid有些不能解决的问题,我也没查openid的规范。BPX中国设计秀
这个对付简单的登录还是没问题的,不过代码还没测试。BPX中国设计秀

先放上来,有兴趣的可以看看BPX中国设计秀

BPX中国设计秀
 <script language="JScript" runat="server">BPX中国设计秀
/*BPX中国设计秀
ASP OpenidBPX中国设计秀
by fiskerBPX中国设计秀
2008-9-3BPX中国设计秀
*/BPX中国设计秀
var alert=PRint=write=function(str){Response.Write(str);}BPX中国设计秀
var openid = new fiskerOpenid();BPX中国设计秀
var input=getInput();BPX中国设计秀
if(input["openid.mode"]=="id_res"){BPX中国设计秀
  var nickname = input["openid.sreg.nickname"];BPX中国设计秀
  var email = input["openid.sreg.email"];BPX中国设计秀
  var returnUrl=input["return"];BPX中国设计秀
  returnUrl += returnUrl.indexOf("?")!=-1?"&":"?";BPX中国设计秀
  returnUrl += "nickname="+nickname;BPX中国设计秀
  returnUrl += "&email="+email;BPX中国设计秀

  Response.Redirect(returnUrl);BPX中国设计秀
}else{BPX中国设计秀
  if(input["openid"]==""||input["return"]==""){BPX中国设计秀
    Response.write("<sc"+"ript>");BPX中国设计秀
    Response.write("alert("error");");BPX中国设计秀
    Response.write("window.history.forward(1);");BPX中国设计秀
    Response.write("</sc"+"ript>");BPX中国设计秀
    Response.end();BPX中国设计秀
  }BPX中国设计秀
  BPX中国设计秀
  openid.url = input["openid"];BPX中国设计秀
  openid.get();BPX中国设计秀
}BPX中国设计秀

function getInput(){BPX中国设计秀
    var input=new Array();BPX中国设计秀
    var e=new Enumerator(Request.QueryString);BPX中国设计秀
    for (;!e.atEnd();e.moveNext()){BPX中国设计秀
      x=e.item();BPX中国设计秀
      input[String(x).toLowerCase()]=String(Request.QueryString(x));BPX中国设计秀
    }BPX中国设计秀
    e=new Enumerator(Request.Form);BPX中国设计秀
    for (;!e.atEnd();e.moveNext()){BPX中国设计秀
      x=e.item();BPX中国设计秀
      input[String(x).toLowerCase()]=String(Request.Form(x));BPX中国设计秀
    }BPX中国设计秀
    return input;BPX中国设计秀
}BPX中国设计秀

function fiskerOpenid(){BPX中国设计秀
  this.url="";BPX中国设计秀
  this.server="";BPX中国设计秀
  this.delegate="";BPX中国设计秀
  this.user = null;BPX中国设计秀
  this.trust_root="";BPX中国设计秀
  this.return_to="";BPX中国设计秀
  this.sreg_required="nickname,email";BPX中国设计秀

  this.get = function(info){BPX中国设计秀
    if(!this.init()){Response.write("error");return;}BPX中国设计秀
    if(info!=undefined)this.sreg_required=info;BPX中国设计秀
    var html=this.request(this.server,"openid.mode=associate&openid.assoc_type=HMAC-SHA1");BPX中国设计秀
    if (html==""){Response.write("error");return;}BPX中国设计秀
    var assoc_handle = "";BPX中国设计秀
    var assoc_type = "";BPX中国设计秀
    var expires_in = "";BPX中国设计秀
    var mac_key = "";BPX中国设计秀
    try{BPX中国设计秀
      var re=new RegExp("assoc_handle:(.+)","ig");BPX中国设计秀
      assoc_handle = re.exec(html)[1];BPX中国设计秀
      var re=new RegExp("assoc_type:(.+)","ig");BPX中国设计秀
      aassoc_type = re.exec(html)[1];BPX中国设计秀
      var re=new RegExp("expires_in:(.+)","ig");BPX中国设计秀
      expires_in = re.exec(html)[1];BPX中国设计秀
      var re=new RegExp("mac_key:(.+)","ig");BPX中国设计秀
      mac_key = re.exec(html)[1];BPX中国设计秀
      delete re;BPX中国设计秀
    }catch(e){}BPX中国设计秀

    var url = this.server;BPX中国设计秀
    url += url.indexOf("?")!=-1?"&":"?";BPX中国设计秀
    url += "openid.mode="+Server.URLEncode("checkid_setup");BPX中国设计秀
    url += "&openid.identity="+Server.URLEncode(this.delegate);BPX中国设计秀
    url += "&openid.trust_root="+Server.URLEncode(this.trust_root);BPX中国设计秀
    url += "&openid.return_to="+Server.URLEncode(this.return_to);BPX中国设计秀
    url += "&openid.assoc_handle="+Server.URLEncode(assoc_handle);BPX中国设计秀
    url += "&openid.sreg.required="+Server.URLEncode(this.sreg_required);BPX中国设计秀

    Response.Redirect(url);BPX中国设计秀
  }BPX中国设计秀

  this.init = function(){BPX中国设计秀
    if(!this.check()) return false;BPX中国设计秀

    if(this.trust_root==""||this.return_to==""){BPX中国设计秀
      var thisServer="";BPX中国设计秀
      var thisUrl="";BPX中国设计秀
      thisServer+=String(Request.serverVariables("https")).toLowerCase()=="off"?"http://":"https://";BPX中国设计秀
      thisServer+=String(Request.serverVariables("server_name"));BPX中国设计秀
      thisServer+=String(Request.serverVariables("server_port"))=="80"?"":":"+String(Request.ServerVariables("server_port"));BPX中国设计秀
      thisUrl+=thisServer;BPX中国设计秀
      thisUrl+=String(Request.serverVariables("URL"));BPX中国设计秀
      thisUrl+=String(Request.QueryString)==""?"":"?"+String(Request.QueryString);BPX中国设计秀
      this.trust_root=(this.trust_root==""?thisServer:this.trust_root);BPX中国设计秀
      this.return_to=(this.return_to==""?thisUrl:this.return_to);BPX中国设计秀
    }BPX中国设计秀

    var html = this.request(this.url);BPX中国设计秀
    if (html=="") return false;BPX中国设计秀
    html=html.replace(/'/ig,""");BPX中国设计秀
    var re=new RegExp("<link(.*?)rel="(.*?)"(.*?)href="(.*?)"(.*?)>","ig");BPX中国设计秀
    var arr=[];BPX中国设计秀
    while ((arrMatch = re.exec(html)) != null){BPX中国设计秀
      var index=arrMatch[2].toLowerCase();BPX中国设计秀
      var value=arrMatch[4];BPX中国设计秀
      if(index.indexOf(" ")){BPX中国设计秀
        for(var j=0;j<index.split(" ").length;j++)arr[index.split(" ")[j]]=value;BPX中国设计秀
      }else{BPX中国设计秀
        arr[index]=value;BPX中国设计秀
      }BPX中国设计秀
    }BPX中国设计秀
    delete re;BPX中国设计秀
    if(arr["openid.server"]!=""){BPX中国设计秀
      this.server=arr["openid.server"];BPX中国设计秀
    }else{BPX中国设计秀
      return false;BPX中国设计秀
    }BPX中国设计秀
    this.delegate = arr["openid.delegate"]==undefined?this.url:arr["openid.delegate"];BPX中国设计秀
    return true;BPX中国设计秀
  }BPX中国设计秀

  this.check = function(){BPX中国设计秀
    if (this.url=="") return false;BPX中国设计秀
    if(this.url.indexOf("://")==-1) this.url="http://"+this.url;BPX中国设计秀
    return true;BPX中国设计秀
  }BPX中国设计秀

  this.request = function(url,data){BPX中国设计秀
    if (data == undefined)var data = null;BPX中国设计秀
    var method = data ? 'POST' : 'GET'; BPX中国设计秀
    var html="";BPX中国设计秀
    try{BPX中国设计秀
      var xmlhttp=Server.CreateObject("MSXML2.Serverxmlhttp.3.0");BPX中国设计秀
      xmlhttp.open(method,url,false);BPX中国设计秀
      xmlhttp.send(data);BPX中国设计秀
        html = this.bytesToStr(xmlhttp.responseBody);BPX中国设计秀
      delete xmlhttp;BPX中国设计秀
    }catch(e){}BPX中国设计秀
      return html;BPX中国设计秀
    }BPX中国设计秀

  this.bytesToStr = function(CodeBody){BPX中国设计秀
    var objStream= Server.CreateObject("ado"+"db.stream") ;BPX中国设计秀
    objStream.Type = 1 ;BPX中国设计秀
    objStream.Mode =3 ;BPX中国设计秀
    objStream.Open() ;BPX中国设计秀
    objStream.Write(CodeBody);BPX中国设计秀
    objStream.Position = 0 ;BPX中国设计秀
    objStream.Type = 2 ;BPX中国设计秀
    objStream.charset = "utf-8" ;BPX中国设计秀
    var returnstr = objStream.ReadText;BPX中国设计秀
    objStream.Close();BPX中国设计秀
    delete objStream;BPX中国设计秀
    return returnstr;BPX中国设计秀
  }BPX中国设计秀

}BPX中国设计秀
</script>BPX中国设计秀

作者:fiskerBPX中国设计秀

本文引用地址:/bc/article_46299.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明