Пример #1
0
        /// <summary>
        /// 获取token
        /// </summary>
        /// <returns></returns>

        public string GetToken()
        {
            try
            {
                string         userName = ConfigCom.W_UserName;
                string         userPass = ConfigCom.W_UserPass;
                string         uri      = ConfigCom.W_TokenUri;
                DataEncryption data     = new DataEncryption();
                //加密方法
                string     encryUserName = data.Encryption(userName);
                string     encryUserPass = data.Encryption(userPass);
                RestClient rc            = new RestClient(baseUri);
                string     res           = rc.Get(uri + "/" + encryUserName + "/" + encryUserPass);
                //验证res
                if (string.IsNullOrWhiteSpace(res))
                {
                    ConfigCom.SetValue("W_ID", res);
                    ConfigCom.SetValue("W_TokenExpire", DateTime.Now.AddMinutes(Convert.ToDouble(ConfigCom.W_TokenExpireInterval)).ToString("yyyy-MM-dd HH:mm:ss"));
                    return(res);
                }
                else
                {
                    log.Error("GetToken()返回值为空");
                    return("");
                }
            }
            catch (Exception ex)
            {
                log.Error("GetToken()出错:" + ex.Message.ToString());
                return("false");
            }
        }
Пример #2
0
 private void SetAppConfigDate()
 {
     try
     {
         ConfigCom.SetValue("W_ReadLastDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
         ConfigCom.SetValue("W_UploadLastDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
         ConfigCom.SetValue("W_UploadQueryLastDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
         ConfigCom.SetValue("E_ActiveEnergyQueryLastDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
         ConfigCom.SetValue("E_readRemainMoneyLastDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
         ConfigCom.SetValue("E_rechargeEleLastDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
     }
     catch (Exception ex)
     {
         log.Error("SetAppConfigDate()报错:" + ex.Message.ToString());
     }
 }