App测试Jin小号

mui分享到朋友圈

电脑版发表于:2019/11/25 12:55

mui分享操作

首先给点击事件一个id或者class标识 -->share


然后我们直接写js代码


//分享操作
var shares = {};
mui.plusReady(function() {
plus.share.getServices(function(s) {
if (s && s.length > 0) {
for (var i = 0; i < s.length; i++) {
var t = s[i];
shares[t.id] = t;
}
}
}, function() {
console.log("获取分享服务列表失败");
});
});
 //分享链接点击事件
mui("body").on("tap",".share",function(){
var ids = [{
id: "weixin",
ex: "WXSceneSession"
}, {
id: "weixin",
ex: "WXSceneTimeline"
}, {
id: "qq"
}],
bts = [{
title: "分享给微信好友"
}, {
title: "分享到朋友圈"
}, {
title: "分享到QQ好友"
}];
plus.nativeUI.actionSheet({
cancel: "取消",
buttons: bts
}, function(e) {
var i = e.index;
if (i > 0) {
var s_id = ids[i - 1].id;
var share = shares[s_id];
if (share.authenticated) {
shareMessage(share, ids[i - 1].ex);
} else {
share.authorize(function() {
shareMessage(share, ids[i - 1].ex);
}, function(e) {
console.log("认证授权失败:" + e.code + " - " + e.message);
});
}
}
});
});
function shareMessage(share, ex) {
var aticleContent=$("body").find(".aticleContent").text();
var msg = {
extra: {
scene: ex
}
};
msg.href = "http://www.xxxx/"+usernames+"/article/details/"+aticleid;//链接URL
msg.title = $("body").find(".aticleTitle").html();//分享链接的标题
msg.content = aticleContent.substring(0,100);//这是再要内容
//msg.thumbs是缩略图
msg.thumbs = ["https://gss0.baidu.co9a901f201.jpg"];
share.send(msg, function() {
console.log("分享到\"" + share.description + "\"成功! ");
}, function(e) {
console.log("分享到\"" + share.description + "\"失败: " + e.code + " - " + e.message);
});
}



关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