收藏
回答

鸿蒙微信通过uri方式分享图片跳转微信后提示参数非法,请问是何原因?

背景:鸿蒙分享作为三方SDK包使用,使用uri分享失败

问题:鸿蒙图片类型分享【图片本地路径的uri类型】,如果不使用base64,转而使用uri分享,uri的标准地址格式是什么?为何我传递uri分享时,跳转微信后提示参数非法?我是通过showAssetsCreationDialog生成uri的。又或者说应该存放于哪个路径所以请老师能够帮忙分析解答(主要代码见下面)

备注:之前技术老师在其他的贴子发的内容我看到了比如这个的:

https://developers.weixin.qq.com/community/minihome/doc/00088adfb140f80d65a3ad11561000


  async savePixelMapWithDialog(

    pixelMap: image.PixelMap,

    fileName?: string,

    quality: number = 90

  ): Promise<string> {

    try {

      const cxt = PlayerViewModel.context;

      if (!cxt) {

        return "";

      }

      const context = cxt;


      const imagePacker = image.createImagePacker();

      const arrayBuffer = await imagePacker.packToData(pixelMap, {

        format: "image/png",

        quality: quality

      });



      const timestamp = Date.now();

      const tempFileName = fileName ? `${fileName}_${timestamp}.png` : `image_${timestamp}.png`;

      const tempFilePath = `${context.cacheDir}/${tempFileName}`;



      const file = await fileIo.open(tempFilePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);

      await fileIo.write(file.fd, arrayBuffer);

      fileIo.closeSync(file);

      let mediaUri: string = fileUri.getUriFromPath(tempFilePath)



      let photoCreationConfigs: photoAccessHelper.PhotoCreationConfig[] = [{

        fileNameExtension: 'png',

        photoType: photoAccessHelper.PhotoType.IMAGE

      }];


      const phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);



      let desFileUris: string[] = await phAccessHelper.showAssetsCreationDialog([mediaUri], photoCreationConfigs);


      if (desFileUris.length === 0) {

        await fileIo.unlink(tempFilePath);

        return "";

      }



      let desFile = await fileIo.open(desFileUris[0], fileIo.OpenMode.WRITE_ONLY);

      let srcFile = await fileIo.open(tempFilePath, fileIo.OpenMode.READ_ONLY);

      await fileIo.copyFile(srcFile.fd, desFile.fd);

      fileIo.closeSync(srcFile);

      fileIo.closeSync(desFile);



      await fileIo.unlink(tempFilePath);


      promptAction.showToast({ message: '图片保存成功' });

      return desFileUris[0];


    } catch (err) {

      promptAction.showToast({ message: '保存失败,请重试' });

      return "";

    }

  }


  private async shareImage() {

    if (!this.imageUrl) {

      return;

    }

    if (!PlayerViewModel.context) {

      return;

    }

    let imageObject = new wxopensdk.WXImageObject

    imageObject.uri = this.imageUrl;


    let mediaMessage = new wxopensdk.WXMediaMessage()

    mediaMessage.mediaObject = imageObject


    let req = new wxopensdk.SendMessageToWXReq()

    req.scene = wxopensdk.SendMessageToWXReq.WXSceneSession

    req.message = mediaMessage;


    WXApi.sendReq(PlayerViewModel.context as common.UIAbilityContext, req);

  }


回答关注问题邀请回答
收藏

1 个回答

  • 社区技术运营专员--许涛
    社区技术运营专员--许涛
    2025-10-23

    你好,复现问题时麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点,bundleid、identifier、appid和opensdk的调用时间点(可以社区私信提供)和open帐号后台移动应用签名包名截图,私信后请在评论区回复

    2025-10-23
    有用
    回复 2
登录 后发表内容