/** * * 更新分享服务 */ function updateSerivces(){ plus.share.getServices( function(s){ shares={}; for(var i in s){ var t=s[i]; shares[t.id]=t; } }, function(e){ plus.nativeUI.alert("获取分享服务列表失败:"+e.message ); } ); } /** * 分享操作 * @param {JSON} sb 分享操作对象s.s为分享通道对象(plus.share.ShareService) * @param {Boolean} bh 是否分享链接 */ function shareAction(sb,bh) { if(!sb||!sb.s){ plus.nativeUI.alert("无效的分享服务!"); return; } var msg={content:sharehrefDes,extra:{scene:sb.x}}; if(bh){ msg.href=shareUrl; if(sharehrefTitle&&sharehrefTitle!=""){ msg.title=sharehrefTitle; } if(sharehrefTitle&&sharehrefTitle!=""){ if(sb.title=="新浪微博"){ msg.content=shareUrl+"\t"+sharehrefTitle; }else{ msg.content=sharehrefTitle; } } msg.thumbs=[picUrl]; msg.pictures=[picUrl]; }else{ if(pic&&pic.realUrl){ msg.pictures=[pic.realUrl]; } } // 发送分享 if ( sb.s.authenticated ) { shareMessage(msg,sb.s); } else { sb.s.authorize( function(){ shareMessage(msg,sb.s); },function(e){ plus.nativeUI.alert("认证授权失败:"+e.code+" - "+e.message ); }); } } /** * 发送分享消息 * @param {JSON} msg * @param {plus.share.ShareService} s */ function shareMessage(msg,s){ s.send( msg, function(){ plus.nativeUI.alert("分享到\""+s.description+"\"成功! " ); }, function(e){ console.log(e.code+"========="+e.message) plus.nativeUI.alert( "分享到\""+s.description+"\"失败 !"); } ); } // 分析链接 function shareHref(){ var shareBts=[]; // 更新分享列表 var ss=shares['weixin']; ss&&ss.nativeClient&&(shareBts.push({title:'微信朋友圈',s:ss,x:'WXSceneTimeline'}), shareBts.push({title:'微信好友',s:ss,x:'WXSceneSession'})); /* ss=shares['qq']; ss&&ss.nativeClient&&shareBts.push({title:'QQ',s:ss}); ss=shares['sinaweibo']; ss&&shareBts.push({title:'新浪微博',s:ss});*/ // 弹出分享列表 shareBts.length>0?plus.nativeUI.actionSheet({title:'分享链接',cancel:'取消',buttons:shareBts},function(e){ (e.index>0)&&shareAction(shareBts[e.index-1],true); }):plus.nativeUI.alert('当前环境无法支持分享链接操作!'); }