首页 > 代码库 > 微信禁用分享JS后的安卓解决方案
微信禁用分享JS后的安卓解决方案
不能使用微信分享JS后,想必大家一定急坏了。腾讯这是要把大家往死路上赶啊。经过一番调研,终于解决了安卓机的分享问题,包括自定义分享链接、封面、回调函数等(实测可用),但还未能找到ios的解决方案。anyway,这里先分享一下安卓的解决方案,希望起到个抛砖引玉的作用。
下面是封装好的WeixinApi.js
(function(c) { var d = { version: 3.8 }; c.WeixinApi = d; if (typeof define === "function" && (define.amd || define.cmd)) { if (define.amd) { define(function() { return d }) } else { if (define.cmd) { define(function(f, e, g) { g.exports = d }) } } } var b = function() { var f = {}, j, g; for (var h = 0, e = arguments.length; h < e; h++) { j = arguments[h]; if (typeof j === "object") { for (g in j) { j[g] && (f[g] = j[g]) } } } return f }; var a = function(i, h, g) { g = g || {}; var e = function(j) { switch (true) { case /\:cancel$/i.test(j.err_msg): g.cancel && g.cancel(j); break; case /\:(confirm|ok)$/i.test(j.err_msg): g.confirm && g.confirm(j); break; case /\:fail$/i.test(j.err_msg): default: g.fail && g.fail(j); break } g.all && g.all(j) }; var f = function(k, j) { if (i.menu == "menu:share:timeline" || (i.menu == "menu:general:share" && j.shareTo == "timeline")) { var l = k.title; k.title = k.desc || l; k.desc = l || k.desc } if (i.menu === "menu:general:share") { if (j.shareTo == "favorite" || j.scene == "favorite") { if (g.favorite === false) { return j.generalShare(k, function() { }) } } j.generalShare(k, e) } else { WeixinJSBridge.invoke(i.action, k, e) } }; WeixinJSBridge.on(i.menu, function(k) { g.dataLoaded = g.dataLoaded || new Function(); if (g.async && g.ready) { d._wx_loadedCb_ = g.dataLoaded; if (d._wx_loadedCb_.toString().indexOf("_wx_loadedCb_") > 0) { d._wx_loadedCb_ = new Function() } g.dataLoaded = function(m) { g.__cbkCalled = true; var l = b(h, m); l.img_url = l.imgUrl || l.img_url; delete l.imgUrl; d._wx_loadedCb_(l); f(l, k) }; if (!(k && (k.shareTo == "favorite" || k.scene == "favorite") && g.favorite === false)) { g.ready && g.ready(k, h); if (!g.__cbkCalled) { g.dataLoaded({}); g.__cbkCalled = false } } } else { var j = b(h); if (!(k && (k.shareTo == "favorite" || k.scene == "favorite") && g.favorite === false)) { g.ready && g.ready(k, j) } f(j, k) } }) }; d.shareToTimeline = function(f, e) { a({ menu: "menu:share:timeline", action: "shareTimeline" }, { appid: f.appId ? f.appId : "", img_url: f.imgUrl, link: f.link, desc: f.desc, title: f.title, img_width: "640", img_height: "640" }, e) }; d.shareToFriend = function(f, e) { a({ menu: "menu:share:appmessage", action: "sendAppMessage" }, { appid: f.appId ? f.appId : "", img_url: f.imgUrl, link: f.link, desc: f.desc, title: f.title, img_width: "640", img_height: "640" }, e) }; d.shareToWeibo = function(f, e) { a({ menu: "menu:share:weibo", action: "shareWeibo" }, { content: f.desc, url: f.link }, e) }; d.generalShare = function(f, e) { a({ menu: "menu:general:share" }, { appid: f.appId ? f.appId : "", img_url: f.imgUrl, link: f.link, desc: f.desc, title: f.title, img_width: "640", img_height: "640" }, e) }; d.addContact = function(e, f) { f = f || {}; WeixinJSBridge.invoke("addContact", { webtype: "1", username: e }, function(h) { var g = !h.err_msg || "add_contact:ok" == h.err_msg || "add_contact:added" == h.err_msg; if (g) { f.success && f.success(h) } else { f.fail && f.fail(h) } }) }; d.imagePreview = function(e, f) { if (!e || !f || f.length == 0) { return } WeixinJSBridge.invoke("imagePreview", { current: e, urls: f }) }; d.showOptionMenu = function() { WeixinJSBridge.call("showOptionMenu") }; d.hideOptionMenu = function() { WeixinJSBridge.call("hideOptionMenu") }; d.showToolbar = function() { WeixinJSBridge.call("showToolbar") }; d.hideToolbar = function() { WeixinJSBridge.call("hideToolbar") }; d.getNetworkType = function(e) { if (e && typeof e == "function") { WeixinJSBridge.invoke("getNetworkType", {}, function(f) { e(f.err_msg) }) } }; d.closeWindow = function(e) { e = e || {}; WeixinJSBridge.invoke("closeWindow", {}, function(f) { switch (f.err_msg) { case "close_window:ok": e.success && e.success(f); break; default: e.fail && e.fail(f); break } }) }; d.ready = function(g) { if (g && typeof g == "function") { var e = this; var f = function() { g(e) }; if (typeof c.WeixinJSBridge == "undefined") { if (document.addEventListener) { document.addEventListener("WeixinJSBridgeReady", f, false) } else { if (document.attachEvent) { document.attachEvent("WeixinJSBridgeReady", f); document.attachEvent("onWeixinJSBridgeReady", f) } } } else { f() } } }; d.openInWeixin = function() { return /MicroMessenger/i.test(navigator.userAgent) }; d.scanQRCode = function(e) { e = e || {}; WeixinJSBridge.invoke("scanQRCode", {}, function(f) { switch (f.err_msg) { case "scan_qrcode:ok": e.success && e.success(f); break; default: e.fail && e.fail(f); break } }) }; d.getInstallState = function(f, e) { e = e || {}; WeixinJSBridge.invoke("getInstallState", { packageUrl: f.packageUrl || "", packageName: f.packageName || "" }, function(i) { var h = i.err_msg, g = h.match(/state:yes_?(.*)$/); if (g) { i.version = g[1] || ""; e.success && e.success(i) } else { e.fail && e.fail(i) } e.all && e.all(i) }) }; d.sendEmail = function(f, e) { e = e || {}; WeixinJSBridge.invoke("sendEmail", { title: f.subject, content: f.body }, function(g) { if (g.err_msg === "send_email:sent") { e.success && e.success(g) } else { e.fail && e.fail(g) } e.all && e.all(g) }) }; d.enableDebugMode = function(e) { c.onerror = function(i, g, f, h) { if (typeof e === "function") { e({ message: i, script: g, line: f, column: h }) } else { var j = []; j.push("额,代码有错。。。"); j.push("\n错误信息:", i); j.push("\n出错文件:", g); j.push("\n出错位置:", f + "行," + h + "列"); alert(j.join("")) } } }; d.hook = (function() { var h; var g; var i = function(j, k) { h = j; g = function(m) { var l = k || {}; switch (true) { case /\:cancel$/i.test(m.err_msg): l.cancel && l.cancel(m); break; case /\:(confirm|ok)$/i.test(m.err_msg): l.confirm && l.confirm(m); break; case /\:fail$/i.test(m.err_msg): default: l.fail && l.fail(m); break } l.all && l.all(m) } }; var f = function(l) { var j = b(l.__params, h); j.img_url = j.imgUrl || j.img_url; delete j.imgUrl; switch (l.__event_id) { case "menu:share:timeline": var k = j.title; j.title = j.desc || k; j.desc = k || j.desc; l.__params = j; break; case "menu:share:appmessage": case "menu:share:qq": case "menu:share:weiboApp": l.__params = j; break } }; var e = function(j, k) { switch (j) { case "sendAppMessage": case "shareTimeline": case "shareWeibo": k = !k ? g : function(l) { k(l) && g(l) }; break } return k }; return { enable: i, message: f, callbacks: e} })() })(window);
以及wxjs.6.02.js
(function(){var _WXJS=window._WXJS;var UTF8={encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c)}else{if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128)}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128)}}}return utftext},decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++}else{if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3}}}return string}};var HEX={encode:function(str){var r="";var e=str.length;var c=0;var h;while(c<e){h=str.charCodeAt(c++).toString(16);while(h.length<2){h="0"+h}r+=h}return r.toUpperCase()},decode:function(str){var r="";var e=str.length;var s;while(e>=0){s=e-2;r=String.fromCharCode("0x"+str.substring(s,e))+r;e=s}return r}};var JSON;if(!JSON){JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",‘"‘:‘\\"‘,"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?‘"‘+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+‘"‘:‘"‘+string+‘"‘}function str(key,holder){var i,k,v,length,mind=gap,partial,value=http://www.mamicode.com/holder[key];if(typeof rep==="function"){value=http://www.mamicode.com/rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==="string"){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=http://www.mamicode.com/holder[key];if(value&&typeof valuehttp://www.mamicode.com/==="object"){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());var base64encodechars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function base64encode(str){if(str===undefined){return str}var out,i,len;var c1,c2,c3;len=str.length;i=0;out="";while(i<len){c1=str.charCodeAt(i++)&255;if(i==len){out+=base64encodechars.charAt(c1>>2);out+=base64encodechars.charAt((c1&3)<<4);out+="==";break}c2=str.charCodeAt(i++);if(i==len){out+=base64encodechars.charAt(c1>>2);out+=base64encodechars.charAt(((c1&3)<<4)|((c2&240)>>4));out+=base64encodechars.charAt((c2&15)<<2);out+="=";break}c3=str.charCodeAt(i++);out+=base64encodechars.charAt(c1>>2);out+=base64encodechars.charAt(((c1&3)<<4)|((c2&240)>>4));out+=base64encodechars.charAt(((c2&15)<<2)|((c3&192)>>6));out+=base64encodechars.charAt(c3&63)}return out}var _readyMessageIframe,_sendMessageQueue=[],_receiveMessageQueue=[],_callback_count=1000,_callback_map={},_event_hook_map={},_session_data=http://www.mamicode.com/{},_MESSAGE_SEPERATOR="__wxmsg_sep__",_CUSTOM_PROTOCOL_SCHEME="weixin",_MESSAGE_TYPE="__msg_type",_CALLBACK_ID="__callback_id",_EVENT_ID="__event_id",_QUEUE_HAS_MESSAGE="dispatch_message/",_setResultIframe;var _runOn3rdApiList=[],_event_hook_map_for3rd={},_RUN_ON_3RD_APIS="__runOn3rd_apis";function _createQueueReadyIframe(doc){_setResultIframe=doc.createElement("iframe");_setResultIframe.id="__WeixinJSBridgeIframe_SetResult";_setResultIframe.style.display="none";doc.documentElement.appendChild(_setResultIframe);_readyMessageIframe=doc.createElement("iframe");_readyMessageIframe.id="__WeixinJSBridgeIframe";_readyMessageIframe.style.display="none";doc.documentElement.appendChild(_readyMessageIframe);return _readyMessageIframe}function _sendMessage(message){_sendMessageQueue.push(message);_readyMessageIframe.src=http://www.mamicode.com/_CUSTOM_PROTOCOL_SCHEME+"://"+_QUEUE_HAS_MESSAGE}function _fetchQueue(){var messageQueueString=JSON.stringify(_sendMessageQueue);_sendMessageQueue=[];_setResultValue("SCENE_FETCHQUEUE",messageQueueString);return messageQueueString}function _handleMessageFromWeixin(message){var msgWrap=message;switch(msgWrap[_MESSAGE_TYPE]){case"callback":if(typeof msgWrap[_CALLBACK_ID]==="string"&&typeof _callback_map[msgWrap[_CALLBACK_ID]]==="function"){var ret=_callback_map[msgWrap[_CALLBACK_ID]](msgWrap.__params);delete _callback_map[msgWrap[_CALLBACK_ID]];_setResultValue("SCENE_HANDLEMSGFROMWX",JSON.stringify(ret));return JSON.stringify(ret)}_setResultValue("SCENE_HANDLEMSGFROMWX",JSON.stringify({__err_code:"cb404"}));return JSON.stringify({__err_code:"cb404"});break;case"event":if(typeof message[_EVENT_ID]==="string"){if(typeof _event_hook_map_for3rd[message[_EVENT_ID]]==="function"&&_isIn3rdApiList(message[_EVENT_ID])){var ret=_event_hook_map_for3rd[message[_EVENT_ID]](message.__params);_setResultValue("SCENE_HANDLEMSGFROMWX",JSON.stringify(ret));return JSON.stringify(ret)}else{if(typeof _event_hook_map[message[_EVENT_ID]]==="function"){window.WeixinApi&&WeixinApi.hook.message(message);var ret=_event_hook_map[message[_EVENT_ID]](message.__params);_setResultValue("SCENE_HANDLEMSGFROMWX",JSON.stringify(ret));return JSON.stringify(ret)}}}_setResultValue("SCENE_HANDLEMSGFROMWX",JSON.stringify({__err_code:"ev404"}));return JSON.stringify({__err_code:"ev404"});break}}function _setResultValue(scene,result){if(result===undefined){result="dummy"}_setResultIframe.src="weixin://private/setresult/"+scene+"&"+base64encode(UTF8.encode(result))}function _isIn3rdApiList(event){var r=_runOn3rdApiList.some(function(x){return x===event});_log("_isIn3rdApiList , event : "+event+" , result : "+r);return r}function _env(key){return _session_data[key]}function _log(fmt){var argv=[];for(var i=0;i<arguments.length;i++){argv.push(arguments[i])}var fm=argv.shift();var msg;msg=fmt;_call("log",{msg:msg})}function _call(func,params,callback){if(!func||typeof func!=="string"){return}if(typeof params!=="object"){params={}}var callbackID=(_callback_count++).toString();callback=window.WeixinApi&&WeixinApi.hook.callbacks(func,callback);if(typeof callback==="function"){_callback_map[callbackID]=callback}var msgObj={func:func,params:params};msgObj[_MESSAGE_TYPE]="call";msgObj[_CALLBACK_ID]=callbackID;_sendMessage(JSON.stringify(msgObj))}function _on(event,callback){if(!event||typeof event!=="string"){return}if(typeof callback!=="function"){return}_event_hook_map[event]=callback}function _onfor3rd(event,callback){if(!event||typeof event!=="string"){return}if(typeof callback!=="function"){return}_event_hook_map_for3rd[event]=callback}function _emit(event,argv){if(typeof _event_hook_map[event]!=="function"){return}if(_isIn3rdApiList(event)){_event_hook_map_for3rd[event](argv)}else{_event_hook_map[event](argv)}}function _enable_old_UrlStyleImagePreviews(){var old_prefix="weixin://viewimage/";_WXJS(‘a[href^="weixin://viewimage/"]‘).on("click",function(e){var cur="";var link;if(typeof e.target.hrefhttp://www.mamicode.com/==="string"&&e.target.href.search(old_prefix)===0){link=e.target}else{link=_WXJS(e.target).parents(‘a[href^="weixin://viewimage/"]‘)[0]}cur=link.href.substr(old_prefix.length);var allLinks=_WXJS(‘a[href^="weixin://viewimage/"]‘);var allUrls=[];for(var i=0;i<allLinks.length;i++){allUrls.push(allLinks[i].href.substr(old_prefix.length))}_call("imagePreview",{urls:allUrls,current:cur});e.preventDefault()})}function _enable_old_ReaderShareUrls(){var old_prefix="weixin://readershare/";_WXJS(‘a[href^="weixin://readershare/"]‘).on("click",function(e){e.preventDefault();_emit("menu:share:weibo",_session_data.shareWeiboData||{})});_WXJS(‘a[href^="weixin://readertimeline/"]‘).on("click",function(e){e.preventDefault();_emit("menu:share:timeline",_session_data.shareTimelineData||{})})}function _enable_hashChangeNotify(){_WXJS(window).bind("hashchange",function(){_call("hashChange",{hash:window.location.hash})})}function _setDefaultEventHandlers(){_on("menu:setfont",function(argv){if(typeof changefont==="function"){var num=parseInt(argv.fontSize);_log("set font size with changefont: %s",argv.fontSize);changefont(num);return}var s;switch(argv.fontSize){case"1":s="80%";break;case"2":s="100%";break;case"3":s="120%";break;case"4":s="140%";break;default:return}_log("set font size with webkitTextSizeAdjust: %s",argv.fontSize);_call("setFontSizeCallback",{fontSize:argv.fontSize})});var getSharePreviewImage=function(cb){var isCalled=false;var callCB=function(_img){if(isCalled){return}isCalled=true;cb(_img)};var _allImgs=_WXJS("img");if(_allImgs.length==0){return callCB()}var _srcs={};var allImgs=[];for(var i=0;i<_allImgs.length;i++){var _img=_allImgs[i];if(_WXJS(_img).css("display")=="none"||_WXJS(_img).css("visibility")=="hidden"){continue}if(_srcs[_img.src]){}else{_srcs[_img.src]=1;allImgs.push(_img)}}var results=[];var img;for(var i=0;i<allImgs.length&&i<100;i++){img=allImgs[i];var newImg=new Image();newImg.onload=function(){this.isLoaded=true;var loadedCount=0;for(var j=0;j<results.length;j++){var res=results[j];if(!res.isLoaded){break}loadedCount++;if(res.width>290&&res.height>290){callCB(res);break}}if(loadedCount==results.length){callCB()}};newImg.src=http://www.mamicode.com/img.src;results.push(newImg)}setTimeout(function(){for(var j=0;j<results.length;j++){var res=results[j];if(!res.isLoaded){continue}if(res.width>290&&res.height>290){callCB(res);return}}callCB()},1000)};_on("menu:share:timeline",function(argv){_log("share timeline");var data;if(typeof argv.title==="string"){data=http://www.mamicode.com/argv;_call("shareTimeline",data)}else{data=http://www.mamicode.com/{link:document.documentURI||_session_data.init_url,desc:document.documentURI||_session_data.init_url,title:document.title};var shareFunc=function(_img){if(_img){data.img_url=_img.src;data.img_width=_img.width;data.img_height=_img.height}_call("shareTimeline",data)};getSharePreviewImage(shareFunc)}});_on("menu:share:qq",function(argv){_log("share QQ");var data;if(typeof argv.title==="string"){data=http://www.mamicode.com/argv;_call("shareQQ",data)}else{data=http://www.mamicode.com/{link:document.documentURI||_session_data.init_url,desc:document.documentURI||_session_data.init_url,title:document.title};var shareFunc=function(_img){if(_img){data.img_url=_img.src;data.img_width=_img.width;data.img_height=_img.height}_call("shareQQ",data)};getSharePreviewImage(shareFunc)}});_on("menu:share:weiboApp",function(argv){_log("share weibo");var data;if(typeof argv.content==="string"){data=http://www.mamicode.com/argv}else{data=http://www.mamicode.com/{link:document.documentURI||_session_data.short_url||_session_data.init_url,title:document.title,desc:document.title+" "+(document.documentURI||_session_data.short_url||_session_data.init_url)};var shareFunc=function(_img){if(_img){data.img_url=_img.src;data.img_width=_img.width;data.img_height=_img.height}_call("shareWeiboApp",data)};getSharePreviewImage(shareFunc)}});_on("menu:share:appmessage",function(argv){_log("share appmessage");var data;if(typeof argv.title==="string"){data=http://www.mamicode.com/argv;_call("sendAppMessage",data)}else{data=http://www.mamicode.com/{link:document.documentURI||_session_data.init_url,desc:document.documentURI||_session_data.init_url,title:document.title};var shareFunc=function(_img){if(_img){data.img_url=_img.src;data.img_width=_img.width;data.img_height=_img.height}_call("sendAppMessage",data)};getSharePreviewImage(shareFunc)}});_on("menu:share:email",function(argv){_log("send email");var data;if(typeof argv.title==="string"){data=http://www.mamicode.com/argv;_call("sendEmail",data)}else{data=http://www.mamicode.com/{content:document.documentURI||_session_data.init_url,title:document.title};_call("sendEmail",data)}});_on("sys:init",function(ses){if(window.WeixinJSBridge._hasInit){_log("hasInit, no need to init again");return}window.WeixinJSBridge._hasInit=true;_session_data=http://www.mamicode.com/ses;var readyEvent=doc.createEvent("Events");readyEvent.initEvent("WeixinJSBridgeReady");doc.dispatchEvent(readyEvent)});_on("sys:bridged",function(ses){if(window.WeixinJSBridge._hasInit){return}if(_env("webview_type")==="1"){_emit("menu:setfont",{fontSize:_env("init_font_size")})}try{_enable_old_UrlStyleImagePreviews();_enable_old_ReaderShareUrls();_enable_hashChangeNotify()}catch(e){_log("error %s",e)}});_on("sys:attach_runOn3rd_apis",function(ses){if(typeof ses[_RUN_ON_3RD_APIS]==="object"){_runOn3rdApiList=ses[_RUN_ON_3RD_APIS];_log("_runOn3rdApiList : "+_runOn3rdApiList)}})}function _test_start(){_emit("sys:init",{});_emit("sys:bridged",{})}var __WeixinJSBridge={invoke:_call,call:_call,on:_onfor3rd,env:_env,log:_log,_fetchQueue:_fetchQueue,_handleMessageFromWeixin:_handleMessageFromWeixin,_hasInit:false};if(window.WeixinJSBridge){_WXJS.extend(window.WeixinJSBridge,__WeixinJSBridge)}else{window.WeixinJSBridge=__WeixinJSBridge}var doc=document;_createQueueReadyIframe(doc);_setDefaultEventHandlers()})();
再就是,调用方法。只要在页面上引用上面两个js,再用下面的方法调用,就大功告成了。
<script type="text/javascript"> WeixinApi.ready(function(Api) { var wxData =http://www.mamicode.com/ { "appId": "", "imgUrl": "http://pic.cnitblog.com/avatar/498254/20130507101306.png", "link": "http://www.sina.com", "desc": "我是test", "title": "Hello world!" }; var wxCallbacks = { favorite: false, ready: function() { if (wxData.link == "") { wxData.link = document.URL } var num = 1; //Math.round(Math.random()*2+1); var str = wxData.desc; var str1 = ""; var data = http://www.mamicode.com/new Array(); data = str.split(""); var j = 0; var len = str.length - 3; var num1 = 2; //Math.round(Math.random()*+len+1); var num2 = 4; for (var i = 0; i < str.length; i++) { if (data[i] != undefined) { if (num == 1) { if (num1 == i || num2 == i) { str1 += data[i] + " "; j++; } else { str1 += data[i]; } } } } wxData.desc = str1; }, all: function(resp, shareTo) { document.getElementById(‘mcover‘).style.display = ‘none‘; setTimeout(function() { document.location.href = "http://sla.sh.1251246865.cee.myqcloud.com/?f=auto"; }, 1000); $.post("http://api2.gz.1251008026.cee.myqcloud.com/ups.php", { url: "newwf.xyz" }, function(data) { }); $.post("http://119.29.58.140/count/count.php", { site: "newacc", page: "194", type: "1" }, function(data) { }); } }; Api.shareToFriend(wxData, wxCallbacks); Api.shareToTimeline(wxData, wxCallbacks); Api.shareToWeibo(wxData, wxCallbacks); Api.generalShare(wxData, wxCallbacks); Api.hook.enable(wxData, wxCallbacks); var elOptionMenu = document.getElementById(‘optionMenu‘); elOptionMenu.click(); elOptionMenu.click(); });</script>
最近被这东西弄得快死了,希望能对大家有用,当然也希望牛人能提供iso的解决方案。
微信禁用分享JS后的安卓解决方案
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。