分享

调用接口会先检测是否安装支付宝。对未安装的用户会提示"没有安装支付宝"

[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.alipay.share(options,successCallback,errorCallback)

支持平台:

  • Android
  • iOS

参数说明

参数 类型 必填 说明
options Object 参数对象
successCallback Function 成功回调函数
errorCallback Function 失败回调函数

options参数对象的类型为ShareTextObjectShareImageObjectShareMusicObjectShareVideoObjectShareWebpageObject

构造函数

  • ShareTextObject: function (text){}
  • ShareImageObject: function (shareImage){}
  • ShareMusicObject: function (musicUrl, title, description, thumbImage){}
  • ShareVideoObject: function (videoUrl, title, description, thumbImage){}
  • ShareWebpageObject: function (webpageUrl, title, description, thumbImage){}

ShareTextObject对象,包含以下属性:

  • text( String / 必选 ) -- 分享的文本

ShareImageObject对象,包含以下属性:

  • shareImage( String / 必选) -- 分享的图片URL,支持 http/https/file/cdvfile

ShareMusicObject对象,包含以下属性:

  • musicUrl( String / 必选 ) -- 音乐网页的url地址,支持 http/https
  • title( String / 可选 ) -- 标题
  • description ( String / 可选 ) -- 描述
  • thumbImage( String / 可选 ) -- 缩略图URL,支持 http/https/file/cdvfile

ShareVideoObject对象,包含以下属性:

  • videoUrl( String / 必选 ) -- 视频URL,支持 http/https
  • title( String / 可选 ) -- 标题
  • description( String / 可选 ) -- 描述
  • thumbImage( String / 可选 ) -- 缩略图URL,支持 http/https/file/cdvfile

ShareWebpageObject对象,包含以下属性:

  • webpageUrl( String / 必选 ) -- 网页URL,支持 http/https
  • title( String / 可选 ) -- 标题
  • description( String / 可选 ) -- 描述
  • thumbImage( String / 可选 ) -- 缩略图URL,支持 http/https/file/cdvfile

successCallback函数会返回一个字符串,字符串内容为分享结果信息

errorCallback函数会返回一个字符串,分享错误的相关信息

示例代码

分享文字

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
// 分享文字 
var obj = new ShareTextObject('分享文字');
navigator.alipay.share(obj,function (successCallback) {
  alert(JSON.stringify(successCallback));
},function (errorCallback){
  alert(JSON.stringify(errorCallback));
});
}
</script>

分享图片

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
// 分享图片 
var obj = new ShareImageObject('http://hot.online.sh.cn/images/attachement/jpeg/site1/20180225/IMGf48e3894467146954814361.jpeg');
navigator.alipay.share(obj,function (successCallback) {
  alert(JSON.stringify(successCallback));
},function (errorCallback){
  alert(JSON.stringify(errorCallback));
});
}
</script>

分享音乐

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
// 分享音乐 
var obj = new ShareMusicObject('http://y.qq.com/i/song.html?songid=432451&source=mobileQQ%23wechat_redirect','歌曲名:不要说话','专辑名:不想放手歌手名:陈奕迅','http://imgcache.qq.com/music/photo/mid_album_300/V/E/000J1pJ50cDCVE.jpg');
navigator.alipay.share(obj,function (successCallback) {
  alert(JSON.stringify(successCallback));
},function (errorCallback){
  alert(JSON.stringify(errorCallback));
});
}
</script>

分享视频

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
// 分享视频 
var obj = new ShareVideoObject('http://url.cn/5ciXSIz','视频《画》',
        'G.E.M.邓紫棋','http://hot.online.sh.cn/images/attachement/jpeg/site1/20180225/IMGf48e3894467146954814361.jpeg');
navigator.alipay.share(obj,function (successCallback) {
  alert(JSON.stringify(successCallback));
},function (errorCallback){
  alert(JSON.stringify(errorCallback));
});
}
</script>

分享网页

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
// 分享网页 
var obj = new ShareWebpageObject('http://www.qlwb.com.cn/2019/0214/1397405.shtml','网页标题','描述',
        'http://hot.online.sh.cn/images/attachement/jpeg/site1/20180225/IMGf48e3894467146954814361.jpeg');
navigator.alipay.share(obj,function (successCallback) {
  alert(JSON.stringify(successCallback));
},function (errorCallback){
  alert(JSON.stringify(errorCallback));
});
}
</script>

响应示例代码:

"分享成功"

results matching ""

    No results matching ""