时间:2021-05-02
本文给出了openid登录的源代码,以与大家共享。
以前sipo好像说asp写openid有些不能解决的问题,我也没查openid的规范。
这个对付简单的登录还是没问题的,不过代码还没测试。先放上来,有兴趣的可以看看
<script language="JScript" runat="server">
var alert=print=write=function(str){Response.Write(str);} var openid = new fiskerOpenid(); var input=getInput(); if(input["openid.mode"]=="id_res"){ var nickname = input["openid.sreg.nickname"]; var email = input["openid.sreg.email"]; var returnUrl=input["return"]; returnUrl += returnUrl.indexOf("?")!=-1?"&":"?"; returnUrl += "nickname="+nickname; returnUrl += "&email="+email;
Response.Redirect(returnUrl); }else{ if(input["openid"]==""||input["return"]==""){ Response.write("<sc"+"ript>"); Response.write("alert(\"error\");"); Response.write("window.history.forward(1);"); Response.write("</sc"+"ript>"); Response.end(); } openid.url = input["openid"]; openid.get(); }
function getInput(){ var input=new Array(); var e=new Enumerator(Request.QueryString); for (;!e.atEnd();e.moveNext()){ x=e.item(); input[String(x).toLowerCase()]=String(Request.QueryString(x)); } e=new Enumerator(Request.Form); for (;!e.atEnd();e.moveNext()){ x=e.item(); input[String(x).toLowerCase()]=String(Request.Form(x)); } return input; }
function fiskerOpenid(){ this.url=""; this.server=""; this.delegate=""; this.user = null; this.trust_root=""; this.return_to=""; this.sreg_required="nickname,email";
this.get = function(info){ if(!this.init()){Response.write("error");return;} if(info!=undefined)this.sreg_required=info; var html=this.request(this.server,"openid.mode=associate&openid.assoc_type=HMAC-SHA1"); if (html==""){Response.write("error");return;} var assoc_handle = ""; var assoc_type = ""; var expires_in = ""; var mac_key = ""; try{ var re=new RegExp("assoc_handle:(.+)","ig"); assoc_handle = re.exec(html)[1]; var re=new RegExp("assoc_type:(.+)","ig"); aassoc_type = re.exec(html)[1]; var re=new RegExp("expires_in:(.+)","ig"); expires_in = re.exec(html)[1]; var re=new RegExp("mac_key:(.+)","ig"); mac_key = re.exec(html)[1]; delete re; }catch(e){}
var url = this.server; url += url.indexOf("?")!=-1?"&":"?"; url += "openid.mode="+Server.URLEncode("checkid_setup"); url += "&openid.identity="+Server.URLEncode(this.delegate); url += "&openid.trust_root="+Server.URLEncode(this.trust_root); url += "&openid.return_to="+Server.URLEncode(this.return_to); url += "&openid.assoc_handle="+Server.URLEncode(assoc_handle); url += "&openid.sreg.required="+Server.URLEncode(this.sreg_required);
Response.Redirect(url); }
this.init = function(){ if(!this.check()) return false;
if(this.trust_root==""||this.return_to==""){ var thisServer=""; var thisUrl=""; thisServer+=String(Request.serverVariables("https")).toLowerCase()=="off"?"http://":"https://"; thisServer+=String(Request.serverVariables("server_name")); thisServer+=String(Request.serverVariables("server_port"))=="80"?"":":"+String(Request.ServerVariables("server_port")); thisUrl+=thisServer; thisUrl+=String(Request.serverVariables("URL")); thisUrl+=String(Request.QueryString)==""?"":"?"+String(Request.QueryString); this.trust_root=(this.trust_root==""?thisServer:this.trust_root); this.return_to=(this.return_to==""?thisUrl:this.return_to); }
var html = this.request(this.url); if (html=="") return false; html=html.replace(/\’/ig,"\""); var re=new RegExp("<link(.*?)rel=\"(.*?)\"(.*?)href=\"(.*?)\"(.*?)>","ig"); var arr=[]; while ((arrMatch = re.exec(html)) != null){ var index=arrMatch[2].toLowerCase(); var value=arrMatch[4]; if(index.indexOf(" ")){ for(var j=0;j<index.split(" ").length;j++)arr[index.split(" ")[j]]=value; }else{ arr[index]=value; } } delete re; if(arr["openid.server"]!=""){ this.server=arr["openid.server"]; }else{ return false; } this.delegate = arr["openid.delegate"]==undefined?this.url:arr["openid.delegate"]; return true; }
this.check = function(){ if (this.url=="") return false; if(this.url.indexOf("://")==-1) this.url="http://"+this.url; return true; }
this.request = function(url,data){ if (data == undefined)var data = null; var method = data ? ’POST’ : ’GET’; var html=""; try{ var xmlhttp=Server.CreateObject("MSXML2.ServerXMLHTTP.3.0"); xmlhttp.open(method,url,false); xmlhttp.send(data); html = this.bytesToStr(xmlhttp.responseBody); delete xmlhttp; }catch(e){} return html; }
this.bytesToStr = function(CodeBody){ var objStream= Server.CreateObject("ado"+"db.stream") ; objStream.Type = 1 ; objStream.Mode =3 ; objStream.Open() ; objStream.Write(CodeBody); objStream.Position = 0 ; objStream.Type = 2 ; objStream.charset = "utf-8" ; var returnstr = objStream.ReadText; objStream.Close(); delete objStream; return returnstr; }
} </script>
文章来自: 翔宇亭乐园(http://www.biye5u.com)
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
微信小程序获取openid及用户信息的方法1.获取openid1.1获取code调用接口获取登录凭证(code)进而换取用户登录态信息,包括用户的唯一标识(op
asp生日自动提醒小程式用ASP编写,调试通过,使用方便-aspbirthdayautomaticallyremindsmallprogramswiththep
asp/vbscript将json字符解析为json对象的方法,如果asp使用jscript来编写服务器端代码操作json字符串就简单了,vbscript需要M
使用python来登录asp网站和登录其他网站差不多,只是因为asp页面在每次请求的时候都要带上viewstate,因此使用python来登录的话就多了一个步骤
众所周知,用户在打开微信小程序的时候,我们可以使用小程序自带的静默登录代码,获取用户的openid的,现在就分析来小程序的登录代码该如何写,才能确定的实现小程序