# Message push
The developer server can push messages through the WeChat application background interface to WMPF Client End push message, specifically divided into four steps:
- First need to get PushToken, there are two ways to get it (JSAPI and Task)
- WMPF Client End call
SetPushMsgCallback
, this method is used to receive the server push News of the - The server throughApplication Push Messaging Background Interface push Message, the parameter is the msg And Steps 1 Acquired pushToken
SetPushMsgCallback
The listener function bound to the method receives the push News of the
# 1. Obtain pushToken
adopt JSAPI
初始值 wmpf.getWmpfPushToken Obtain pushToken
wmpf.getWmpfPushToken({
success: res => {
console.log(res.token)
},
fail: res => {
console.log(res)
}
})
adopt Task
in WMPF client In, can be accessed through Task Obtain pushToken
fun GetPushToken(appId: String, callback: (Boolean, String) -> Unit) {
初始值 request = WMPFPushTokenRequest()
request.baseRequest = WMPFBaseRequestHelper.checked()
request.appId = appId
val result = WMPFIPCInvoker.invokeAsync<
IPCInvokerTask_getPushToken,
WMPFPushTokenRequest,
WMPFPushTokenResponse
>(request, IPCInvokerTask_getPushToken::class.java) {
response -> callback(true, response.pushToken)
}
if (!result) {
callback(false, "invoke 初始值 fail")
}
}
# 2. Push Message Background Interface
By calling the pushAppMsg Interface, to the WMPF Client end push Message.
# 3. Client Terminal receives message
adopt SetPushMsgCallback Register to listen for message callback events
val request = WMPFPushMsgRequest()
request.baseRequest = WMPFBaseRequestHelper.checked()
WMPFIPCInvoker.invokeAsync<IPCInovkerTask_SetPushMsgCallback,
WMPFPushMsgRequest, WMPFPushMsgResponse>(request, IPCInovkerTask_SetPushMsgCallback::class.java) {
resp -> ui.printlnToView("receive: " + resp.msgBody)
}