SceneActivityContext.bind
基础库 3.27.0 开始支持本方法,低版本需做兼容处理,这是一个异步方法。
绑定侧边栏复访福利活动并返回已配置的复访福利活动信息
| 前提条件 | 请确认已通过开发者平台控制台中或通过 OpenAPI 创建小程序券模板和小程序营销活动,接入方式详见:侧边栏复访营销 |
| 业务背景 | 无 |
| 使用限制 | 暂不支持抖音开发者工具调试,真机调试请参考小程序线上调试彩蛋 |
| 注意事项 | 该能力需要开发者前置在控制台或通过 openapi 创建复访营销活动并且复访营销活动的引流方式需要为小程序内组件调用,弹窗样式需要选择自定义样式,才可进行调用,具体申请流程可参考>>小程序券创建流程、小程序营销活动创建流程。 |
| 支持沙盒 | 否 |
| 相关教程 | 无 |
语法
SceneActivityContext.bind(options)
参数说明
options 为 object 类型,属性如下:
| 属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|---|
| activityId | string | 否 |
| 3.27.0 | |
| success | function | 否 | 接口调用成功的回调函数 | 3.27.0 | |
| fail | function | 否 | 接口调用失败的回调函数 | 3.27.0 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败 都会执行) | 3.27.0 |
回调成功
object 类型,属性如下:
| 属性名 | 类型 | 说明 | 最低支持版本 |
|---|---|---|---|
| mainTitle | string | 主标题 | 3.27.0 |
| subTitle | string | 副标题 | 3.27.0 |
| imageUrl | string | 封面图片 | 3.27.0 |
| leftButtonText | string | 关闭按钮文案 | 3.27.0 |
| rightButtonText | string | 引导标题文案 | 3.27.0 |
| extra | string | 福利信息 | 3.27.0 |
| errMsg | string | "SceneActivityContext.bind:ok" | 3.27.0 |
回调失败
object 类型,属性如下:
| 属性名 | 类型 | 说明 | 最低支持版本 |
|---|---|---|---|
| errMsg | string | "SceneActivityContext.bind:fail" + 详细错误信息 | 3.27.0 |
错误码
| errNo | errMsg | 说明 | 最低支持版本 |
|---|---|---|---|
| 21001 | ActivityContext.bind:fail activity does not exist | 营销复访活动不存在,请先查阅《小程序营销活动创建流程》 | 3.27.0 |
| 21011 | ActivityContext.bind:fail invalid activity | 无效活动id 或者 营销复访活动已失效 | 3.27.0 |
| 21021 | already in the sidebar scene, do not repeat boot | 用户已在侧边栏场景下访问,请勿重复引导复访 | 3.27.0 |
扫码体验
请使用字节宿主APP扫码
代码示例
<view class="container"> <view class="body-space"> <view tt:if="{{canShowRelation}}" class="page-section"> <view class="title">请在非侧边栏场景下调用</view> <button class="button-group" type="primary" bindtap="bind">关联侧边栏复访福利</button> <button tt:if="{{relationResult}}" type="primary" bindtap="jump">跳转</button> </view> </view> </view>
Page({ activityContext: undefined, data: { canShowRelation: false, relationResult: '', }, onLoad() { this.activityContext = tt.createSceneActivityContext(); }, onShow() { this.setData({ canShowRelation: this.activityContext.checkScene({ scene: 'bind', }), }); }, bind() { const canRelation = this.activityContext.checkScene({ scene: 'bind', }); if (!canRelation) { tt.showToast({ title: '请在非侧边栏场景下使用', }); return; } this.activityContext.bind({ activityId: '', success: (res) => { if (res.mainTitle) { console.log('关联侧边栏福利成功', res); tt.showToast({ title: '关联侧边栏福利成功', }); this.setData({ relationResult: JSON.stringify(res), }); } }, fail: (err) => { console.log('关联侧边栏福利失败', err); tt.showToast({ title: '关联侧边栏福利失败', icon: 'none', }); }, }); }, jump() { this.activityContext.jump({ fail(e) { console.log('跳转失败', e); }, }); }, });
