All Products
Search
Document Center

Mobile Platform as a Service:Client APIs

Last Updated:May 24, 2022

Message Push Service involves the following client APIs.

Call method

API

Description

RPC call

Bind

Bind the user ID and device ID (Ad-token).

Unbind

Unbind the user ID and device ID (Ad-token).

Report third-party channel devices

Bind the third-party channel device ID (Ad-token).

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. The API calls are implemented through the mobile gateway SDK.

Bind

  • 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.

        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.

  • Request parameters

    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

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

Unbind

  • Method definition

    This method is used to unbind user ID and device ID.

    Note

    The interface must be called in the child thread.

      public static ResultPbPB unbind(Context ctx, String userId, String token)
  • Request parameters

    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 of Bind API.

  • Code sample

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

Report third-party channel devices

  • 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.

    public static ResultPbPB report(Context context, String deliveryToken, int thirdChannel, String thirdChannelDeviceToken)
  • Request parameters

    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:

    • 2: Apple

    • 4: Xiaomi

    • 5: Huawei

    • 6: FCM

    • 7: OPPO

    • 8: vivo

    thirdChannelDeviceToken

    String

    The ID of a device connected to a third-party channel.

  • Response parameters

    Refer to the response parameters of Bind API.

  • Code sample

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

Troubleshooting

If an exception occurs in the process of initiating RPC requests for resources, refer to Security guard result codes.