faxinxi.la的實現原理分析

網上說微信中有個神奇代碼faxinxi.la能夠分享頁面功能看,看了確實好奇,其實網上也說這就是一個網址。它通過微信的useragetn後臺分析micromessage來限制之能在微信的內置瀏覽器中使用。通過模擬微信模擬器,查看他的代碼,搞清了他的基本實現原理。他的分享也是利用了微信裏的WeixinJsBridge來實現的。
當你選擇某個功能,如賀卡,裏的發送按鈕時他執行如下代碼 _card._post.

String.prototype.innerText=function(){return this.replace(/(<[^>]+>)|( )/ig,"");};
var _card={
_post:function(){
// 獲取title標題 content內容 author發送人等內容並進行判斷
var _title=$("card_title").innerHTML.innerText().trim(),_content=$("card_content").innerHTML.replace(/(<(br|div|\/div)>)+/ig,"\n").innerText(),_author=$("card_author").innerHTML.innerText().trim();
if(_title=="" || _title=="收卡人"){_system._toast("沒有輸入收卡人名字");return;}
if(_title.len()>20){_system._toast("收卡人名字在20字節以內");return;}
if(_content.len()<10){_system._toast("祝福語太短了");return;}
if(_content.len()>200){_system._toast("祝福語太長了");return;}
if(_author=="" || _author=="署名"){_system._toast("請署上你的大名");return;}
if(_author.len()>20){_system._toast("署名請在20字節以內");return;}
//之後調用_$,_$的意思是一個函數意思是發送連接進行後臺存儲,將你填寫的信息保存下來,並回調調用 _card._ok 方法
_$("/servlet/card","type="+_cardType+"&title="+_title.encode()+"&content="+_content.encode()+"&author="+_author.encode(),"請稍候","_card._ok");
},
_ok:function(json){
//如果保存成功返回狀態正常,則初始化一些分享的信息,包括分享的內容標題,圖標,分享的鏈接,分享的描述。
if(json.state=="0"){_system._toast("你填寫的內容有問題");return;}
dataForWeixin.MsgImg="http://img1.faxinxila.net/images/card_msg.png";
dataForWeixin.TLImg="http://img1.faxinxila.net/images/card.png";
dataForWeixin.path="card/"+_cardType+"/"+json.id;
dataForWeixin.title="收到一張來自"+$("card_author").innerHTML.innerText().trim()+"的"+_cardName;
dataForWeixin.desc=$("card_content").innerHTML.innerText().trim().left(88);
dataForWeixin.callback=function(){
_$("/servlet/share?kind=card&id="+json.id,"","");
};
// _system._guide()是調用另一個方法,顯示指引選擇微信分享的彈層
_system._guide();
}
};
window.onload=function(){$("card_body").show();$("card_loading").hide();};


