概要
通过云巴推送实现一个在线聊天的功能。可实现点对点发消息、群发消息。需要到云巴开放平台注册key。
1.setCallbackForPush
功能
设置回调函数,初始化的时候调用
定义
IpuMobile.setCallbackForPush(callback, err);
参数
参数名 | 参数类型 | 参数描述 | 参数备注 |
---|---|---|---|
callback | string | 回调函数 | 必传 |
err | function | 执行失败后的回调函数 | 选传 |
范例
IpuMobile.setCallbackForPush('receiveMessage')
备注
无
2.registerForPush
功能
注册云巴推送,并设置别名
定义
IpuMobile.registerForPush(alias, err);
参数
参数名 | 参数类型 | 参数描述 | 参数备注 |
---|---|---|---|
alias | string | 别名 | 必传 |
err | function | 执行失败后的回调函数 | 选传 |
范例
IpuMobile.registerForPush('aniu')
备注
设置了别名,才能发送消息给指定别名的用户
3.unregisterForPush
功能
注销云巴推送,注销之后不能再发送、接收消息
定义
IpuMobile.unregisterForPush(err);
参数
参数名 | 参数类型 | 参数描述 | 参数备注 |
---|---|---|---|
err | function | 执行失败后的回调函数 | 选传 |
范例
IpuMobile.unregisterForPush()
备注
无
4.sendText
功能
发送消息
定义
IpuMobile.sendText(alias, message, err);
参数
参数名 | 参数类型 | 参数描述 | 参数备注 |
---|---|---|---|
alias | string | 消息接收者别名 | 必传 |
message | string | 发送消息内容 | 必传 |
err | function | 执行失败后的回调函数 | 选传 |
范例
IpuMobile.sendText('aniu', 'aniu你好,在吗?');
IpuMobile.sendText('ALL', '大家晚上好');
备注
如果发送消息给所有人,alias为固定值ALL