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
NS_ASSUME_NONNULL_BEGIN

@protocol MPPAlipayPlusClientCommonOAuthProtocol <NSObject>

- (void)getAuthCode:(MPPCommonOAuthServiceParams *)params
            completionHandler:(void(^)(MPPCommonOAuthServiceResult *_Nullable result, NSError *_Nullable error))completionHandler;

@end
NS_ASSUME_NONNULL_END

Request parameters

Item

Type

Description

Required

params

MPPCommonOAuthServiceParams

Parameters that are required to obtain the authorization code.

M

completionHandler

iOS block

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

M

completionHandler

Item

Type

Description

Required

result

MPPCommonOAuthServiceResult

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

O

error

NSError

The error code that is required if the authorization fails.

O

Response parameters

N/A

Sample

Definition of YOUR_OAUTH_SERVICE_CLASS:

copy
#import <MPPAlipayPlusClient/MPPAlipayPlusClientAPI.h>

@interface YOUR_OAUTH_SERVICE_CLASS: NSObject <MPPAlipayPlusClientCommonOAuthProtocol>
- (void)getAuthCode:(MPPCommonOAuthServiceParams *)params
            completionHandler:(void(^)(MPPCommonOAuthServiceResult *_Nullable result, NSError *_Nullable error))completionHandler;
@end

@implementation YOUR_OAUTH_SERVICE_CLASS
- (void)getAuthCode:(MPPCommonOAuthServiceParams *)params
            completionHandler:(void(^)(MPPCommonOAuthServiceResult *_Nullable result, NSError *_Nullable error))completionHandler; {
  
  //Obtain the authCode with the authClientId and scopes in params

  MPPCommonOAuthServiceResult *result = MPPCommonOAuthServiceResult.new;
  result.authCode = @"xxx";
  result.authSuccessScopes = @[@'auth_base'];
  result.authErrorScopes = [NSMutableDictionary dictionary];
  completionHandler(result, nil);

  }
@end

Instance of YOUR_OAUTH_SERVICE_CLASS:

copy
#import <MPPAlipayPlusClient/MPPAlipayPlusClientAPI.h>
[AlipayPlusClient shared].commonOAuthService = YOUR_OAUTH_SERVICE_CLASS.new