Beispiel #1
0
        /// <summary>
        /// 删除应用授权
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public DelAppIdAuthResponse DelAppIdAuth(DelAppIdAuthRequest request)
        {
            var response = new DelAppIdAuthResponse();

            try
            {
                var entity = _appIdAuthTokenRepository.Find <AppIdAuthPo>(e => e.IsValid == 1 && e.Id == request.Id);

                if (entity == null)
                {
                    throw new Exception("删除应用授权不存在");
                }

                entity.IsValid = 0;
                EntityLogger.UpdateEntity(entity);

                _appIdAuthTokenRepository.UpdateColumns(entity, (e) => new { e.IsValid, e.UpdateTime, e.UpdateUserId });
            }
            catch (Exception ex)
            {
                response.IsSuccess   = false;
                response.MessageCode = "-1";
                response.MessageText = ex.Message;
                LogManager.LogicLogger.ErrorFormat("删除应用授权出错:{0}", new { request, err = ex.ToString() }.ToJson());
            }
            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// 保存秘钥
        /// </summary>
        /// <param name="request">参数</param>
        /// <returns></returns>
        public SaveSecretKeyResponse SaveSecretKey(SaveSecretKeyRequest request)
        {
            var response = new SaveSecretKeyResponse();

            try
            {
                if (request.Entity == null || request.Entity.Id == 0)
                {
                    response.IsSuccess   = false;
                    response.MessageCode = "1";
                    response.MessageText = "参数不能为空";
                    return(response);
                }

                var entitytemp = _appIdAuthTokenRepository.FindSingle <AppIdAuthPo>(request.Entity.Id);

                if (entitytemp == null)
                {
                    response.IsSuccess   = false;
                    response.MessageCode = "2";
                    response.MessageText = "修改不存在";
                    return(response);
                }

                entitytemp.SecretKey  = request.Entity.SecretKey;
                entitytemp.PrivateKey = request.Entity.PrivateKey;
                entitytemp.PublicKey  = request.Entity.PublicKey;

                EntityLogger.UpdateEntity(entitytemp);

                if (entitytemp.EncryptionType == 3)
                {
                    #region 检查秘钥是否合法
                    var testtxt = "mayiboy";

                    if (RsaCryption.Decrypt(request.Entity.PrivateKey, RsaCryption.Encrypt(request.Entity.PublicKey, testtxt)) != testtxt)
                    {
                        response.IsSuccess   = false;
                        response.MessageCode = "4";
                        response.MessageText = "非对称加密有误";
                        return(response);
                    }
                    #endregion

                    _appIdAuthTokenRepository.UpdateColumns(entitytemp, e => new
                    {
                        e.UpdateUserId,
                        e.UpdateTime,
                        e.PrivateKey,
                        e.PublicKey
                    });
                }
                else
                {
                    #region 检查秘钥是否合法
                    if (entitytemp.EncryptionType == 1 && entitytemp.SecretKey.Length < 8)
                    {
                        response.IsSuccess   = false;
                        response.MessageCode = "3";
                        response.MessageText = "秘钥长度不能小于8";
                        return(response);
                    }
                    else if (entitytemp.EncryptionType == 2 && entitytemp.SecretKey.Length < 32)
                    {
                        response.IsSuccess   = false;
                        response.MessageCode = "4";
                        response.MessageText = "秘钥长度不能小于32";
                        return(response);
                    }
                    #endregion

                    _appIdAuthTokenRepository.UpdateColumns(entitytemp, e => new
                    {
                        e.UpdateUserId,
                        e.UpdateTime,
                        e.SecretKey,
                    });
                }

                var key = entitytemp.AppId.AddCachePrefix("AppIdAuth");

                CacheManager.RedisDefault.Del(key);
            }
            catch (Exception ex)
            {
                response.IsSuccess   = false;
                response.MessageCode = "-1";
                response.MessageText = ex.Message;
                LogManager.LogicLogger.ErrorFormat("保存秘钥出错:{0}", new { request, err = ex.ToString() }.ToJson());
            }
            return(response);
        }