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
void getMemberInfo(MemberInfoFetchStrategy memberInfoFetchStrategy, MemberInfoScope memberInfoScope, APIContext apiContext, Callback<MemberInfoResult> callback)

Request parameters

Field

Data type

Description

Required

memberInfoFetchStrategy

String

The strategy of gettiing members' information. Valid values are:

  • LOCAL_USER_ID_ONLY:Gets the locally cached user id but payloaded into MemberInfo. Used when distinguishing storage by userid inside the miniprogram, such as my.setStorage
  • REMOTE_FETCH:Gets the latest remote MemberInfo. 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 (For details, see the following section)

The callback that is executed when request processing is complete.

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

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 LOCAL_CACHED:
                memberInfo =  //Gets the locally cached 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.LOCAL_CACHED -> {
                    this = // Gets the locally cached MemberInfo
                }
                MemberInfoFetchStrategy.REMOTE_FETCH -> {
                    this = // Gets the latest remote MemberInfo
                }
            }
        }
        callback.result(MemberInfoResult(memberInfo))
    }
}