复制代码
var shares=null;
var Intent=null,File=null,Uri=null,main=null;
function plusReady(){
updateSerivces();
if(plus.os.name=="Android"){
main = plus.android.runtimeMainActivity();
Intent = plus.android.importClass("android.content.Intent");
File = plus.android.importClass("java.io.File");
Uri = plus.android.importClass("android.net.Uri");
}
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
function updateSerivces(){
plus.share.getServices( function(s){
shares={};
for(var i in s){
var t=s[i];
shares[t.id]=t;
}
}, function(e){
alert("获取分享服务列表失败:"+e.message );
} );
}
function shareAction(sb,bh) {
if(!sb||!sb.s){
alert("无效的分享服务!");
return;
}
var msg={content:sharehrefDes.value,extra:{scene:sb.x}};
if(bh){
msg.href=sharehref.value;
if(sharehrefTitle&&sharehrefTitle.value!=""){
msg.title=sharehrefTitle.value;
}
if(sharehrefDes&&sharehrefDes.value!=""){
msg.content=sharehrefDes.value;
}
msg.thumbs=["_www/logo.png"];
msg.pictures=["_www/logo.png"];
}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){
alert("认证授权失败:"+e.code+" - "+e.message );
});
}
}
function shareMessage(msg,s){
s.send( msg, function(){
alert("分享到\""+s.description+"\"成功! " );
}, function(e){
alert( "分享到\""+s.description+"\"失败: "+JSON.stringify(e) );
} );
}
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['qq'];
ss&&ss.nativeClient&&shareBts.push({title:'QQ空间',s:ss});
ss&&ss.nativeClient&&shareBts.push({title:'腾讯微博',s:ss});
ss&&ss.nativeClient&&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('当前环境无法支持分享链接操作!');
}
function settoken(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
5 个回复
[已删除]
我会,联系我既可!
[已删除]
qq:550707177
7***@qq.com
复制代码
var shares=null; var Intent=null,File=null,Uri=null,main=null; // H5 plus事件处理 function plusReady(){ updateSerivces(); if(plus.os.name=="Android"){ main = plus.android.runtimeMainActivity(); Intent = plus.android.importClass("android.content.Intent"); File = plus.android.importClass("java.io.File"); Uri = plus.android.importClass("android.net.Uri"); } } if(window.plus){ plusReady(); }else{ document.addEventListener("plusready",plusReady,false); } /** * * 更新分享服务 */ function updateSerivces(){ plus.share.getServices( function(s){ shares={}; for(var i in s){ var t=s[i]; shares[t.id]=t; } }, function(e){ alert("获取分享服务列表失败:"+e.message ); } ); } /** * 分享操作 * @param {JSON} sb 分享操作对象s.s为分享通道对象(plus.share.ShareService) * @param {Boolean} bh 是否分享链接 */ function shareAction(sb,bh) { if(!sb||!sb.s){ alert("无效的分享服务!"); return; } var msg={content:sharehrefDes.value,extra:{scene:sb.x}}; if(bh){ msg.href=sharehref.value; if(sharehrefTitle&&sharehrefTitle.value!=""){ msg.title=sharehrefTitle.value; } if(sharehrefDes&&sharehrefDes.value!=""){ msg.content=sharehrefDes.value; } msg.thumbs=["_www/logo.png"]; msg.pictures=["_www/logo.png"]; }else{ if(pic&&pic.realUrl){ msg.pictures=[pic.realUrl]; } } // 发送分享 if ( sb.s.authenticated ) { // alert("---已授权---"); shareMessage(msg,sb.s); } else { // alert("---未授权---"); sb.s.authorize( function(){ shareMessage(msg,sb.s); },function(e){ alert("认证授权失败:"+e.code+" - "+e.message ); }); } } /** * 发送分享消息 * @param {JSON} msg * @param {plus.share.ShareService} s */ function shareMessage(msg,s){ // alert(JSON.stringify(msg)); s.send( msg, function(){ alert("分享到\""+s.description+"\"成功! " ); }, function(e){ alert( "分享到\""+s.description+"\"失败: "+JSON.stringify(e) ); } ); } // 分析链接 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['qq']; ss&&ss.nativeClient&&shareBts.push({title:'QQ空间',s:ss}); ss&&ss.nativeClient&&shareBts.push({title:'腾讯微博',s:ss}); ss&&ss.nativeClient&&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('当前环境无法支持分享链接操作!'); } function settoken(c_name,value,expiredays) { var exdate=new Date() exdate.setDate(exdate.getDate()+expiredays) document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) }
[已删除] (作者)
能帮忙 弄下吗 可以付费
2019-04-24 22:46
7***@qq.com
回复 [已删除]: 付费不必,,不会扫码只会原生分享
2019-04-24 22:52
[已删除] (作者)
回复 7***@qq.com: 谢谢
2019-04-25 08:40
7***@qq.com
全局放我上面的分享代码
吧需要分享的放到input里
我比较懒
复制代码
<input type="hidden" id="sharehref" type="url" value="http://shop.mxin.ltd/bbs/forum.php?mod=viewthread&tid={$thread[tid]}&mobile=2" /> <input type="hidden" id="sharehrefTitle" type="text" value="{$_G[forum_thread][subject]}" /> <input type="hidden" id="sharehrefDes" type="text" value="<!--{eval $neirong = DB::result_first('SELECT `message` FROM '.DB::table('forum_post').' WHERE `tid` ='.$_GET[tid]);}--> <!--{eval echo$neirong; }-->"/>
网址标题简介
谢家兴
web2app是要引入js的吧 找不到引入什么js啊
2019-11-04 16:09
谢家兴
求救援
2019-11-04 16:09
7***@qq.com
2处代码加起来已经完整了,动态网页需要分享的东西放到input里就行了或者你自己js获取