String.prototype.len=function(){return this.replace(/[^\x00-\xff]/g,"aa").length;};
String.prototype.trim=function(){return this.replace(/(^ *)|( *$)/g, "");};
String.prototype.encode=function(){return escape(this.replace(/·/g," ")).replace(/\+/g,"%2B");};
String.prototype.left=function(length){
if(this.len()>length){
var _temp=this;
_temp=_temp.replace(/([^\x00-\xff])/g,"$1>");
_temp=_temp.substring(0,length-2)+"..";
return _temp.replace(/>/g,"");
}else{
return this.toString();
}
};
Element.prototype.show=function(){this.style.display="block";};
Element.prototype.hide=function(){this.style.display="none";};
Element.prototype.center=function(top){
this.style.left=(_system._scroll().x+_system._zero(_system._client().bw-this.offsetWidth)/2)+"px";
this.style.top=(top?top:(_system._scroll().y+_system._zero(_system._client().bh-this.offsetHeight)/2))+"px";
};
var _system={
_client:function(){
return {w:document.documentElement.scrollWidth,h:document.documentElement.scrollHeight,bw:document.documentElement.clientWidth,bh:document.documentElement.clientHeight};
},
_scroll:function(){
return {x:document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft,y:document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop};
},
_cover:function(show){
if(show){
$("cover").show();
$("cover").style.width=(this._client().bw>this._client().w?this._client().bw:this._client().w)+"px";
$("cover").style.height=(this._client().bh>this._client().h?this._client().bh:this._client().h)+"px";
}else{
$("cover").hide();
}
},
_loading:function(text){
if(text){
this._cover(true);
$("loading").show();
$("loading_text").innerHTML=text;
$("loading").center();
window.onresize=function(){_system._cover(true);$("loading").center();};
}else{
this._cover(false);
$("loading").hide();
window.onresize=null;
}
},
_toast:function(text,fun){
$("toast").show();
$("toast").innerHTML=text;
$("toast").center();
setTimeout(function(){
$("toast").hide();
if(fun){(fun)();}
},3*1000);
},
_ok:function(text,fun){
$("ok").show();
$("ok_text").innerHTML=text;
$("ok").center();
window.onresize=function(){$("ok").center();};
setTimeout(function(){
window.onresize=null;
$("ok").hide();
(fun)();
},2*1000);
},

//分享的彈層,顯示讓你分享網址。
_guide:function(click){
this._cover(true);
$("guide").show();
$("guide").style.top=(_system._scroll().y+5)+"px";
window.onresize=function(){_system._cover(true);$("guide").style.top=(_system._scroll().y+5)+"px";};
if(click){$("cover").onclick=function(){
_system._cover();
$("guide").hide();
$("cover").onclick=null;
window.onresize=null;
};}
},
_zero:function(n){
return n<0?0:n;
},
_forbidden:function(text){
return text.match(/(老市長|bxl|b市長|flg)/)!=null;
},
_shareUrl:function(){
var domain=["url.lc","www.faxinxi.la","www.faxingxi.la","www.kanxinxi.la","www.zhaoxinxi.la","www.zhaofuwu.la","faxinxila.com","faxinxila.net","kanxinxila.com","kanxinxila.net","www.messagehelper.com","www.messagehelper.net","tongmang.com","tongmang.net","tuimang.com","teimang.com","rengmei.com","fxxl.xiaozhongapp.com","fxxl.xiaozongapp.com","showarticle.cc","showparty.cc","showvote.cc","showmore.cc","jootun.com","showinfo.cc","showdetail.cc","showhot.cc","shownew.cc","getall.cc","gethot.cc","getnew.cc","getone.cc","getdetail.cc","getmessage.cc","myvote.cc","myarticle.cc","newmessage.cc","newarticle.cc","newvote.cc","newparty.cc","sharemessage.cc","sharearticle.cc","sharevote.cc","shareparty.cc","showpost.cc","getpost.cc","newpost.cc","sharepost.cc","readit.cc","jointhem.cc","clickit.cc","showit.cc","allarticle.cc","allcard.cc","allparty.cc","allvote.cc","bestparty.cc","bestvote.cc","bestarticle.cc","bestmessage.cc","yourarticle.cc","yourvote.cc","yourparty.cc","yourcard.cc","yourmessage.cc","loveparty.cc","lovevote.cc","lovecard.cc","lovearticle.cc","ourparty.cc","ourvote.cc","ourcard.cc","ourarticle.cc","goodarticle.cc","goodvote.cc","goodparty.cc","goodmessage.cc","joootun.com","jooootun.com","joooootun.com"],path=["detail.jsp?r=","show.asp?l=","index.do?u=","info.do?i="];
return "http://"+domain[parseInt(domain.length*Math.random())]+"/"+path[parseInt(path.length*Math.random())]+dataForWeixin.path;
}
};
(function(){

//由於分享的東西已經初始化完成,所以這裏直接調用微信的分享功能,完成對配置的連接的分享。
var onBridgeReady=function(){
WeixinJSBridge.on('menu:share:appmessage', function(argv){
WeixinJSBridge.invoke('sendAppMessage',{
"appid":dataForWeixin.appId,
"img_url":dataForWeixin.MsgImg,
"img_width":"120",
"img_height":"120",
"link":_system._shareUrl(),
"desc":dataForWeixin.desc,
"title":dataForWeixin.title
}, function(res){(dataForWeixin.callback)();});
});
WeixinJSBridge.on('menu:share:timeline', function(argv){
(dataForWeixin.callback)();
WeixinJSBridge.invoke('shareTimeline',{
"img_url":dataForWeixin.TLImg,
"img_width":"120",
"img_height":"120",
"link":_system._shareUrl(),
"desc":dataForWeixin.desc,
"title":dataForWeixin.title
}, function(res){});
});
WeixinJSBridge.on('menu:share:weibo', function(argv){
WeixinJSBridge.invoke('shareWeibo',{
"content":dataForWeixin.title,
"url":_system._shareUrl()
}, function(res){(dataForWeixin.callback)();});
});
WeixinJSBridge.on('menu:share:facebook', function(argv){
(dataForWeixin.callback)();
WeixinJSBridge.invoke('shareFB',{
"img_url":dataForWeixin.TLImg,
"img_width":"120",
"img_height":"120",
"link":_system._shareUrl(),
"desc":dataForWeixin.desc,
"title":dataForWeixin.title
}, function(res){});
});
};
if(document.addEventListener){
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
}else if(document.attachEvent){
document.attachEvent('WeixinJSBridgeReady' , onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady' , onBridgeReady);
}
})();
var _$=function(url,parameters,loadingMessage,functionName){
var request=new XMLHttpRequest();
if(loadingMessage!=""){_system._loading(loadingMessage);}
var method="POST";
if(parameters==""){method="GET";parameters=null;}
request.open(method,url,true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.onreadystatechange=function(){
if(request.readyState==4){
if(loadingMessage != ""){_system._loading();}
if(request.status==200){
if(functionName){
try{
var json = eval("("+ request.responseText+")");
eval(functionName+"(json)");
}catch(e){}
}
}else{
if(loadingMessage != ""){_system._toast("發生意外錯誤,請稍候再試");}
}
}
};
request.send(parameters);
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章