基础库 > 3.108.x, 客户端 > 8.57 版本 开始支持,低版本需做兼容处理。(以 Promise 风格 调用:不支持)
客户端 > 8.57, 基础库 > 3.108.x 以后的版本,分享出去的链接将包含 shareTicket 信息,当用户点开小程序时,开发者可以通过 xhs.getShareInfo 获取到以下分享者信息: 分享者的open_id(可以针对分享者行为来给予一定的激励) 点开小程序的用户所在的加密群ID(可以用于统计分享者分享给了多少个不同的群)
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
shareTicket | string | 是 | 分享的凭证,可通过 App.onLanuch/App.onShow/xhs.getLaunchOptionsSync/xhs.getEnterOptionsSync 等方式获取 | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
代码示例
Page({ data: { shareTicket: '', }, onReady() { const options = xhs.getEnterOptionsSync(); this.setData({ shareTicket: options.shareTicket }); }, getShareInfo() { if (!this.data.shareTicket) { xhs.showToast({ title: '请先获取 shareTicket' }); return; } let _this = this; xhs.getShareInfo({ shareTicket: _this.data.shareTicket, success(res) { console.log('getShareInfo success', res); _this.setData({ shareInfo: '获取 shareInfo 信息成功:' + JSON.stringify(res) }); }, fail(err) { console.log('getShareInfo fail', err); _this.setData({ shareInfo: '获取 shareInfo 信息失败:' + JSON.stringify(err) }); } }); } });
参数名 | 类型 | 说明 |
---|---|---|
open_share_Id | string | 分享者的 open_id |
open_g_id | string | 通过群聊进入时的群 id |
open_id | string | 点击分享链接进入的用户的 open_id (与当前用户 open_id 一致) |