Alipay+ DocsAlipay+ Docs

getAuthCode

The Alipay+ client SDK uses the getAuthCode API to obtain the authorization code from the Mobile Payment Provider (MPP).

Method signature

copy
public interface CommonOAuthService {

    void getAuthCode(CommonOAuthServiceParams params, Callback<CommonOAuthServiceResult> callback);

}

Request parameters

Item

Type

Description

Required

params

CommonOAuthServiceParams

Parameters that are required to obtain the authorization code.

M

callback

Callback

The callback to be invoked after the process to obtain the authorization code ends. See Callback for details.

M

Callback

Item

Type

Description

Required

result

CommonOAuthServiceResult

The result information that is required if the authorization is successful.

O

errorCode

String

The error code that is required if the authorization fails.

O

errorMessage

String

The error message that is required if the request fails.

O

Response parameters

N/A

Sample

Definition of YOUR_OAUTH_SERVICE_CLASS:

copy
public class YOUR_OAUTH_SERVICE_CLASS implements CommonOAuthService {
    
    public void getAuthCode(CommonOAuthServiceParams params, Callback<CommonOAuthServiceResult>) {
         
        //Your logic
            
        //On success
        CommonOAuthServiceResult result = new CommonOAuthServiceResult();
        result.authCode = "XXX";
        List<String> authSuccessScopes = new ArrayList();
        authSuccessScopes.add("auth_base");
        result.authSuccessScopes = authSuccessScopes;
        result.authErrorScopes = new HashMap();
        callback.onSuccess(result);
        
        //On failure
        callback.onFailure(1001, "XXXX");
        
        
    }
    
}

Instance of YOUR_OAUTH_SERVICE_CLASS:

copy
AlipayPlusClient.getInstance().commonOAuthService = new YOUR_OAUTH_SERVICE_CLASS();