MemberService

IAPMiniProgram SDK calls the MemberService SPI to obtain the members' information for the mini program.

getMemberInfo

Method signature

Call this method to get members' information.

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 gettiing members' information. Valid values are:

  • localUserIdOnly:Gets the locally cached user id but payloaded into MemberInfo. It's used when distinguishing storage by userid inside the miniprogram, such as my.setStorage.
  • localCached:Gets the locally cached MemberInfo
  • remoteFetch:Gets the latest remote MemberInfo. It's used in my.getOpenUserInfo.

No

scope

IAPWalletMemberInfoScope

The scopes of MemberInfo.

No

context

IAPWalletAPIContext

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

No

callback

Callback (For details, see the following section)

The callback that is executed when request processing is complete.

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.

Samples

The following samples show how to call the MemberService SPI to obtain the member information:

  1. Create a class that implements the MemberService interface.
  2. Within this class, implement the getMemberInfo method to fetch the member information according to the specified strategy.

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 .localCached:
            memberInfo.userId = xxx //Gets the locally cached MemberInfo
        case .remoteFetch:
            memberInfo.userId = xxx //Gets the latest remote MemberInfo
        }
        
        callback(IAPWalletMemberInfoFetchResult(memberInfo: memberInfo))
    }
}