/// <summary> /// 新增令牌 /// </summary> /// <param name="tokenEntity"></param> /// <returns></returns> public bool AddToken(TokenEntity tokenEntity) { bool flag = false; StringBuilder sqlCommandText = new StringBuilder(); sqlCommandText.Append(" @JournalID"); sqlCommandText.Append(", @AuthorID"); sqlCommandText.Append(", @Token"); sqlCommandText.Append(", @Type"); DbCommand cmd = db.GetSqlStringCommand(String.Format("INSERT INTO dbo.Token ({0}) VALUES ({1})",sqlCommandText.ToString().Replace("@", ""),sqlCommandText.ToString())); db.AddInParameter(cmd, "@JournalID", DbType.Int64, tokenEntity.JournalID); db.AddInParameter(cmd,"@AuthorID",DbType.Int64,tokenEntity.AuthorID); db.AddInParameter(cmd,"@Token",DbType.AnsiString,tokenEntity.Token); db.AddInParameter(cmd,"@Type",DbType.Byte,tokenEntity.Type); try { db.ExecuteNonQuery(cmd); flag = true; } catch(SqlException sqlEx) { throw sqlEx; } return flag; }
public XmlDocument Login(string strMagazineName, string strUserName, string strPassword) { string returnXml = @" <login> <result>{0}</result> <user_id>{1}</user_id> <safety_code>{2}</safety_code> <magazine_id>{3}</magazine_id> </login> "; string strToekCode = RadomCode.GenerateCode(10) + DateTime.Now.Ticks; IAuthorFacadeService authorService = ServiceContainer.Instance.Container.Resolve<IAuthorFacadeService>(); TokenEntity getPwdToken = new TokenEntity(); getPwdToken.Token = strToekCode; getPwdToken.JournalID = SiteConfig.SiteID; getPwdToken.Type = 3; // API Token getPwdToken.AuthorID = 0; authorService.InsertToken(getPwdToken); string result = string.Format(returnXml, 0, SiteConfig.SiteID, strToekCode, SiteConfig.SiteID); XmlDocument xd = new XmlDocument(); XmlDeclaration xmldecl; xmldecl = xd.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement root = xd.DocumentElement; xd.InsertBefore(xmldecl, root); xd.LoadXml(result); return xd; }
public ExecResult InsertToken(TokenEntity tokenEntity) { ExecResult execResult = new ExecResult(); try { ITokenService tokenService = ServiceContainer.Instance.Container.Resolve<ITokenService>(); tokenService.AddToken(tokenEntity); execResult.result = EnumJsonResult.success.ToString(); execResult.msg = "添加令牌成功"; } catch (Exception ex) { execResult.result = EnumJsonResult.error.ToString(); execResult.msg = "添加令牌失败:" + ex.Message; LogProvider.Instance.Error("添加令牌出现异常:" + ex.Message); } return execResult; }
/// <summary> /// 新增令牌 /// </summary> /// <param name="token">TokenEntity实体对象</param> /// <returns>true:存储成功 false:存储失败</returns> public bool AddToken(TokenEntity token) { return TokenBusProvider.AddToken(token); }
/// <summary> /// 获取令牌 /// </summary> /// <param name="tokenID"></param> /// <returns></returns> public TokenEntity GetToken(TokenQuery tokenQuery) { TokenEntity tokenEntity=null; StringBuilder sqlCommandText = new StringBuilder(); sqlCommandText.Append("SELECT TOP 1 TokenID,AuthorID,Token,Type,AddDate FROM dbo.Token WITH(NOLOCK)"); sqlCommandText.Append(" WHERE JournalID=@JournalID AND AuthorID=@AuthorID AND AddDate>=@ExpireDate"); if (!string.IsNullOrEmpty(tokenQuery.Token)) { sqlCommandText.Append(" AND Token=@Token"); } if (tokenQuery.Type > 0) { sqlCommandText.Append(" AND Type=@Type"); } DbCommand cmd = db.GetSqlStringCommand(sqlCommandText.ToString()); db.AddInParameter(cmd, "@JournalID", DbType.Int64, tokenQuery.JournalID); db.AddInParameter(cmd, "@AuthorID", DbType.Int64, tokenQuery.AuthorID); if (!string.IsNullOrEmpty(tokenQuery.Token)) { db.AddInParameter(cmd, "@Token", DbType.String, tokenQuery.Token); } if (tokenQuery.Type > 0) { db.AddInParameter(cmd, "@Type", DbType.Int16, tokenQuery.Type); } db.AddInParameter(cmd, "@ExpireDate", DbType.DateTime, tokenQuery.ExpireDate); using(IDataReader dr = db.ExecuteReader(cmd)) { if (dr.Read()) { tokenEntity = new TokenEntity(); tokenEntity.TokenID = (Int64)dr["TokenID"]; tokenEntity.AuthorID = (Int64)dr["AuthorID"]; tokenEntity.Token = (String)dr["Token"]; tokenEntity.Type = (Byte)dr["Type"]; tokenEntity.AddDate = (DateTime)dr["AddDate"]; } dr.Close(); } return tokenEntity; }
/// <summary> /// 新增令牌 /// </summary> /// <param name="token">TokenEntity实体对象</param> /// <returns>true:存储成功 false:存储失败</returns> public bool AddToken(TokenEntity token) { return TokenDataAccess.Instance.AddToken(token); }