微信禁用分享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=holder[key];if(typeof rep==="function"){value=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=holder[key];if(value&&typeof value==="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={},_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=_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.href==="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=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=argv;_call("shareTimeline",data)}else{data={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=argv;_call("shareQQ",data)}else{data={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=argv}else{data={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=argv;_call("sendAppMessage",data)}else{data={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=argv;_call("sendEmail",data)}else{data={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=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 = {
            "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 = 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的解决方案。

时间: 2024-10-22 18:56:53

微信禁用分享JS后的安卓解决方案的相关文章

用微信浏览器调整字体后页面错位解决方案

普通解决方案: android暂无方案: ios使用-webkit-text-size-adjust禁止调整字体大小 body{-webkit-text-size-adjust: 100%!important;} 最好的解决方案: 整个页面用rem或者百分比布局 如果html5页面特效多比较,建议开启硬件加速: .css { -webkit-transform: translate3d(0, 0, 0); -moz-transform: translate3d(0, 0, 0); -ms-tra

IOS微信禁用分享跳转页面返回BUG修复

1 fresh(); 2 function fresh() { 3 let isPageHide = false; 4 window.addEventListener('pageshow', function () { 5 if (isPageHide) { 6 window.location.reload(); 7 } 8 }); 9 window.addEventListener('pagehide', function () { 10 isPageHide = true; 11 }); 1

微信分享JS接口失效说明及解决方案

关键字:微信分享 JS 失效  分享到朋友圈 微信分享JS接口目前已失效,以前可以自定义分享的标题.描述.图片.链接地址在微信6.0.2版本中失效. 官方回复如下: 旧版的获取分享状态及设置分享内容的JS接口一直用于内部业务,并未对外开放,在微信公开的开放文档里面并没有此接口. 某些第三方借助微信客户端漏洞在未获得权限的情况下使用接口,微信6.0.2版本对此漏洞做了修复以确保用户分享内容的准确性,避免诱导分享. 另外,不久将向广大公众号开放正式分享接口供开发者使用. 临时解决方案: 标题:修改<

浏览器禁用Js后解决方案

一,浏览器禁用js的方法 二,浏览器禁用了 js 阻止其提交的解决方案  UseSubmitBehavior="false" 对于禁用js,可以使用:UseSubmitBehavior="false" 来避免这样禁用了js,就不能提交页面了. <input name="" id="btn" type="submit" UseSubmitBehavior="false" onclic

微信公众平台Js API实现微信分享

今天上班第一天,Boss让实现微信分享后,要知道用户是否分享成功,分享成功后就给用户一个surprise(游戏礼包). 通过查看API,做简单记录: 1.编写一个简单的jsp页面,加入如下JS代码: // 开发阶段,开启WeixinApi的调试模式 WeixinApi.enableDebugMode(); // 初始化WeixinApi,等待分享 WeixinApi.ready(function(Api) { // 微信分享的数据 var wxData = { "appId": &qu

微信朋友圈分享js代码最新2015年无错版

最近微信对分享做了进一步规范,导致很多分享都不起作用了,今天跟大家分享,2015年最新修无错的! 以下是主要微信分享页面代码:(其中红色部分主要懒友自己填写自己哈.) <?php require_once "jssdk.php"; $jssdk = new JSSDK("yourAppID", "yourAppSecret"); $signPackage = $jssdk->GetSignPackage(); ?> <!D

微信JSSDK分享--挖坑填坑之小结

最近参与微信服务号小项目的开发,关于微信分享,我是只知其功能,并没深入了解其中的弯弯道道.虽然项目中不是我负责微信分享这一块(因为我也不太会),但是团队在这个功能上,那可是说多了都是泪,耗费了超级多的时间:一句话就是加班加点的挖坑,制造解决不了的bug,然后加班加点的找问题所在,去解决.主要是我们对于微信分享这块的了解并不深入,没想到的太多. 当时一直分享不成功,我们前端一直以为是我们的js代码写的有问题,谁知道最大的问题是配置问题: 一.不再同一个服务号. 因为微信端,为了识别用户,每个用户针

微信网页分享标题图片自定义设置(最新)

1 前言 刚好有微信网页分享标题图片自定义设置这个需求,然后查找文档,发现有两种方案[1],但是第一种方案已经失效了,只能走第二种方案,然后根据实战配置好了,本文会写上配置中遇到的问题和解决方案,也作为记录使用,方便自己也方便他人. 2 步骤 2.1 准备工作 2.1.1 微信JS-SDK说明文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115 2.1.2 附录6-DEMO页面和示例代码:在JS-SDK说明文档中

微信内分享链接在推广的时候如何防封的常见问题解答

针对微信转发分享链接过程中,您宝贵的域名被微信检测系统过滤拦截而无法正常浏览,例如该网页包含诱导分享内容,被多人投诉等,又例如提示该网页已停止访问等提示.域名防封的原理就是能快速及时地绕过检测系统,让你的域名在微信内始终保持可访问的状态.以达到减少推广成本,提高推广效率的目的. 那么我们分析的时候应该从哪些方面去着手分析呢?今天就为大家分析一下拦截原理和解决方案,请看下文. 首先我们要知道为什么我们的域名会被微信封,然后从拦截因素逐条解决. 域名被拦截因素 1.项目竞争大,同行举报过多. 2.网