微信小程序多端框架

最近更新时间:2025-06-12 11:53:32

我的收藏

接口概览

API
描述
setRegistrationID
设置注册推送服务使用的推送 ID 标识,即 RegistrationID,需要在注册推送服务之前调用。
getRegistrationID
注册推送服务成功后,获取推送 ID 标识,即 RegistrationID。
registerPush
注册推送服务 (必须在 App 用户同意了隐私政策,并且确定为 App 用户开始提供推送服务后,再调用该接口使用推送服务)。
unRegisterPush
反注册关闭推送服务。
addPushListener
订阅推送事件,如点击通知栏事件。
removePushListener
取消订阅推送事件。
disablePostNotificationInForeground
应用在前台时,开/关通知栏通知(默认开)。
createNotificationChannel
创建客户端通知 channel。此接口可实现自定义铃音功能。
setCustomBadgeNumber
设置应用角标数字(仅华为、iOS)

接口详情

注册推送服务

注意:
必须在 App 用户同意了隐私政策,并且确定为 App 用户开始提供推送服务后,再调用该接口使用推送服务。否则可能因提前获取用户隐私导致上架失败。

接口

registerPush(sdkAppID: number, appKey: string): Promise<JSON>;

参数说明

参数
类型
说明
获取路径
sdkAppID
number
推送(Push)应用 ID



appKey
string
推送(Push)应用客户端密钥


返回值说明

返回值
说明
Promise
成功返回 {"errCode":0,"errMsg":"success","data":{"token":"xxx"}},失败返回 { errCode: number, errMsg: string }

反注册关闭推送服务。

接口

unRegisterPush(): Promise<JSON>;

返回值说明

返回值
说明
Promise
成功返回 {"errCode":0,"errMsg":"success"},失败返回 { errCode: number, errMsg: string }

设置推送 ID 标识 RegistrationID

注意:
需要在注册推送服务之前调用。

接口

setRegistrationID(registrationID: string): Promise<JSON>;

参数说明

参数
类型
必填
说明
registrationID
string
设备的推送标识 ID,卸载重装会改变

返回值说明

返回值
说明
Promise
成功返回 {"errCode":0,"errMsg":"success"},失败返回 { errCode: number, errMsg: string }

获取推送 ID 标识 RegistrationID

说明:
需要在注册推送服务成功之后调用。

接口

getRegistrationID(): Promise<JSON>;

返回值说明

返回值
说明
Promise
成功返回 {"errCode":0,"errMsg":"success","data":{"registrationID":"xxx"}},失败返回 { errCode: number, errMsg: string }

订阅推送事件,如点击通知栏事件

接口

addPushListener(eventName: string, listener: (res: any) => void): void;

参数说明

参数
类型
必填
说明
eventName
string
推送事件类型,可查看 Push.EventName
listener
(res: any) => void
推送事件处理方法

取消订阅推送事件

接口

removePushListener(eventName: string, listener: (res: any) => void): void;

参数说明

参数
类型
必填
说明
eventName
string
推送事件类型,可查看 Push.EventName
listener
(res: any) => void
推送事件处理方法

应用在前台时,开/关通知栏通知

接口

disablePostNotificationInForeground(disable: boolean): void;

参数说明

参数
类型
必填
说明
disable
boolean
应用在前台时,开/关通知栏通知,默认开:
true: 应用在前台时,关闭通知栏通知。
false: 应用在前台时,开启通知栏通知。

创建客户端通知 channel

说明:
如果不同厂商的 ChannelID 各不相同,那么每个 Channel 都需要创建。

接口

createNotificationChannel(options: {
channelID: string;
channelName: string;
channelDesc?: string;
channelSound?: string;
}): Promise<JSON>;

参数说明

参数
类型
必填
说明
options.channelID
String
自定义 channel 的 ID。
options.channelName
String
自定义 channel 的名称。
options.channelDesc
String
自定义 channel 的描述。
options.channelSound
String
自定义 channel 铃音的音频文件名,不带文件扩展名,音频文件需要放到 xxx/android/nativeResources/res/raw 中。
例如:options.channelSound = private_ring,即设置xxx/android/nativeResources/res/raw/private_ring.mp3 为自定义铃音。

返回值说明

返回值
说明
Promise
成功返回 {"errCode":0,"errMsg":"success"},失败返回 { errCode: number, errMsg: string }

设置应用角标数字

注意:
1. 需要在注册推送服务之后调用。
2. 仅支持华为、iOS。

接口

setCustomBadgeNumber(badgeNumber: number): Promise<JSON>;

参数说明

参数
类型
必填
说明
badgeNumber
number
应用角标数字

返回值说明

返回值
说明
Promise
成功返回 {"errCode":0,"errMsg":"success"},失败返回 { errCode: number, errMsg: string }