Kus*_*yar 6 c# unique-id windows-phone-8.1
我想要back_end服务(ws)的唯一设备ID,我发现以下参考
private string GetDeviceId()
{
var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
var hardwareId = token.Id;
var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] bytes = new byte[hardwareId.Length];
dataReader.ReadBytes(bytes);
return BitConverter.ToString(bytes).Replace("-", "");
}//Note: This function may throw an exception.
Run Code Online (Sandbox Code Playgroud)
但是,我无法理解代码,每次我为我的设备获得相同的Id(64个字符串),我想知道它是否适用?我也找不到MSDN的任何参考资料
谢谢
这可能会有所帮助:
private string GetDeviceID()
{
HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null);
IBuffer hardwareId = token.Id;
HashAlgorithmProvider hasher = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
IBuffer hashed = hasher.HashData(hardwareId);
string hashedString = CryptographicBuffer.EncodeToHexString(hashed);
return hashedString;
}
Run Code Online (Sandbox Code Playgroud)
有关文档,请查看HardwareIdentification类中的GetPackageSpecificToken方法。