public static string GetToken(string userId) { cleanExpired(); string key = userId; lock (lockObject) { if (dictIdSecretWithSid.ContainsKey(key)) { return(dictIdSecretWithSid[key].ToString()); } } long sid = LeafSnowflake.getID(); Token token = new Token(); token.UserID = userId; token.ExpireTime = DateTime.Now.AddHours(2); AppSessionBLL.SaveToken(sid, token); lock (lockObject) { dictToken.Add(sid, token); dictIdSecretWithSid.Add(key, sid); } return(sid.ToString()); }
public static string GetToken(long appId, string appSecret) { cleanExpired(); string key = appId + "_" + appSecret; lock (lockObject) { if (dictIdSecretWithSid.ContainsKey(key)) { return(dictIdSecretWithSid[key].ToString()); } } if (AppInfoBLL.Valid(appId, appSecret)) { long sid = LeafSnowflake.getID(); Token token = new Token(); token.UserID = appId.ToString(); token.ExpireTime = DateTime.Now.AddHours(2); AppSessionBLL.SaveToken(sid, token); lock (lockObject) { dictToken.Add(sid, token); dictIdSecretWithSid.Add(key, sid); } return(sid.ToString()); } else { return(null); } }