分享
调用接口会先检测是否安装支付宝。对未安装的用户会提示"没有安装支付宝"[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.alipay.share(options,successCallback,errorCallback)
支持平台:
- Android
- iOS
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
options | Object | 是 | 参数对象 |
successCallback | Function | 否 | 成功回调函数 |
errorCallback | Function | 否 | 失败回调函数 |
options
参数对象的类型为ShareTextObject
、ShareImageObject
、ShareMusicObject
、ShareVideoObject
、ShareWebpageObject
。
构造函数
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>
响应示例代码:
"分享成功"