Alipay+ DocsAlipay+ Docs

applyTokenAlipay+ → MPP

The Mobile Payment Provider (MPP) uses the applyToken API to provide an access token to Alipay+. Access tokens are used for the purposes such as:

  • to initiate an Auto Debit payment.
  • to initiate a one-time password (OTP) verification process.

The applyToken API is used in the following cases:

  • After the auth client receives the auth code, Alipay+ requests the access token from the MPP.
  • The auth client requests a new access token by using the refresh token when an existing access token is about to expire or has expired.

  • After the auth client receives the auth code, Alipay+ requests the customer ID from the MPP for payments in the Chinese mainland. 

Notes:

  • A refresh token can only be used to get a new access token within the refresh token expiry time.
  • In the following sections, the Mobile Payment Partner (MPP) is also known as PSP. For example, pspId refers to the ID that identifies an MPP. 

Structure

A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see:

Note:

1. Set the data type of each parameter (except array) as String. This means that you must use double quotation marks (" ") to enclose the parameter value. Examples:

  • If the data type of a parameter is Integer and its value is 20, set it as "20".
  • If the data type of a parameter is Boolean and its value is true, set it as "true". 

2. For optional parameters that are not required in your case, you can take one of the following actions:

  • Exclude the parameters from the request body.
  • Set the parameter values as null (without the double quotation marks). 

Do NOT leave the optional parameters empty by setting their values as ""; otherwise, an error might occur. 

Request parameters

pspId String  REQUIRED

The unique ID that is assigned by Alipay+ to identify an MPP. 

More information about this field

  • Maximum length: 64 characters

acquirerId String  REQUIRED

The unique ID that is assigned by Alipay+ to identify an ACQP. 

More information about this field

  • Maximum length: 64 characters

grantType String  REQUIRED

This parameter specifies the method through which the auth client can get the access token. Valid values are:

  • AUTHORIZATION_CODE: indicates that the auth client uses the authorization code (authCode) to get an access token.
  • REFRESH_TOKEN: indicates that the auth client uses the refresh token (refreshToken) to get a new access token to replace the existing one. 

authCode String  

The authorization code that is used by the auth client to get the access token. The MPP generates the authorization code after the user completes the authorization.

Notes

  • The first 8 digits of the authorization code must be in the format of 281***13. The fourth to sixth digits are assigned by Alipay+.
  • Required when the value of the grantType parameter is AUTHORIZATION_CODE

More information about this field

  • Maximum length: 32 characters

refreshToken String  

The refresh token that is used by the auth client to get a new access token to replace the existing one. With this parameter, valid access tokens can be obtained continuously without further interaction with the user.

This parameter is specified by Alipay+ if the value of the grantType parameter is REFRESH_TOKEN

More information about this field

  • Maximum length: 128 characters

passThroughInfo String  

The information that is passed through by Alipay+ to the MPP. The value of this parameter is in the set of key-value pairs.

This parameter is specified by Alipay+ if the ACQP wants to pass information to the MPP. 

More information about this field

  • Maximum length: 20000 characters

Response parameters

result Result object REQUIRED

The result of applying the token. If the value of the result.resultCode parameter is SUCCESS, the token is successfully sent to Alipay+. For more information about how to return the result, see How to return the result

Show child parameters

accessToken String  

The token that is used to access the MPP user's resources.

Return this parameter if the value of the result.resultCode parameter is SUCCESS

More information about this field

  • Maximum length: 128 characters

accessTokenExpiryTime Datetime  

The access token expiration time, after which the access token cannot be used.

Return this parameter if the value of the result.resultCode parameter is SUCCESS

More information about this field

  • The value follows the ISO 8601 standard format. For example, "2019-11-27T12:01:01+08:00".

refreshToken String  

The refresh token that is used by the auth client to get a new access token to replace the existing one. With this parameter, valid access tokens can be obtained continuously without further interaction with the user. The value of this parameter must follow the Alipay+ coding standard.

Return this parameter if the value of the result.resultCode parameter is SUCCESS and the access token is short-term effective. You are not required to return this parameter if the access token is long-term effective, that is, 10 years or longer. 

More information about this field

  • Maximum length: 128 characters

refreshTokenExpiryTime Datetime  

The refresh token expiration time, after which the refresh token cannot be used. It is recommended that the refresh token is valid longer than the access token.

Return this parameter if the value of the result.resultCode parameter is SUCCESS and the accessToken is short-term effective. 

More information about this field

  • The value follows the ISO 8601 standard format. For example, "2019-11-27T12:01:01+08:00".

customerId String  

The unique ID that is assigned by the MPP to identify an MPP user.

Return this parameter if the value of the result.resultCode parameter is SUCCESS

More information about this field

  • Maximum length: 64 characters

userLoginId String  

The login ID that is used by the user to log in to the MPP platform. The value of userLoginId can be the user's email address or phone number and is desensitized when returned to the ACQP. The merchant will display the desensitized login ID to the user on payment initialization.

Return this parameter if the value of the result.resultCode parameter is SUCCESS and the value of the scopes parameter of the prepare API contains USER_LOGIN_ID.

More information about this field

  • Maximum length: 64 characters

passThroughInfo String  

The information that is passed through by Alipay+ to the MPP. The value of this parameter is in the set of key-value pairs.

Return this parameter if the MPP wants to pass information to the ACQP. 

More information about this field

  • Maximum length: 20000 characters
API Explorer

Request

Case
Apply the access token
Request Body

Response

Response Body

More information

How to return the result

According to the request processing result, the MPP needs to return the corresponding result (specified by the result parameter):

  • If the token application succeeds, set the value of result.resultStatus to S and the value of result.resultCode to SUCCESS.
  • If the token application fails, set the value of result.resultStatus to F and the value of result.resultCode accordingly.
  • If the token application result is unknown, set the value of result.resultStatus to U and the value of result.resultCode accordingly.

For more information about how to define your result codes, see the Result codes section below. 

Sample

Apply the access token

 Alipay+ requests the access token from the MPP.

1. Alipay+ sends the request to the Mobile Payment Provider.  

Sample Code

2. The MPP returns the access token to Alipay+.

Sample Code

Refresh the access token

Use the refreshToken to request a new access token.

1. Alipay+ sends a request to obtain a new access token.

Sample Code



2. The MPP returns the access token to Alipay+.  

Sample Code

Result/Error codes

CodeValueMessage
SUCCESSSSuccess
ACCESS_DENIEDFAccess is denied.
EXPIRED_REFRESH_TOKENFThe refresh token is expired.
INVALID_AUTHCODEFThe authorization code is invalid.
INVALID_CLIENTFThe client is invalid.
INVALID_REFRESH_TOKENFThe refresh token is invalid.
INVALID_SIGNATUREFThe signature is invalid.
KEY_NOT_FOUNDFThe key is not found.
MEDIA_TYPE_NOT_ACCEPTABLEFThe server does not implement the media type that is acceptable to the client.
METHOD_NOT_SUPPORTEDFThe server does not implement the requested HTTPS method.
NO_INTERFACE_DEFFAPI is not defined.
PARAM_ILLEGALFIllegal parameters. For example, non-numeric input, invalid date.
PROCESS_FAILFA general business failure occurred. Do not retry.
REQUEST_TRAFFIC_EXCEED_LIMITUThe request traffic exceeds the limit.
UNKNOWN_EXCEPTIONUAn API call failed, which is caused by unknown reasons.