时间,13位时间毫秒数,4位随机数,13位的时间戳,MAC地址"/>
UTC时间,13位时间毫秒数,4位随机数,13位的时间戳,MAC地址
string timestamp = "";
//使用UTC时间,ISO8601格式为"yyyy-MM-ddTHH:mm:ss.sss+08:00"
DateTime dt = DateTime.Now;
timestamp = dt.ToString("yyyy-MM-ddTHH:mm:ss.sss+08:00");
//使用13位时间毫秒数 + 4位随机数
System.Random Random = new System.Random();
int Result = Random.Next(1000, 9999);
string auth_Nonce = GetTimeStamp() + Result.ToString();
//获得13位的时间戳
System.DateTime time = System.DateTime.Now;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
long ts = (time.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
return ts.ToString();
//返回计算机MAC地址
string physicalAddress = "";
try {
InetAddress inetAddress = InetAddress.getLocalHost();
/**
* 获取电脑网卡的AMC地址
* 返回包含硬件地址的 byte 数组;如果地址不存在或不可访问,则返回 null
* 如果电脑因为网卡被禁用,则这里获取会返回 null
*/
byte[] mac = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress();
if (mac == null) {
return null;
}
StringBuffer stringBuffer = new StringBuffer("");
for (int i = 0; i < mac.length; i++) {
if (i != 0) {
stringBuffer.append("-");
}
/**
* 转换mac的字节数组
*/
int temp = mac[i] & 0xff;
String str = Integer.toHexString(temp);
if (str.length() == 1) {
stringBuffer.append("0" + str);
} else {
stringBuffer.append(str);
}
}
physicalAddress = stringBuffer.toString().toUpperCase();
} catch (SocketException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return physicalAddress;
更多推荐
UTC时间,13位时间毫秒数,4位随机数,13位的时间戳,MAC地址
发布评论