html5plus分享功能
1》使用系统分享功能,这个分享经测试(202006月)只能分享文字,不能分享图片。毕竟这不需要任何appid,还可以接受。
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready", plusReady, false);
}
// 扩展API准备完成后要执行的操作
function plusReady(){
//分享内容,开发者可自定义
var message = {
type:"text",
title: "plusShare示例", //应用名字
content: "plusShare基于HTML5+的share模块,开发者只需调用一个API,即可调起微信好友、微信朋友圈、系统更多分享功能",
href: "http://www.dcloud.io/hellomui", //分享出去后,点击跳转地址
thumbs: ["http://img-cdn-qiniu.dcloud.net.cn/icon3.png"],//分享缩略图
pictures : ["http://img-cdn-qiniu.dcloud.net.cn/icon3.png"]
};
plus.share.sendWithSystem( message, function(){
$(".ht-bar .text").html("分享ok");
}, function(e){
plus.nativeUI.toast("分享失败!"+e.code+"-"+e.message);
} ); }
2>使用注册的分享,所谓注册,就是在QQ开放平台,微信开放平台注册过,已有appid的
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready", plusReady, false);
}
// 扩展API准备完成后要执行的操作
function plusReady(){
plus.share.getServices(function(ss) {
var str="";
var qq='';
for (var i in ss ) {
var s = ss[i];
str += s.id;
if(s.id == "qq"){
qq = s;
}
}
$(".ht-bar .text").html(str);
if (qq.authenticated) {
//alert("---已授权---");
shareMessage(qq, 'ex');
} else {
alert("---未授权---");
qq.authorize(function() {
shareMessage(qq, 'ex');
}, function(e) {
alert("认证授权失败:" + e.code + " - " + e.message);
});
}
//
}, function(e) {
alert("获取分享服务列表失败:" + e.message);
});
function shareMessage(s,ex){
var msg={
content:"hello",
href:"http://www.xxx.com/mdu/index/index",
type:'text',
title:'mdu'
};
s.send( msg, function(){
alert( "分享到\""+s.description+"\"成功! " );
}, function(e){
alert( "分享到\""+s.description+"\"失败: "+e.code+" - "+e.message );
} );
}
}
文档说明: https://www.html5plus.org/doc/zh_cn/share.html#plus.share.sendWithSystem

浙公网安备 33010602011771号