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.
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:
| No |
scope | The scopes of | 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 | The result of the | 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:
- Create a class that implements the MemberService interface.
- Within this class, implement the
getMemberInfo
method to fetch the member information according to the specified strategy.
Swift
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))
}
}