upShareModule 分享模块

模块概述

分享模块为H5页面提供分享第三方平台能力。


方法列表

  • showShareView (显示分享面板,uplusapi 4.0.0版本废弃该接口)
  • share (特定平台分享)
  • shareWechatMiniProgram (App分享微信小程序)

公共数据

  • 所有数据均以JSON结构返回,由代码,信息和数据三部分组成
    {
      "retCode": "000000", //接口状态标识码,错误标识码以29开头
      "retInfo": "操作成功",//接口信息说明
      "retData": null //业务数据
    }
    

具体定义:返回数据通用


模块变更记录

  • V3.0.0

    • 模块名由umshareModule更改为upShareModule
  • V3.2.0

    • 分享模块未定义的retCode编码按照通用数据规定变为990001,操作失败retCode变为000001,非法参数错误retCode变为000002
  • V4.0.0

    • 废弃showShareView接口,不在提供该接口的功能维护。

方法说明

  • showShareView (显示分享面板)

    showShareView({params})
分享面板说明

分享面板

  • 分享类型为webPage的面板支持4种功能
    1.将网页分享给微信好友
    2.将网页分享到微信朋友圈
    3.将网页分享到新浪微博
    4.在手机浏览器中打开网页

分享面板

  • 分享类型为image的面板目前支持3种功能
    1.把图片分享给微信好友
    2.把图片分享到微信朋友圈
    3.把图片分享到新浪微博
适用性
容器 cordova APICloud Nebula
支持情况
APP版本 5.8.0 及以上 5.8.0 及以上 6.12.0 及以上
params 输入参数:
属性名 数据类型 说明
shareType String 分享类型 webPage 或者 image
thumImage String 缩略图 如 'https://', 'file://'
title String 分享类型为webPage时,要分享的网页的标题 ;分享类型为image时不需填"标题"
url String 分享类型为webPage时,要分享的网页的URl;分享类型为image时不需填写
desc String 分享类型为webPage时,要分享的网页的描述信息;分享类型为image时不需填"描述信息"
image String 分享类型为image时的image路径,如 'http://', 'https://', 'file://',也可以为base64编码的字符串;分享类型为webPage时不需填写

参数补充说明: shareType为“webPage”时:参数url、thumImage必填;title、desc选填(建议填写,否则第三方可能会有默认文案);
shareType为“image”时:参数image必填;参数thumImage选填(建议填写,否则会导致分享拉起速度慢等问题);
特别注意:iOS平台网络图片类型只能用https格式。

错误返回 retCode说明:
retCode编码 retInfo说明
150001 应用未安装
000001 分享失败
特别说明:在第三方平台取消分享,接口仍然会返回分享成功的结果。
示例

调用方式

uplusapi.upShareModule.showShareView({
  title:"百度",
  desc:"百度首页",
  url:"http://www.baidu.com",
  thumImage:"",
  shareType:"webPage"
}).then((result) =>console.log('result',result));

成功返回结果

{
  "retCode": "000000",
  "retInfo": "分享成功",
  "retData": null
}
  • share (特定平台分享)

    share({params})
特定平台分享说明
  • 特定平台分享方法在 showShareView (显示分享面板)方法的基础上增加【平台类型】(platformType)参数,从而不需要调起多选项的分享面板,而是可以直接将要分享的内容在特定平台针对性分享。
适用性
容器 cordova APICloud Nebula
支持情况
APP版本 6.4.0 及以上 6.4.0 及以上 6.12.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
platformType String 平台类型: Sina(新浪) WechatSession(微信聊天)WechatTimeLine(微信朋友圈) WechatFavorite(微信收藏) QQ(QQ) QQzone(QQ空间)
title String 标题,分享类型为webPage,此参数必填
desc String 描述,建议填写,否则第三方平台可能会有默认文案
url String 分享类型为webPage时,要分享的网页的URl,分享类型为image时不必填, 分享类型为webPage,此参数必填
image String 分享类型为image时必填,image路径,如 'http://', 'https://', 'file://',也可以为base64编码的字符串,分享类型为webPage时不必填。特别注意:iOS平台网络图片类型只能用https格式
shareType String 分享类型 webPage 或者 image, 请注意cordova 容器下只支持 webPage 类型
thumImage String 缩略图 如 'https://', 'file://',特别注意:iOS平台网络图片类型只能用https格式
错误返回 retCode说明:
retCode编码 retInfo说明
150001 应用未安装
150002 分享参数异常
000001 分享失败

因受第三方平台限制:
图片分享:图片大小不能超过2M,本地文件,地址长度小于512,图片内容不能为空;
网页分享:url不能为空,且长度小于512 描述不能为空,且长度小于1024,标题不能为空;
缩略图大小不超过24k;标题加描述不能超过140个字以上限制;

https://developer.umeng.com/docs/128606/detail/129565

示例

调用方式

uplusapi.upShareModule.share({
  platformType:"WechatTimeLine",
  title:"智家",
  desc:"这里是智家",
  image:"https://image.haier.com/bbs/images/fx_moren.png",
  shareType:"image",
  thumImage:"https://image.haier.com/bbs/images/fx_moren.png"
}).then((result) =>console.log('result',result));

成功返回结果

{
  "retCode": "000000",
  "retInfo": "分享成功",
  "retData": null
}
  • shareWechatMiniProgram (App分享微信小程序)

    shareWechatMiniProgram({params})
适用性
容器 cordova APICloud Nebula
支持情况
APP版本 6.23.3 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
programId String 小程序的原始id(注意不是AppId)
targetPath String 分享后点击打开小程序的页面路径
imageData String 图片,大小不能超过128kb,base64字符串
thumImage String 缩略图,大小不能超过128kb,可以是图片路径或者base64字符串
title String 小程序的名称
desc String 小程序内容描述
extraData map 需要传递给目标小程序的数据
错误返回 retCode说明:
retCode编码 retInfo说明
150001 应用未安装
150002 分享参数异常
000001 分享失败
示例

调用方式

uplusapi.upShareModule.shareWechatMiniProgram({
  title: "测试分享小程序",
  desc: "测试内容,分享微信小程序",
  programId: "gh_afc1f40647b0",
  targetPath: "pages/home/home",
  imageData: "需要传入目标图片的base64字符串",
  thumImage: "https://enxcook.xcook.cn/disinfect/image/bg-share.jpg",
  extraData:{
      "authcode": "1234",
      "userId": "000000",
      "familyId":"111111",
   }
}).then((result) =>console.log('result',result));

成功返回结果

{
  "retCode": "000000",
  "retInfo": "分享成功",
  "retData": null
}

results matching ""

    No results matching ""