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
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:

  • 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

memberInfoScope

MemberInfoScope

The scopes of MemberInfo.

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

MemberInfoResult

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 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.

Java

copy
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

copy
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))
    }
}