mui.init();
var shares = null;
// H5 plus事件处理
function plusReady() {
updateSerivces();
}
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;
}
logDebug("------>" + JSON.stringify(shares));
}, function(ex) {
logError('获取分享服务列表失败:' + ex);
});
}
function share(share_id) {
logDebug(share_id);
if(share_id == "qq") {
shareAction(shares.qq)
}
if(share_id == "weixin") {
shares.weixin.x = 'WXSceneSession';
shareAction(shares.weixin)
}
if(share_id == "weixin_p") {
shares.weixin.x = 'WXSceneTimeline';
shareAction(shares.weixin)
}
if(share_id == "sinaweibo")
{
shareAction(shares.sinaweibo)
}
}
/**
@param {Boolean} bh 是否分享链接
*/
function shareAction(sb) {
var curView = plus.webview.currentWebview();
if(!sb) {
logDebug('无效的分享服务!');
return;
}
var share_content ='';
if(sb.id == "sinaweibo")
{
share_content=curView.title+"http://"+curView.url;
}
else
{
//分享时content太长会报错,此处加上截断处理,保留80个字符
if(curView.content.length > 80) {
share_content=curView.content.substr(0,80);
} else {
share_content=curView.content;
}
}
var msg = {
title : curView.title,
content:share_content,
// href : curView.url,
pictures: ['http://10.133.64.34:8091/static/img/code.jpg'],
sharetype : curView.sharetype,
sharepkey : curView.sharepkey,
thumbs : [curView.thumbs],
extra: {
scene: sb.x
}
};
console.log('<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
console.log(JSON.stringify(msg));
// 发送分享
if(sb.authenticated) {
logDebug('---已授权---');
shareMessage(msg, sb);
} else {
logDebug('---未授权---');
sb.authorize(function() {
shareMessage(msg, sb);
}, function(e) {
logDebug('认证授权失败:' + e.code + ' - ' + e.message);
});
}
}
/**
发送分享消息
@param {JSON} msg
@param {plus.share.ShareService} shareServiceIns
*/
function shareMessage(msg, shareIns) {
logDebug(JSON.stringify(msg));
console.log("--------->"+msg.href);
console.log("--------->"+msg.title);
console.log("--------->"+msg.sharetype);
console.log("--------->"+msg.artcleid);
var post_data = {
'NSHAREPKEY': msg.sharepkey,
'VSHARETYPE': msg.sharetype,
'VSHAREHREF': msg.href,
'uuid': plus.device.uuid
};
callAjaxService('/SysCommon/SaveUserShare', post_data, function(){},0);
console.log(msg.content);
shareIns.send(msg, function() {
logDebug('分享到"' + shareIns.description + '"成功!');
}, function(e) {
logDebug('分享到"' + shareIns.description + '"失败: ' + JSON.stringify(e));
});
}
function closeShare() {
plus.webview.currentWebview().close();
}
当不分享不传// href : curView.url,**(分享url)时
报如下错误
分享到"QQ"失败: {"code":-100,"message":"[ShareQQ分享:-6]非法的图片地址!, http://ask.dcloud.net.cn/article/287"}
传href : curView.url时,分享出去的是图片的连接,现在要直接分享成图片而非链接地址,请问该怎么做
可以参考buptlzx的博客地址如下:https://blog.csdn.net/buptlzx/article/details/9767203
希望能有帮助
哪位能提供h5+ send 方法的源码啊?我觉得是send方法里对分享图片到QQ做了一下校验,校验没通过,所以返回了 -6“非法的图片地址”,
提供看 send方法的源码的方法或者源码可以给分啊,哪位大神回答一下
自己已解决,是QQ不支持网路图片地址,需要给api传本地图片地址,是file///:开头的路径,具体可以参考5+的地址转换方法
requestFileSystem: 请求本地文件系统对象
resolveLocalFileSystemURL: 通过URL参数获取目录对象或文件对象
convertLocalFileSystemURL: 将本地URL路径转换成平台绝对路径
convertAbsoluteFileSystem: 将平台绝对路径转换成本地URL路径