Skip to main content

SendPushMessage

Workflow#

  1. The mini app calls the js api bn.requestSubscribeMessage({tmplIds: $template\_ids}) to the mini program framework, the later will popup a authorization page for the user to approve, and return the $template_ids and $push_tokens if the user approves
  2. The mini app uploads the $template_ids and $push_tokens to the merchant’s backend
  3. The backend calls the sendPushMessage with the $push_tokens and other parameters , and sends the message to the user.

You can get all the required APIs in the reference.

Requirements:

Binance APP >=2.52.0

SDK >= 3.13.0

Preparation#

Please refer to Preparation Of Open Service

Mini Program#

On the mini program, the developer can call the js api: bn.requestSubscribeMessage() to pop-up an authorization page for the user. After getting the user’s approval, the api will return the $template_ids and their $push_tokens, which can be used to push messages to users 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 appId of the mini program
pushTokenrequired push_token from previous steps
templateIdrequired templateId of the template
languagerequired language of the message
pathoptional pages path when user clicks the message, the path to the entry page by default
parametersrequired arrays of parameters to the template,[{“name”:string, “value”:string}]

Note:

1. pushToken Only valid for seven days

2. One pushToken only can be used once

3. You need to call this api by carrying a jwt token in the header X-Mp-Open-Api-Token. For the method of generating 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 Param
900002Jwt auth failed
900003Unexpected error
900230Invalid pushToken or pushToken expired
900231Rate limit

statusCode

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