Skip to main content

SendPushMessage

Workflow#

  1. The mini app invokes the JavaScript API function, bn.requestSubscribeMessage({tmplIds: $template_ids}), through the mini program framework. This action prompts an authorization pop-up for user approval, returning $template_ids and corresponding $push_tokens upon user consent.
  2. The mini app transmits the $template_ids and $push_tokens to the merchant’s backend.
  3. Backed by the $push_tokens and additional parameters, the backend system calls the 'sendPushMessage' operation and forwards the message to the user.

Refer to the documentation for all required APIs.

Requirements:

Binance APP version >= 2.52.0

SDK version >= 3.13.0

Preparation#

Please refer to Preparation Of Open Service

Mini Program#

Within the mini program, developers can invoke the $ bn.requestSubscribeMessage() JavaScript API to trigger an authorization pop-up for users. Once user consent is obtained, the API returns $template_ids and corresponding $push_tokens which can be utilized for message pushing on the backend.

const tmplIds = []const info = await mpService.requestSubscribeMessage({     tmplIds})tmplIds.forEach((id) => {   if (!info[id] || info[id].type !== 'accept' || !info[id].token) {      // not accept      console.log(info[id].type)      return;   }   api.sendToBackend(info[id],info[id].token)})

Backend#

SendPushMessage#

Host: dip-cb.binanceapi.com

POST /mp-api/v1/apps/{appId}/message/send

Parameters

ParameterDescription
appIdrequired The AppId of the mini program.
pushTokenrequired The push_token obtained from previous steps.
templateIdrequired The templateId of the template.
languagerequired The language of the message.
pathoptional Pages path when user clicks the message. By default, it is the path to the entry page.
parametersrequired Arrays of parameters to the template. Format is [{"name":string, "value":string}].

Note:

  1. The pushToken is valid only for seven days.
  2. Each pushToken can only be used once.
  3. You need to carry a JWT token in the X-Mp-Open-Api-Token header when you call this API. For generating the JWT token, please refer to Description of External Interface Signature Authentication Algorithm.

Request

​​{  "appId": "your-app-id-can-get-from-workspace",  "pushToken": "push_token_****",  "templateId": "1344****",  "language": "en",  "path": "pages/details/index?source=***",  "parameters": [       {           "name": "result",           "value": "success"       },       {           "name": "withdrawMoney",           "value": "100"       }   ],}

Response

HTTP 200

{  "code": "000000",  "message": null,  "data": {    "statusCode": "000000"  },  "success": true}

Code

ErrorCodeRemark
000000Success
900001Invalid Parameter
900002JWT Authentication Failed
900003Unexpected Error
900230Invalid or Expired pushToken
900231Rate Limit

statusCode

statusCodeRemark
000000Success
900240The user has refused to receive all messages from the mini-program
900241The user has declined to receive the message corresponding to the mini-program template
  • Workflow
  • Preparation
  • Mini Program
  • Backend
    • SendPushMessage