TomVision
TomVision
  • 发布:2016-07-26 09:09
  • 更新:2016-07-26 09:28
  • 阅读:3259

无法分享给微信好友

分类:HTML5+
var shares = null,  
        bhref = false;  
    var Intent = null,  
        File = null,  
        Uri = null,  
        main = null;  

    mui.plusReady(function() {  
        vm.service = plus.webview.currentWebview().service;  

        updateSerivces();  
        if (plus.os.name == "Android") {  
            Intent = plus.android.importClass("android.content.Intent");  
            File = plus.android.importClass("java.io.File");  
            Uri = plus.android.importClass("android.net.Uri");  
            main = plus.android.runtimeMainActivity();  
        }  

        /**  
         * 更新分享服务  
         */  
        function updateSerivces() {  
            plus.share.getServices(function(s) {  
                shares = {};  
                for (var i in s) {  
                    var t = s[i];  
                    shares[t.id] = t;  
                }  
            }, function(e) {  
                console.log("获取分享服务列表失败:" + e.message);  
            });  
        }  

        /**  
         * 分享操作  
         * @param {String} id  
         */  
        function shareAction(id, ex) {  
            var s = null;  
            console.log("分享操作:");  
            if (!id || !(s = shares[id])) {  
                console.log("无效的分享服务!");  
                return;  
            }  
            if (s.authenticated) {  
                console.log("---已授权---");  
                shareMessage(s, ex);  
            } else {  
                console.log("---未授权---");  
                s.authorize(function() {  
                    shareMessage(s, ex);  
                }, function(e) {  
                    console.log("认证授权失败:" + e.code + " - " + e.message);  
                });  
            }  
        }  
        /**  
         * 发送分享消息  
         * @param {plus.share.ShareService} s  
         */  
        function shareMessage(s, ex) {  
            var title = $('.apponit-title').text();  
            s.send({  
                thumbs: '../img/logo.png',  
                pictures: '../img/logo.png',  
                title: '睿翔云家' + title,  
                content:'content',  
                href: app_addr+"share/index.html?serviceId="+vm.service.id  
            }, function() {  
                console.log("分享到\"" + s.description + "\"成功! ");  
            }, function(e) {  
                console.log("分享到\"" + s.description + "\"失败: " + e.code + " - " + e.message);  
            });  
        }  

        // 打开分享  
        function shareShow() {  
            bhref = false;  
            var ids = [{  
                    id: "weixin",  
                    ex: "WXSceneSession"  
                }, {  
                    id: "weixin",  
                    ex: "WXSceneTimeline"  
                }],  
                bts = [{  
                    title: "发送给微信好友"  
                }, {  
                    title: "分享到微信朋友圈"  
                }];  
            plus.nativeUI.actionSheet({  
                    cancel: "取消",  
                    buttons: bts  
                },  
                function(e) {  
                    var i = e.index;  
                    if (i > 0) {  
                        shareAction(ids[i - 1].id, ids[i - 1].ex);  
                    }  
                }  
            );  
        }  

        //分享  
        $('.share').on('tap', function() {  
            shareShow()  
        })  
    });

分享给好友和朋友圈点击后都是跳转到朋友圈了,无法分享给好友

2016-07-26 09:09 负责人:无 分享
已邀请:

最佳回复

TomVision

TomVision (作者)

已解决 shareMessage s.send时未传入ex

Trust

Trust - 少说废话

请上传完整的可以还原场景的项目源码。

该问题目前已经被锁定, 无法添加新回复