Skip to main content

GetOpenId/GetPhoneNumber/GetEmailAddress

Workflow#

  1. The mini app invokes the JavaScript API function, bn.getOpenId(), bn.getPhoneNumber(), or bn.getEmailAddress() via the mini program framework. This step triggers a pop-up authorization page asking for user approval, returning a data_token upon user's consent.
  2. The mini app transmits the data_token to the merchant’s backend system.
  3. The backend system invokes the 'getOpenData' operation with the received data_token, extracting the data from the resultant response.
  4. The backend decrypts the data to retrieve the openid, phone number or email address.

Please note, all necessary APIs can be found in the reference section. This API operates only on Binance APP version 2.51.0 or later.

Preparation#

Please refer to Preparation Of Open Service

Mini Program#

In the mini program, developers can call the JavaScript API functions - bn.getOpenId(), bn.getPhoneNumber(), or bn.getEmailAddress() - which trigger an authorization pop-up for the user. Upon gaining user consent, the API returns the data_token which can be used to obtain the user's openid, phone number, or email address from the backend.

<Button onGetphonenumber={getPhoneNumber} openType="getPhoneNumber"> Get Phone Number </Button>
getPhoneNumber(e) {    const code = e.detail.code    if (code) {      api.sendToBackend(code)    }}

Backend#

Backend#

Host: dip-cb.binanceapi.com

GET /mp-api/v1/apps/{appId}/user-open-data?openData=data_token

Parameters

ParameterDescription
appIdrequired The AppId of the mini program
openDatarequired The data_token from previous steps

Note:

  1. The data_token is valid only for 2 minutes.
  2. This API must be called with a JWT token in the X-Mp-Open-Api-Token header. For generating the JWT token, please refer to Description of External Interface Signature Authentication Algorithm

Request

​​{  "appId": "your-app-id-can-get-from-workspace",  "openData": "*******",}

Response

HTTP 200

{  "code": "000000",  "message": null,  "data": {    "userData": "******"  },  "success": true}
ErrorCodeRemark
000000Success
900001Invalid Parameter
900002JWT Authentication Failed
900003Unexpected Error
900200Data Token Expired
900201Invalid Data Token
  • Workflow
  • Preparation
  • Mini Program
  • Backend
    • Backend