首页 > 技术文章 > h5+ 分享到"QQ"失败: {"code":-100,"message":"[ShareQQ分享:-6]非法的图片地址!, http://ask.dcloud.net.cn/article/287"}

fanqiuzhuji 2020-06-19 19:15 原文

原因:

QQ不支持网路图片地址,需要给api传本地图片地址,是file///:开头的路径,具体可以参考5+的地址转换方法
requestFileSystem: 请求本地文件系统对象

resolveLocalFileSystemURL: 通过URL参数获取目录对象或文件对象

convertLocalFileSystemURL: 将本地URL路径转换成平台绝对路径

convertAbsoluteFileSystem: 将平台绝对路径转换成本地URL路径

 

 if (a == 'qq') {
          $(function() {
            mui.plusReady(function() {
              console.log(' mui.plusReady执行了')
              // plus.io.resolveLocalFileSystemURL('_www/static/img/android.png', function(entry) {//安卓
              plus.io.resolveLocalFileSystemURL('_www/static/img/ios.png', function(entry) {//ios
                let pictures = [];
                var dirReader = entry.toLocalURL();
                pictures.push(dirReader);
                console.log(pictures,'绝对路径')
                let qq_msg = {
                  type: 'image', //分享的内容的类型
                  pictures:pictures,
                }
                plus.nativeUI.actionSheet({
                  title: '分享图片到QQ',
                  cancel: '取消',
                  buttons: _this.buttons1,
                }, function(e) {
                  (e.index > 0) && _this.sharePage(_this.sqq, qq_msg, _this.buttons[e.index - 1]);
                })
              }, function(e) {
                alert('路径或文件不存在')
              });
            })
          })
        }

 

推荐阅读