POST /v1/authorizations/applyToken
Obtains access tokens. Supports two use cases:
- Authorization Code Exchange: after your server receives an
authCodefrom the Mini Program (my.getAuthCode), exchange it for anaccessToken. In agreement scenarios this is generally used together with Prepare. - Token Refresh: when the original token expires, use the
refreshTokento obtain a newaccessToken. This can be used independently, without further user interaction.
Request Parameters
The type of token grant being requested.Possible values:
AUTHORIZATION_CODE— Exchange an auth code for tokensREFRESH_TOKEN— Refresh an expired access token
The authorization code received after user authorization.Required when:
grantType is AUTHORIZATION_CODEExtended information (JSON string). Key:
customerBelongsTo: the e-wallet the customer uses, corresponding to thesiteNamereturned by themy.getSiteInfoJSAPI. Mandatory in the Mini Program scenario. Example:"{\"customerBelongsTo\":\"siteNameExample\"}"
Response Parameters
Token for accessing the user’s resources within the authorized scope. Returned when
result.resultStatus is S.Access token expiration time (ISO 8601). Returned when
result.resultStatus is S. After this time the token is invalid and can no longer be used (for example, to deduct from the user’s account).Token used to obtain a new access token when the current one expires, without further user interaction. Returned when
result.resultStatus is S.Refresh token expiration time (ISO 8601). Returned when
result.resultStatus is S. After this time the refresh token can no longer be used and the user must authorize again.Agreement contract ID, globally unique. Returned in agreement scenarios. Example:
20251230111215800000REBLW3IT198000006315Result Handling
result.resultStatusisS: the token was issued. UseaccessTokento access the user’s resources within the granted scope untilaccessTokenExpiryTime, and userefreshTokento get a new access token untilrefreshTokenExpiryTime.result.resultStatusisForU: the request failed. Guide the user to try again (for an expired or usedauthCode, callmy.getAuthCodeagain to get a new code).
Result Codes
Sample
Request
Response
accessToken to access the user’s resource scope until accessTokenExpiryTime, and refreshToken to request a new accessToken until refreshTokenExpiryTime.