Skip to main content

GetOpenId/GetPhoneNumber/GetEmailAddress

Workflow#

  1. The mini app calls the js api bn.getOpenId() or bn.getPhoneNumber() or bn.getEmailAddress to the mini program framework, the later will popup a authorization page for the user to approve, and return the data_token if the user approves
  2. The mini app uploads the data_tokee=n to the merchant’s backend
  3. The backend calls the getOpenData with the data_token , and get the data from response
  4. The backend decrypt the data, get openid or phone number or email address

You can get all the required APIs in the reference. This API only works only Binance APP >= 2.51.0

Preparation#

Please refer to Preparation Of Open Service

Mini Program#

On the mini program, the developer can call the js api: bn.getOpenId() or bn.getPhoneNumber() or bn.getEmailAddress() to pop-up an authorization page for the user. After getting the user’s approval, the api will return the data_token`, which can be used to fetch the openid or phone number or email address of the user on 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 appId of the mini program
openDatarequired data_token from previous steps

Note:

1. data_token Only valid for 2 minutes

2. 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",  "openData": "*******",}

Response

HTTP 200

{  "code": "000000",  "message": null,  "data": {    "userData": "******"  },  "success": true}
ErrorCodeRemark
000000Success
900001Invalid Param
900002Jwt auth failed
900003Unexpected error
900200Data token expired
900201Invalid data token
  • Workflow
  • Preparation
  • Mini Program
  • Backend
    • Backend