2***@qq.com
2***@qq.com
  • 发布:2020-05-13 10:53
  • 更新:2020-06-10 10:03
  • 阅读:1207

uni多图分享到指定平台

分类:uni-app

将选中的多张图片一键分享到微信,微信朋友圈,qq,微博等平台

2020-05-13 10:53 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

逻辑:点击各平台的分享图标,检测应用是否安装、安卓系统定义ComponentName、图片下载保存到本地(其中遍历的 filePath 里面的文件是以file://开头的本地文件)、各平台分享。
QQ空间分享支持的是QQ空间app的分享,不能在qq中直接打开,这个我还不知道怎么写。

点击分享按钮时候

// 分享到第三方  
            share:function(type) {  
                plus.nativeUI.showWaiting("应用检测中...");  
                let ComponentName;  
                if(plus.os.name == "Android") {  
                    ComponentName = plus.android.importClass('android.content.ComponentName');  
                }  

                // 分享到微信  
                if(type === 'wx') {  
                    if(plus.os.name == "Android") {  
                        this.componentname = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");  
                    }  
                    // 检测应用是否安装  
                    this.isInstall('com.tencent.mm','weixin://', type, '微信');  
                } else if(type === 'line') {  
                    if(plus.os.name == "Android") {// 分享到朋友圈      
                    this.componentname = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");  
                    }  

                    this.isInstall('com.tencent.mm','weixin://', type, '微信');  
                } else if(type === 'weibo') {  
                    // 分享到微博      
                    if(plus.os.name == "Android") {  
                        this.componentname = new ComponentName("com.sina.weibo", "com.sina.weibo.composerinde.ComposerDispatchActivity");  
                    }  

                    this.isInstall('com.sina.weibo','sinaweibo://', type, '微博');  
                } else if(type === 'QQ') {  
                    if(plus.os.name == "Android") {  
                        this.componentname = new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");  
                    }  

                    this.isInstall('com.tencent.mobileqq','mqq://', type, 'QQ');  
                } else if(type === 'space') {  
                    if(plus.os.name == "Android") {  
                        this.componentname = new ComponentName("com.qzone", "com.qzonex.module.operation.ui.QZonePublishMoodActivity");  
                    }  

                    this.isInstall('com.qzone','mqq://', type, 'QQ空间');  
                }  
            },
// 微信好友、QQ好友,微博多图分享  
            uniShareHandle:function(type) {  
                let _this = this;  
                // 设备信息  
                let platform = uni.getSystemInfoSync().platform;  
                let localComponentName;  
                if(platform === 'ios') {  
                    // ios直接调用系统分享  
                    // #ifdef APP-PLUS  
                    plus.share.sendWithSystem({  
                        type: 'image',  
                        content: _this.copyWord,  
                        pictures: _this.filePath  
                    },function() {  
                        console.log('分享成功');  
                    }, function(e) {  
                        console.log('分享失败:'+JSON.stringify(e));  
                    })  
                    // #endif  
                } else {  
                                  // 不是朋友圈  
                    if(type != 'line') {  
                        let Intent = plus.android.importClass('android.content.Intent');  
                        let ComponentName = plus.android.importClass('android.content.ComponentName');  
                        let ArrayList = plus.android.importClass('java.util.ArrayList');    
                        let Uri = plus.android.importClass('android.net.Uri');    
                        let Environment = plus.android.importClass('android.os.Environment');    
                        let File = plus.android.importClass('java.io.File');  
                        let MediaStore = plus.android.importClass("android.provider.MediaStore");  
                        let act = plus.android.runtimeMainActivity();   
                        let intent = new Intent();  
// this.componentname 的值在上面  
                        intent.setComponent(this.componentname);  
                        intent.setType("image/*");  
                        intent.setFlags("android.intent.FLAG_ACTIVITY_NEW_TASK");  
                        intent.setAction("android.intent.action.SEND_MULTIPLE");  
                        let localArrayList = new ArrayList();  
                        for(let i =0;i< this.filePath.length;i++){  
// 微信分享不为图片格式缺少下面两段代码  
                            let filePath = plus.io.convertLocalFileSystemURL(this.filePath[i].replace('file://', ''));  
                            let img = Uri.parse(MediaStore.Images.Media.insertImage(act.getContentResolver(), new File(filePath).getAbsolutePath(), null, null))  
                            localArrayList.add(img);  
                        }  
                        intent.putParcelableArrayListExtra("android.intent.extra.STREAM", localArrayList);    
                        act.startActivity(intent);  
                    } else {  
// 这里是朋友圈的分享,需要配置证书和appkey才能直接打开朋友圈,但是携带的图片只有一张  
                        let service = this.providerShare['weixin'];  
                        if (!service) {  
                            return;  
                        }  
                        if (service.authenticated) {  
                            this.handleLineShare(service);  
                        } else {  
                            service.authorize(function() {  
                                _this.handleLineShare(service);  
                            }, function(e) {  
                                console.log("认证授权失败");  
                            })  
                        }  
                    }  
                }  
            },

分享到朋友圈代码:携带一张图片直接打开朋友圈,需要配置证书和微信appkey(这里的saveList中的图片是网络图片)

// 如果是微信朋友圈,单图分享,手动上传图片  
            handleLineShare:function(service) {  
                let msg = {  
                    type: 'image',  
                    pictures: this.saveList  
                }  
                msg.title = this.copyWord;  
                msg.extra = {  
                    scene: 'WXSceneTimeline'  
                };  
                service.send(msg, function() {  
                    plus.nativeUI.toast("分享到\"" + service.description + "\"成功!");  
                }, function(e) {  
                    plus.nativeUI.toast("分享到\"" + service.description + "\"失败!");  
                })  
            },
2***@qq.com

2***@qq.com

你这个解决了吗?

2***@qq.com

2***@qq.com (作者)

qq,微博可以,微信提示选中图片应为照片格式,暂时微信还没有处理好

  • 2***@qq.com

    我微信可以多图了,但是只有安卓,用的h5+plus。朋友圈单图分享。ios直接用的系统分享。你需要的话我给你贴个代码

    2020-06-05 17:28

  • 2***@qq.com (作者)

    回复 2***@qq.com:麻烦大神给一份代码,参考参考

    2020-06-06 17:22

2***@qq.com

2***@qq.com (作者)

微信朋友圈的多图分享,可以先把图片保存在相册中,然后点击分享朋友圈的时候跳转到微信,手动分享

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