All Products
Search
Document Center

Client API

Last Updated: Jul 07, 2021

Message Push Service involves the following client APIs, which are described in the following table:

Call method Operation Description
RPC call Bind - RPC Bind the user ID and device ID (Ad-token).
Unbind - RPC Unbind the user ID and device ID (Ad-token).
Report third-party channel device - RPC Bind the third-party channel device ID (Ad-token).

RPC calls

The MPPush class in the intermediate layer of mPaaS encapsulates all the APIs of MPS, including the interfaces for binding users, unbinding users, and reporting three-party channel device information.

Bind - RPC

  • Method definition
    This method is used to bind user ID and device ID. After the binding is completed, messages can be pushed in user dimension.

    Note: The interface must be called in the child thread.

       
    1. public static ResultPbPB bind(Context ctx, String userId, String token)

    This method is used to bind the user ID with device ID. Once the user IDs and device IDs are bound, MPS push messages from user dimension.

  • Parameter description

    Parameter Type Description
    ctx Context It must be a non-empty Context.
    userId String The unique identifier of a user. The user ID is not always the actual identifier in the business system, but there must be one-to-one mapping between the user ID and user.
    token String The device token distributed by the push gateway.

  • Response parameters

    Parameter Description
    success Whether the interface call is successful or not.
    • true: Successful
    • false: Failed
    code Operation result code. For the common operation codes and the corresponding description, see the following Result codes table.
    name Name of the result code
    message Description corresponding to the result code
  • Result codes

    Code Name Message Description
    3012 NEED_USERID need userid The parameter userId is empty when client calls the interface.
    3001 NEED_DELIVERYTOKEN need token The parameter token is empty when client calls the interface.
  • Code sample

       
    1. private void doSimpleBind() {
    2. final ResultPbPB resultPbPB = MPPush.bind(getApplicationContext(), mUserId, PushMsgService.mAdToken);
    3. handlePbPBResult("Bind users", resultPbPB);
    4. }

Unbind - RPC

  • Method definition
    This method is used to unbind user ID and device ID.

    Note: The interface must be called in the child thread.
       
    1. public static ResultPbPB unbind(Context ctx, String userId, String token)
  • Parameter description

    Parameter Type Description
    ctx Context It must be a non-empty Context.
    userId String The unique identifier of a user. The user ID is not always the actual identifier in the business system, but there must be one-to-one mapping between the user ID and user.
    token String The device token distributed by the push gateway.
  • Response parameters

    Refer to the response parameters for binding interface.

  • Code sample

       
    1. private void doSimpleUnBind() {
    2. final ResultPbPB resultPbPB = MPPush.unbind(getApplicationContext()
    3. , mUserId, PushMsgService.mAdToken);
    4. handlePbPBResult("Unbind users", resultPbPB);
    5. }

Report third-party channel device - RPC

  • Method definition
    This method is used to bind the third-party channel device ID and the Ad-token. That is, the third-party channel device identifier and mPaaS device identifier (the Ad-token issued by the MPS gateway) are reported to the mobile push core, and the mobile push core will bind these two identifiers. After completing this process, you can use third-party channels to push messages.

    Note: This method will be called once by the framework. To avoid SDK call failure, it is recommended that you call it again manually.

       
    1. public static ResultPbPB report(Context context, String deliveryToken, int thirdChannel, String thirdChannelDeviceToken)
  • Parameter description

    Parameter Type Description
    ctx Context It must be a non-empty Context.
    deliveryToken String The device ID (Ad-token) issued by MPS gateway.
    thirdChannel int The third-party channel. Valid values include:
    • 4: Xiaomi
    • 5: Huawei
    thirdChannelDeviceToken String The ID of a device connected to a third-party channel.
  • Response parameters
    Refer to the response parameters for binding interface.

  • Code sample

       
    1. private void doSimpleUploadToken() {
    2. final ResultPbPB resultPbPB = MPPush.report(getApplicationContext(), PushMsgService.mAdToken
    3. , PushOsType.HUAWEI.value(), PushMsgService.mThirdToken);
    4. handlePbPBResult("report 3rd-party device ID", resultPbPB);