Skip to main content
POST /v1/authorizations/applyToken Obtains access tokens. Supports two use cases:
  1. Authorization Code Exchange: after your server receives an authCode from the Mini Program (my.getAuthCode), exchange it for an accessToken. In agreement scenarios this is generally used together with Prepare.
  2. Token Refresh: when the original token expires, use the refreshToken to obtain a new accessToken. This can be used independently, without further user interaction.
See User Authorization for the end-to-end flow.

Request Parameters

string
required
The type of token grant being requested.Possible values:
  • AUTHORIZATION_CODE — Exchange an auth code for tokens
  • REFRESH_TOKEN — Refresh an expired access token
string
The authorization code received after user authorization.Required when: grantType is AUTHORIZATION_CODE
string
The refresh token from a previous token response.Required when: grantType is REFRESH_TOKEN
string
Extended information (JSON string). Key:
  • customerBelongsTo: the e-wallet the customer uses, corresponding to the siteName returned by the my.getSiteInfo JSAPI. Mandatory in the Mini Program scenario. Example: "{\"customerBelongsTo\":\"siteNameExample\"}"

Response Parameters

object
required
Standard result object with resultCode, resultStatus, resultMessage
string
Token for accessing the user’s resources within the authorized scope. Returned when result.resultStatus is S.
string
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).
string
Token used to obtain a new access token when the current one expires, without further user interaction. Returned when result.resultStatus is S.
string
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.
string
Resource owner ID: the user ID, the app ID of the merchant’s application, or the merchant ID.
string
Extended response information.
string
Agreement contract ID, globally unique. Returned in agreement scenarios. Example: 20251230111215800000REBLW3IT198000006315

Result Handling

  • result.resultStatus is S: the token was issued. Use accessToken to access the user’s resources within the granted scope until accessTokenExpiryTime, and use refreshToken to get a new access token until refreshTokenExpiryTime.
  • result.resultStatus is F or U: the request failed. Guide the user to try again (for an expired or used authCode, call my.getAuthCode again to get a new code).

Result Codes

Sample

Request

Response

The merchant can use accessToken to access the user’s resource scope until accessTokenExpiryTime, and refreshToken to request a new accessToken until refreshTokenExpiryTime.