Esempio n. 1
0
        /// <summary>
        /// 获得TOKEN
        /// https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx7374191e442b14ef&secret=c2f9f7d4a6985b2dd0194a86b2254d8c
        /// </summary>
        /// <returns></returns>
        public Model.weixin.token GetToken()
        {
            //if (EndTime > DateTime.Now)
            //    return tokenmodel;
            string               url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + appkey;
            StringBuilder        sb  = new StringBuilder();
            string               str = Get(url);
            JavaScriptSerializer jss = new JavaScriptSerializer();

            try
            {
                tokenmodel = jss.Deserialize <Model.weixin.token>(str);
                EndTime    = System.DateTime.Now.AddSeconds(tokenmodel.expires_in);
                return(tokenmodel);
            }
            catch (Exception ex)
            {
                TxtLog.Add("微信获得TOKEN异常:" + ex.ToString());
                return(new Model.weixin.token());
            }
        }
Esempio n. 2
0
 public void SetMemchche(string Key, object obj, string TableName, int Keyid, string Para, int seconds)
 {
     try
     {
         DateTime now = System.DateTime.Now;
         TextExecuteNonQuery("delete from Lebi_Memcache where CacheKey='" + Key + "'");//删除已有记录
         MemcacheInstance.Set(Key, obj, now.AddSeconds(seconds));
         if (MemcacheInstance != null)
         {
             if (Para.Length > 1000)
             {
                 Para = Para.Substring(0, 1000);
             }
             StringBuilder strSql = new StringBuilder();
             strSql.Append("insert into `Lebi_Memcache`(");
             strSql.Append("CacheKey,TableName,Keyid,Para,Time_Add,Time_End,seconds)");
             strSql.Append(" values (");
             strSql.Append("@CacheKey,@TableName,@Keyid,@Para,@Time_Add,@Time_End,@seconds)");
             SqlParameter[] parameters =
             {
                 new SqlParameter("@CacheKey",  Key),
                 new SqlParameter("@TableName", TableName),
                 new SqlParameter("@Keyid",     Keyid),
                 new SqlParameter("@Para",      Para),
                 new SqlParameter("@Time_Add",  now),
                 new SqlParameter("@Time_End",  now.AddSeconds(seconds)),
                 new SqlParameter("@seconds",   seconds)
             };
             TextExecuteNonQuery(strSql.ToString(), parameters);
         }
     }
     catch (Exception ex)
     {
         TxtLog.Add(ex.Message);
     }
 }