这就是我在几天内通过令牌到期的方式:
tokenOptions.Add(TokenPropertyConstants.EXPIRE_TIME, new DateTime(2014, 03, 24)); //date of tomorrow
我的主要问题是我需要EXPIRE_TIME
从服务器端设置。如何修复EXPIRE_TIME
从创建时间开始的 15 分钟?
我试过这个,但它不工作:
tokenOptions.Add(TokenPropertyConstants.EXPIRE_TIME, new DateTime(2014, 03, 23, 18, 20, 00)); //15 minutes more than current time
EXPIRE_TIME 所在的 tokenOptions 下的代码如下所示
public string GenerateToken(string sessionId)
{
Dictionary<string, object> options = new Dictionary<string, object>();
return GenerateToken(sessionId, options);
}
public string GenerateToken(string sessionId, Dictionary<string, object> options)
{
NameValueCollection appSettings = ConfigurationManager.AppSettings;
options.Add("session_id", sessionId);
options.Add("create_time", (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
options.Add("nonce", RandomNumber(0, 999999));
if (!options.ContainsKey(TokenPropertyConstants.ROLE))
{
options.Add(TokenPropertyConstants.ROLE, "publisher");
}
// Convert expire time to Unix Timestamp
if (options.ContainsKey(TokenPropertyConstants.EXPIRE_TIME))
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0);
DateTime expireTime = (DateTime)options[TokenPropertyConstants.EXPIRE_TIME];
TimeSpan diff = expireTime - origin;
options[TokenPropertyConstants.EXPIRE_TIME] = Math.Floor(diff.TotalSeconds);
}
string dataString = string.Empty;
foreach (KeyValuePair<string, object> pair in options)
{
dataString += pair.Key + "=" + HttpUtility.UrlEncode(pair.Value.ToString()) + "&";
}
dataString = dataString.TrimEnd('&');
string sig = SignString(dataString, appSettings["opentok_secret"].Trim());
string token = string.Format("{0}{1}", appSettings["opentok_token_sentinel"], EncodeTo64(string.Format("partner_id={0}&sdk_version={1}&sig={2}:{3}", appSettings["opentok_key"], appSettings["opentok_sdk_version"], sig, dataString)));
return token;
}