sleepySnail 2018-06-22 02:42 采纳率: 0%
浏览 2272
已结题

h5+ plus.share 分享图片到QQ在 安卓机上报错,如何分享图片到安卓机?

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 {JSON} sb 分享操作对象s.s为分享通道对象(plus.share.ShareService)
  • @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();
}

  • 写回答

4条回答 默认 最新

  • sleepySnail 2018-06-22 02:48
    关注

    当不分享不传// href : curView.url,**(分享url)时
    报如下错误
    分享到"QQ"失败: {"code":-100,"message":"[ShareQQ分享:-6]非法的图片地址!, http://ask.dcloud.net.cn/article/287"}
    传href : curView.url时,分享出去的是图片的连接,现在要直接分享成图片而非链接地址,请问该怎么做

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序