GetOpenId/GetPhoneNumber/GetEmailAddress
Workflow
- The mini app invokes the JavaScript API function,
bn.getOpenId()
,bn.getPhoneNumber()
, orbn.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. - The mini app transmits the data_token to the merchant’s backend system.
- The backend system invokes the 'getOpenData' operation with the received data_token, extracting the data from the resultant response.
- 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
Parameter | Description |
---|---|
appId | required The AppId of the mini program |
openData | required The data_token from previous steps |
Note:
- The data_token is valid only for 2 minutes.
- 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
}
ErrorCode | Remark |
---|---|
000000 | Success |
900001 | Invalid Parameter |
900002 | JWT Authentication Failed |
900003 | Unexpected Error |
900200 | Data Token Expired |
900201 | Invalid Data Token |