Ejemplo n.º 1
0
        public static string GetPicUrl(string productId, string messageType)
        {
            AppConnectLogHelper.DebugFormat("发消息图片地址:{0}", imgUrlFormat);
            string picUrl = "";

            if (string.IsNullOrEmpty(messageType))
            {
                AppConnectLogHelper.Error("获取消息图片产品Id为空!");
                return(picUrl);
            }
            string imgName = "italent_massage_03"; //默认是微信

            if (messageType == "21")               //如果是钉钉
            {
                imgName = "italent_massage_04";
            }
            switch (productId)
            {
            //审批中心
            case "907": picUrl = string.Format(imgUrlFormat, imgName); break;

            //核心人力
            case "908": picUrl = string.Format(imgUrlFormat, imgName); break;

            //假勤
            case "909": picUrl = string.Format(imgUrlFormat, imgName); break;

            //薪酬
            case "960": picUrl = string.Format(imgUrlFormat, imgName); break;

            default: picUrl = string.Format(imgUrlFormat, imgName); break;
            }
            return(picUrl);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取DFS内容
 /// </summary>
 /// <param name="dfsPath"></param>
 /// <returns></returns>
 public static byte[] GetDataFromDfsPath(string dfsPath)
 {
     try
     {
         if (string.IsNullOrEmpty(dfsPath))
         {
             return(null);
         }
         var    item = Dfs.Get(dfsPath);
         byte[] data = null;
         int    i    = 0;
         while (i < 5)
         {
             data = GetDataFromDfsItem(item);
             if (data != null)
             {
                 return(data);
             }
             else
             {
                 i++;
                 Thread.Sleep(300);
             }
         }
         return(data);
     }
     catch (Exception err)
     {
         AppConnectLogHelper.Error(string.Format("DfsHelper.GetDataFromDfsPath failed, dfsPaht:{0}, exception{1}", dfsPath, err));
         return(null);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 删除Redis
 /// </summary>
 /// <param name="key"></param>
 public static void DelRedis(string key)
 {
     try
     {
         using (var redis = new RedisNativeProviderV2(_KeySpace, _TenantId))
         {
             redis.Del(key);
         }
     }
     catch (Exception ex)
     {
         AppConnectLogHelper.Error(string.Format("GetRedis error:key={0}", key), ex);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 是否存在
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static bool IsExist(string key)
 {
     try
     {
         using (var redis = new RedisNativeProviderV2(_KeySpace, _TenantId))
         {
             return(redis.Exists(key));
         }
     }
     catch (Exception ex)
     {
         AppConnectLogHelper.Error(string.Format("RedisIsExist error:key={0}", key), ex);
     }
     return(false);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 写入Redis
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void SetRedis(string key, string value)
 {
     try
     {
         using (var redis = new RedisNativeProviderV2(_KeySpace, _TenantId))
         {
             var bytes = Encoding.UTF8.GetBytes(value);
             redis.Set(key, bytes);
         }
     }
     catch (Exception ex)
     {
         AppConnectLogHelper.Error(string.Format("SetRedis error:key={0},value={1}", key, value), ex);
     }
 }
Ejemplo n.º 6
0
        public static string AESDecrypt(string cipher)
        {
            MemoryStream msDecrypt = null;
            CryptoStream csDecrypt = null;
            StreamReader srDecrypt = null;
            Aes          aesAlg    = null;
            string       letter    = null;

            try
            {
                var decryptedBuffer = Base64ToBytes(cipher);
                aesAlg     = Aes.Create();
                aesAlg.Key = Encoding.UTF8.GetBytes(Key);
                aesAlg.IV  = Encoding.UTF8.GetBytes(IV);
                var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
                msDecrypt = new MemoryStream(decryptedBuffer);
                csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
                srDecrypt = new StreamReader(csDecrypt);
                letter    = srDecrypt.ReadToEnd();
            }
            catch (Exception ex)
            {
                AppConnectLogHelper.Error("AES解密失败:cipher=" + cipher, ex);
                return(null);
            }
            finally
            {
                if (srDecrypt != null)
                {
                    srDecrypt.Close();
                }
                if (csDecrypt != null)
                {
                    csDecrypt.Close();
                }
                if (msDecrypt != null)
                {
                    msDecrypt.Close();
                }
                if (aesAlg != null)
                {
                    aesAlg.Clear();
                }
            }
            return(letter);
        }
Ejemplo n.º 7
0
        public static string AESEncrypt(string letter)
        {
            MemoryStream msEncrypt = null;
            CryptoStream csEncrypt = null;
            StreamWriter swEncrypt = null;
            Aes          aesAlg    = null;

            try
            {
                aesAlg     = Aes.Create();
                aesAlg.Key = Encoding.UTF8.GetBytes(Key);
                aesAlg.IV  = Encoding.UTF8.GetBytes(IV);
                var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
                msEncrypt = new MemoryStream();
                csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
                swEncrypt = new StreamWriter(csEncrypt);
                swEncrypt.Write(letter);
            }
            catch (Exception ex)
            {
                AppConnectLogHelper.Error("AES加密失败:letter=" + letter, ex);
                return(null);
            }
            finally
            {
                if (swEncrypt != null)
                {
                    swEncrypt.Close();
                }
                if (csEncrypt != null)
                {
                    csEncrypt.Close();
                }
                if (msEncrypt != null)
                {
                    msEncrypt.Close();
                }
                if (aesAlg != null)
                {
                    aesAlg.Clear();
                }
            }
            return(ToBase64(msEncrypt.ToArray()));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 获取
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static string GetRedis(string key)
 {
     try
     {
         using (var redis = new RedisNativeProviderV2(_KeySpace, _TenantId))
         {
             var value = redis.Get(key);
             if (value != null && value.Length != 0)
             {
                 return(Encoding.UTF8.GetString(value));
             }
         }
     }
     catch (Exception ex)
     {
         AppConnectLogHelper.Error(string.Format("GetRedis error:key={0}", key), ex);
     }
     return(null);
 }
Ejemplo n.º 9
0
 public static string GetSginV2(int tenantId, int userId, int titaAppId, long timeStamp, int signType = 1)
 {
     try
     {
         //调用tita获取sign信息
         string requestUrl = string.Format("{0}/api/v1/{1}/{2}/sign?app_id={3}&time_stamp={4}&sign_type={5}", TitaApiUrl, tenantId, userId, titaAppId, timeStamp, signType);
         AppConnectLogHelper.DebugFormat("GetSginV2-Url:{0}", requestUrl);
         string resultStr   = HttpClientHelper.HttpGet(requestUrl);
         var    resultModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ApiResultModel>(resultStr);
         if (resultModel.Code != 0)
         {
             AppConnectLogHelper.Error("GetSginV2-获取数据api失败");
             return(string.Empty);
         }
         return(resultModel.Data.ObjData);
     }
     catch (Exception ex)
     {
         AppConnectLogHelper.ErrorFormat("GetSginV2-获取数据api异常:{0}", ex.Message);
         return(string.Empty);
     }
 }
Ejemplo n.º 10
0
        private static void SendMessage(int tenantId, AddMessageModel model)
        {
            ArgumentHelper.AssertNotNull(model);
            ArgumentHelper.AssertPositive(tenantId);
            ArgumentHelper.AssertPositive(model.FromUserId);

            string url = string.Format(TitaApiUrl + "/api/v1/{0}/{1}/message", tenantId, model.FromUserId);

            try
            {
                var resultStr = HttpClientHelper.HttpPost(url, model);
                var result    = JsonConvert.DeserializeObject <ApiResult <object> >(resultStr);
                if (result.code != 0)
                {
                    AppConnectLogHelper.ErrorFormat("Tita发送消息接口出错!租户:{0},发送人:{1}", tenantId, model.FromUserId);
                }
            }
            catch (Exception ex)
            {
                AppConnectLogHelper.ErrorFormat("发送消息出错!接口Url:{0},租户:{1},发送人:{2},异常信息:{3}", url, tenantId, model.FromUserId, JsonConvert.SerializeObject(ex));
            }
        }
Ejemplo n.º 11
0
        public static string GetPicUrlByTag(string tag)
        {
            string picUrl = "";

            if (string.IsNullOrEmpty(tag))
            {
                AppConnectLogHelper.Error("获取消息图片tag为空!");
                return(picUrl);
            }

            var tags = tag.Split('_');

            if (tags.Length == 2)
            {
                string imgName = "italent_massage_03"; //默认是微信
                if (tags[1] == "21")                   //如果是钉钉
                {
                    imgName = "italent_massage_04";
                }

                switch (tags[0])
                {
                //审批中心
                case "907": picUrl = string.Format(imgUrlFormat, imgName); break;

                //核心人力
                case "908": picUrl = string.Format(imgUrlFormat, imgName); break;

                //假勤
                case "909": picUrl = string.Format(imgUrlFormat, imgName); break;

                //薪酬
                case "960": picUrl = string.Format(imgUrlFormat, imgName); break;

                default: picUrl = string.Format(imgUrlFormat, imgName); break;
                }
            }
            return(picUrl);
        }