Native App接入WindVane小程式容器或uni-app小程式容器後,可以在運行時將登入使用者關聯到小程式容器。
除非App使用者尚未登入的情況下,否則在App使用者登入或切換帳號時,App必須在運行時將登入使用者關聯到小程式容器,關聯後小程式容器會在以下情境中使用使用者資訊(僅UserId):
判斷目前使用者是否具備相應的裝置授權
切換使用者時SDK會根據使用者資訊是否發生變化從而自動清理掉WindVane小程式的Cookie
PV、UV等資料上報時(需引入上報外掛程式)
在應用開放平台使用小程式白名單灰階功能
關聯使用者
小程式白名單灰階功能和自動清理WindVane小程式緩衝功能需要調用以下介面關聯使用者才能使用。關聯代碼如下:
ServiceManager.getInstance().registerService(IUserInfoService.class.getName(), new IUserInfoService() {
@Override
public UserInfo getUserInfo() {
//根據登入情況,返回UserInfo,未登入返回null。
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userId);
return userInfo;
}
});判斷裝置許可權
private boolean isAuthorized() {
IUserInfoService userInfoService = ServiceManager.getInstance()
.getService(IUserInfoService.class.getName());
// ...
UserInfo userInfo = userInfoService.getUserInfo();
// ...
return AuthorizationManagement
.getInstance(mContext)
.isAuthorized(innerScope, userInfo.getUserId(), appId);
}
清除Cookie
private void clearMiniAppCookies(...) {
IUserInfoService userInfoService = ServiceManager.getInstance()
.getService(IUserInfoService.class.getName());
// ...
UserInfo userInfo = userInfoService.getUserInfo();
// ...
if (isDifferentUser(userInfo.getUserId())) {
clearCookie();
}
}
資料上報
private void reportData(...) {
IUserInfoService userInfoService = ServiceManager.getInstance()
.getService(IUserInfoService.class.getName());
// ...
UserInfo userInfo = userInfoService.getUserInfo();
// ...
report(userInfo.getUserId());
}