微信分享给好友
手机微信里,分享给好友时,在当前页面指定分享的URL和图片
function share_scene(link, scene_type){ var extargs = ""; if (tid != ""){//gdt traceid extargs = "tid=" + tid + "&aid=" + 54;//share must be 54 } var queryStr = link.split('?')[1] || ''; queryStr = queryStr.split('#')[0]; if( queryStr == '' ){ return; } var queryarr = [queryStr, 'scene='+scene_type]; (extargs != "") && (queryarr.push(extargs)); queryStr = queryarr.join('&'); return link.split('?')[0] + '?' + queryStr + '#' + (link.split('#')[1]||''); } function onBridgeReady(){ // 发送给好友; //安卓分享时会调用此函数 WeixinJSBridge.on('menu:share:appmessage', function(argv){ WeixinJSBridge.invoke('sendAppMessage',{ "appid" : appId, "img_url" : imgUrl, "img_width" : "640", "img_height" : "640", "link" : share_scene(link, 1), "desc" : desc, "title" : title }, function(res) { }); }); // 新的接口 //苹果分享时会调用此函数 WeixinJSBridge.on('menu:general:share', function(argv){ var scene = 0; switch(argv.shareTo){ case 'friend' : scene = 1; break; case 'timeline': scene = 2; break; case 'weibo' : scene = 3; break; } argv.generalShare({ "appid" : appId, "img_url" : imgUrl, "img_width" : "640", "img_height" : "640", "link" : share_scene(link,scene), "desc" : desc, "title" : title }, function(res){ }); }); } if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ onBridgeReady(); }
相关推荐
戴翔的技术 2020-05-18
齐天大圣数据候 2020-05-16
过时不侯的温暖 2020-05-08
浪味仙 2020-04-20
戴翔的技术 2020-03-04
zengfanpei 2020-02-20
cbao 2020-02-14
xiaonao00 2020-01-02
xiaonao00 2019-12-25
cbao 2019-12-12
浪味仙 2019-12-10
maodouhuasheng 2019-12-04
且听真言 2019-12-01
ywwazyj 2019-11-15
badroot 2019-11-18
badroot 2019-11-17
zhichijunjun 2019-11-13
wjeymiantan 2019-11-07