MemberService

When the mini program or the IAPMiniProgram SDK requests basic user information, the SDK calls the MemberInfoService SPI to retrieve such information from the super app. For details on how the SPI functions, refer to the MemberInfoService workflow.

This SPI provides the getMemberInfo method. The method details are as follows:

getMemberInfo

The SDK calls the getMemberInfo method to retrieve basic user information from the super app.

Method signature

copy
func getMemberInfo(
    strategy: IAPWalletMemberInfoFetchStrategy,
    scope: IAPWalletMemberInfoScope? = nil,
    in context: IAPWalletAPIContext? = nil,
    callback: @escaping (IAPWalletMemberInfoFetchResult) -> Void
)

Request parameters

Field

Data type

Description

Required

strategy

IAPWalletMemberInfoFetchStrategy

The strategy of getting users' information. Valid values are:

  • localUserIdOnly: Get the locally cached user ID but payloaded into MemberInfo. This value is used in the following scenarios:
    • Distinguish storage by userId inside the mini program, such as my.setStorage.
    • The IAPMiniProgram SDK requests userId.
  • remoteFetch: Get the latest remote MemberInfo. It's used in my.getOpenUserInfo.

Yes

scope

IAPWalletMemberInfoScope

An object that specifies the types of the user information that is requested.

Yes

context

IAPWalletAPIContext

A context object, which carries the mini program runtime metadata.

Yes

callback

Callback

The callback that is executed when request processing is complete. For details, see the following section.

Yes

Callback

Field

Data type

Description

Required

result

IAPWalletMemberInfoFetchResult

The result of the getMemberInfo request.

Yes

Response parameters

N/A

Error codes

Error code

Error message

1000

ERROR_CODE_UNKNOWN_ERROR

Unknown error

1001

ERROR_CODE_USER_CANCEL

The user cancels the operation.

1002

ERROR_CODE_APP_SERVICE_ERROR

The app service is wrong.

1003

ERROR_CODE_TIMEOUT

Timeout

1005

ERROR_CODE_SYSTEM_ERROR

System error

2001

ERROR_CODE_AUTH_PENDING_AGREEMENT

Authorization is not finished or is pending.

Sample

The following sample shows how to implement the MemberService SPI to provide basic user information to the SDK and mini programs:

  1. Create a class that implements the MemberService interface.
  2. Implement the getMemberInfo method.

Swift

copy
final class MemberInfoService: IAPWalletMemberServiceSignature {
    override func getMemberInfo(
        strategy: IAPWalletMemberInfoFetchStrategy,
        scope: IAPWalletMemberInfoScope? = nil,
        in context: IAPWalletAPIContext? = nil,
        callback: @escaping (IAPWalletMemberInfoFetchResult) -> Void
    ) {
        let memberInfo = IAPWalletMemberInfo()
        switch strategy {
        case .localUserIdOnly:
            memberInfo.userId = xxx //Gets the locally cached user id but payloaded into MemberInfo
        case .remoteFetch:
            memberInfo.userId = xxx //Gets the latest remote MemberInfo
        }
        
        callback(IAPWalletMemberInfoFetchResult(memberInfo: memberInfo))
    }
}