求助:关于wp8/8.1中获取到的用户ANID、ANID2(匿名ID)的两点疑问
通过网络及msdn的相关资料找到以下方式
UserExtendedProperties.TryGetValue("ANID2", out anid)
private static readonly int ANIDLength = 32;
private static readonly int ANIDOffset = 2;
publicstaticstring GetWindowsLiveAnonymousID()
{
string result = string.Empty;
object anid;
if (UserExtendedProperties.TryGetValue("ANID", out anid)) //msdn指出在wp7内为ANID,wp8为ANID2
{
if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset))
{
result = anid.ToString().Substring(ANIDOffset, ANIDLength);
}
}
return result;
}
获取到的用户匿名id长度超过34时,从2号索引位截取32位长字符串为用户匿名id
我的疑问如下
1.为何从2号索引位开始截取32位长度,之前的两个字符作何用?32位之后的作何用?
2.获取到的匿名id是否为用户唯一id,及更换不同设备但使用同一微软账号登录手机时该匿名id是否会有变化?
1、2综合问题:获取到的匿名id是否仅中间的32位相同,前面两位及34之后的字符在不同机器上是同或不同?
求大神解答!!!
补充:
微软的技术文档地址如下
https://msdn.microsoft.com/zh-cn/library/windows/apps/microsoft.phone.info.userextendedproperties.trygetvalue(v=vs.105).aspx
其中明确指出了wp7和wp8中ANID的区别,并说明获取到的值转为字符串后为32位。
但我在实际测试的时候去掉了原代码中的长度判断和截取,获取到的东西转为字符串后长度超过40,直接让我晕菜了。
测试代码如下
publicstaticstring GetWindowsLiveAnonymousID()
{
string result = string.Empty;
object anid;
if (UserExtendedProperties.TryGetValue("ANID", out anid)) //msdn指出在wp7内为ANID,wp8为ANID2
{
if (anid != null)
{
result = anid.ToString();
}
}
return result;
}
求高人!