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
void getMemberInfo(MemberInfoFetchStrategy memberInfoFetchStrategy, MemberInfoScope memberInfoScope, APIContext apiContext, Callback<MemberInfoResult> callback)
Request parameters
Field | Data type | Description | Required |
memberInfoFetchStrategy | String | The strategy of getting users' information. Valid values are:
| Yes |
memberInfoScope | The scopes of | Yes | |
apiContext | APIContext | 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 | 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 implement the MemberService SPI to provide basic user information to the SDK and mini programs:
- Create a class that implements the MemberService interface.
- Implement the
getMemberInfo
method.
Java
public void MemberServiceImpl implements MemberService {
@Override
public void getMemberInfo(MemberInfoFetchStrategy memberInfoFetchStrategy,
MemberInfoScope memberInfoScope, APIContext apiContext,
Callback<MemberInfoResult> callback) {
MemberInfo memberInfo = new MemberInfo();
switch (memberInfoFetchStrategy) {
case LOCAL_USER_ID_ONLY:
memberInfo.userId = //Gets the locally cached user id but payloaded into MemberInfo
break;
case REMOTE_FETCH:
memberInfo = //Gets the latest remote MemberInfo
break;
}
callback.result(
new MemberInfoResult(memberInfo);
}
}
Kotlin
class MemberServiceImpl : MemberService {
override fun getMemberInfo(memberInfoFetchStrategy: MemberInfoFetchStrategy?,
memberInfoScope: MemberInfoScope?, apiContext: APIContext?,
callback: Callback<MemberInfoResult>?) {
val memberInfo = MemberInfo().apply {
when (memberInfoFetchStrategy) {
MemberInfoFetchStrategy.LOCAL_USER_ID_ONLY -> {
userId = // Gets the locally cached user id but payloaded into MemberInfo
}
MemberInfoFetchStrategy.REMOTE_FETCH -> {
this = // Gets the latest remote MemberInfo
}
}
}
callback.result(MemberInfoResult(memberInfo))
}
}