html微博分享功能实现,MUI 分享功能(微信、QQ 、微博、朋友圈等)实现方法

该博客详细介绍了如何在移动应用中配置和实现分享功能,包括在manifest.json中设置QQ和微信的分享配置,以及在HTML代码中处理H5Plus事件,实现分享服务的获取和分享操作。同时,提供了分享链接的分析和弹出分享列表的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置文件:manifest.json(plus ->plugins 下边);

"share": {/*配置应用使用分享功能,参考:http://ask.dcloud.net.cn/article/27/

"qq": {

"appid": "",/*腾讯QQ开放平台申请应用的AppID值*/

"description": "QQ分享"

},

"weixin": {

"appid": "",/*微信开放平台申请应用的AppID值*/

"appsecret": "",/*微信开放平台申请应用的AppSecret值*/

"description": "微信分享"

}

},

html 代码文件

首页

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});

// 弹出分享列表

shareBts.length>0?plus.nativeUI.actionSheet({title:'分享链接',cancel:'取消',buttons:shareBts},function(e){

(e.index>0)&&shareAction(shareBts[e.index-1],true);

}):plus.nativeUI.alert('当前环境无法支持分享链接操作!');

}

链接地址:

链接标题:

链接描述:

分享链接

400b0b5dedbaf143422db7064ed3f540.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值