codecamp

百度智能小程序 小程序消息订阅服务

swan.subscribeService

基础库 3.150.1 开始支持,低版本需做兼容处理。

解释:小程序消息订阅服务:取消订阅和查询订阅;订阅操作详见form 表单

Web 态说明:Web 态暂不支持消息订阅功能,调用该 API 会触发 success 回调,返回参数中的字段均为模拟值,仅供参考。

方法参数

Object object

object 参数说明

参数名 类型 是否必填 默认值 说明
templateId String - 模板消息所用的模板库标题 ID,与使用form 表单订阅时,template-id 对应的值相同
subscribeId String - 订阅唯一标识,与使用form 表单订阅时,subscribe-id 对应的值相同
type String query 订阅的操作类型:query(查询订阅)cancel(取消订阅)
success Function - 接口调用成功的回调函数
fail Function - 接口调用失败的回调函数
complete Function - 接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明

参数名 类型 说明
type String 订阅的操作类型:query(查询订阅)cancel(取消订阅)
form_id String 对应提交form 表单时返回的 formId。当传入参数 type 为 query 时有此字段
status Number 订阅状态;1 表示已订阅,0 表示已取消订阅,-1 表示未找到此订阅。当传入参数 type 为 query 时或 type 为 cancel 且未找到此订阅时有此字段
update_time Number 订阅更新时间
app_key String 小程序唯一标识

示例

在开发者工具中预览效果    

代码示例

  • 在 js 文件中
swan.subscribeService({
    templateId: 'BD0003',
    subscribeId: '8026',
    type: 'query',
    success(res) {
        swan.showModal({
            title: 'success',
            content: JSON.stringify(res)
        });
    },
    fail(err) {
        swan.showModal({
            title: 'fail',
            content: JSON.stringify(err)
        });
    }
})


百度智能小程序 获取风控信息的加密信息
百度智能小程序 书架同步功能介绍
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

百度智能小程序开发文档

百度智能小程序 组件

百度智能小程序 地图

百度智能小程序 画布

百度智能小程序 API

百度智能小程序 界面

百度智能小程序 关注小程序引导组件

百度智能小程序 自定义组件

百度智能小程序 媒体

百度智能小程序 设备

百度智能小程序 拨打电话

百度智能小程序 内存警报

百度智能小程序 手机联系人

百度智能小程序 用户截屏事件

百度智能小程序 第三方平台

百度智能小程序 开放接口

百度智能小程序 百度收银支付

百度智能小程序 分包预下载

百度智能小程序 数据分析

百度智能小程序 服务端

百度智能小程序 云开发

百度智能小程序 初始化

百度智能小程序 云函数

百度智能小程序 服务端初始化

百度智能小程序 服务器获取上下文

百度智能小程序 服务端云函数

百度智能小程序 开发教程

百度智能小程序 功能开发

百度智能小程序 基本原理

百度智能小程序 小程序自动化

百度智能小程序 视频教程

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }