MemberInfoService
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
getMemberInfo(
strategy: MemberInfoFetchStrategy,
scope: MemberInfoScope,
apiContext: APIContext
): Promise<MemberInfoFetchResult>;
Request parameters
Field | Data type | Required | Description |
strategy | MemberInfoFetchStrategy | Yes | The strategy of getting users' information. Valid values are:
|
scope | Yes | An object that specifies the types of the user information that is requested. | |
apiContext | APIContext | Yes | A context object, which carries the mini program runtime metadata. |
Response parameters
Field | Data type | Required | Description |
result | Promise<MemberInfoFetchResult> | Yes | The result of the |
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. |
Sample
The following sample shows how to implement the MemberInfoService SPI to provide basic user information to the SDK and mini programs:
- Create a class that implements the MemberInfoService interface.
- Implement the
getMemberInfo
method.
import type {
MemberInfoFetchStrategy,
MemberInfoScope,
APIContext,
MemberInfoFetchResult,
MemberInfo,
} from 'iapminiprogram-rn';
import type { MemberInfoService } from 'iapminiprogram-rn';
class TestMemberInfoService implements MemberInfoService {
async getMemberInfo(
strategy: MemberInfoFetchStrategy,
scope: MemberInfoScope,
apiContext: APIContext
): Promise<MemberInfoFetchResult> {
return new Promise<MemberInfoFetchResult>(function (resolve) {
const memberInfo: MemberInfo = {
userId: 'userId_xxx',
avatar: 'avatar_xxx',
};
const result: MemberInfoFetchResult = {
memberInfo: memberInfo,
};
resolve(result);
});
}
}