Пример #1
0
        public ResultEntity <ResponseToken> RefreshToken(string refToken)
        {
            ResultEntity <ResponseToken> result = new ResultEntity <ResponseToken>();
            string url = _configuration["Id4Config:Id4Url"] + "connect/token";
            requireUserPwdToken upToken = new requireUserPwdToken
            {
                grant_type    = "refresh_token",
                client_id     = _configuration["Id4Config:client_id"],
                client_secret = _configuration["Id4Config:client_secret"],
                refresh_token = refToken,
            };

            try
            {
                var data = $"grant_type={upToken.grant_type}&client_id={upToken.client_id}&client_secret={upToken.client_secret}&refresh_token={upToken.refresh_token}";
                var res  = HttpUtil.Send(url, HttpUtil.HttpMethod.Post, data, HttpUtil.application_form);
                result.Entity = JsonConvert.DeserializeObject <ResponseToken>(res);
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt($"【UserController】GetUserPwdToken:{ex.Message}");
                result.ErrorMsg = CCWebMsg.Token_GetUserPwdToken;
            }

            return(result);
        }
Пример #2
0
        public ResultNormal ossMove(string fromPath, string toPath)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                if (OssClient.DoesObjectExist(_OssConfig.bucketName, fromPath))
                {
                    var metadata = new ObjectMetadata();
                    //metadata.AddHeader("mk1", "mv1");
                    //metadata.AddHeader("mk2", "mv2");
                    var req = new CopyObjectRequest(_OssConfig.bucketName, fromPath, _OssConfig.bucketName, toPath)
                    {
                        NewObjectMetadata = metadata
                    };
                    // 拷贝文件。
                    OssClient.CopyObject(req);
                    OssClient.DeleteObject(_OssConfig.bucketName, fromPath);
                }
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt("Oss Services-moveOss:" + ex.Message);
                result.ErrorMsg = ex.Message;
            }
            return(result);
        }
Пример #3
0
        public void deleteComment_Res(long commentId)
        {
            try
            {
                _commentResRepository.Db.Ado.BeginTran();

                //删除评论
                _commentResRepository.DeleteByKey(commentId);

                //删除对应的所有回复[ccCommentReply_Res]
                _commentReplyResRepository.DeleteAllReplyByCommentId(commentId);

                //删除评论点赞
                _praizeRepository.DeletePraized_Comment_Res(commentId, null);
                //删除评论对应的所有回复 点赞
                _praizeRepository.DeletePraized_AllReplyBelowComment(commentId);

                _commentResRepository.Db.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                _commentResRepository.Db.Ado.RollbackTran();

                NLogUtil.cc_ErrorTxt("CommentServices deleteComment_Res:" + ex.Message);
                throw new Exception("删除评论失败");
            }
        }
Пример #4
0
        public ResultPager <VueResInfo> GetAllResourcesByRefCode(QRes qRes)
        {
            ResultPager <VueResInfo> result = new ResultPager <VueResInfo>();

            try
            {
                qRes.reqUserId  = this.getUserId();
                result.PageData = _resourceServices.getResByRefCode(qRes);
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt("[BookController]GetAllResourcesByRefCode:" + ex.Message);
                result.ErrorMsg = "查询失败";
            }
            return(result);
        }
 private void async_CreateCommentMessage(SubmitComment submitComment, long commentId)
 {
     Task.Run(() =>
     {
         try{
             _messageServices.CreateNotification_Comment(new MsgSubmitComment
             {
                 SubmitComment = submitComment,
                 CommentId     = commentId,
             });
         }
         catch (Exception msgEx) {
             NLogUtil.cc_ErrorTxt("【评论通知】错误:" + msgEx.Message);
         }
     });
 }
        //异步方法 查询后获取未读消息转成已读
        public void Async_MsgToReadAfterQuery(QMsgUser query,
                                              List <VueMsgInfoNotification> queryResult = null,
                                              List <VueSystemNotification> systemResult = null //由于系统消息对象不同,暂时只能这样写。。。
                                              )
        {
            Task.Run(() =>
            {
                try
                {
                    SubmitUnReadMsgIdList unReadList = new SubmitUnReadMsgIdList();
                    if (query.notificationType == NotificationType.system)
                    {
                        foreach (var msg in systemResult)
                        {
                            if (msg.NotificationStatus != NotificationStatus.read)
                            {
                                unReadList.msgIdList.Add(msg.msgId);
                            }
                        }
                    }
                    else
                    {
                        foreach (var msg in queryResult)
                        {
                            if (msg.NotificationStatus != NotificationStatus.read)
                            {
                                unReadList.msgIdList.Add(msg.msgId);
                            }
                        }
                    }

                    if (unReadList.msgIdList.Count > 0)
                    {
                        unReadList.notificationType = query.notificationType;
                        unReadList.targetStatus     = NotificationStatus.read;
                        unReadList.userId           = query.userId;


                        this.updateMsgToRead(unReadList);
                    }
                }
                catch (Exception ex)
                {
                    NLogUtil.cc_ErrorTxt("[MessageService]MsgToReadAfterQuery_Async:" + ex.Message);
                }
            });
        }
Пример #7
0
        public ResultNormal ossDelete(string ossPath)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                if (OssClient.DoesObjectExist(_OssConfig.bucketName, ossPath))
                {
                    OssClient.DeleteObject(_OssConfig.bucketName, ossPath);
                }
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt("Oss Services-deleteOss:" + ex.Message);
                result.ErrorMsg = ex.Message;
            }
            return(result);
        }
 private void async_CreateReplyMessage(SubmitReply submitReply, long replyId)
 {
     Task.Run(() =>
     {
         try
         {
             _messageServices.CreateNotification_Reply(new MsgSubmitReply
             {
                 SubmitReply = submitReply,
                 ReplyId     = replyId,
             });
         }
         catch (Exception msgEx)
         {
             NLogUtil.cc_ErrorTxt("【回复通知】错误:" + msgEx.Message);
         }
     });
 }
Пример #9
0
        private string RequireVerifySMSCode(SMSRequire sms)
        {
            string url  = _configuration["Id4Config:Id4Url"] + "sms/SubmitVerifyCode";
            string json = JsonConvert.SerializeObject(sms);
            string res  = "";

            try
            {
                res = HttpUtil.Send(url, HttpUtil.HttpMethod.Post, json, HttpUtil.application_json);
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt($"【UserController】RequireVerifySMSCode:{ex.Message}");
                throw new CCException(CCWebMsg.SMS_RequireVerifySMSCode);
            }

            return(res);
        }
 private void asyncCreateMessage(SubmitPraize submitPraize, long praizeId)
 {
     Task.Run(() =>
     {
         try
         {
             _messageServices.CreateNotification_Praize(new MsgSubmitPraize
             {
                 SubmitPraize = submitPraize,
                 PraizeId     = praizeId,
             });
         }
         catch (Exception msgEx)
         {
             NLogUtil.cc_ErrorTxt("【点赞通知】错误:" + msgEx.Message);
         }
     });
 }
Пример #11
0
        public ResultNormal uploadToOss(string localfilePath, string ossKey, bool isCover = true)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                var l = ossKey.Length;
                if (isCover || (!isCover && !ossExist(ossKey)))
                {
                    OssClient.PutObject(_OssConfig.bucketName, ossKey, localfilePath);
                }
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt("Oss Services-uploadFile:" + ex.Message);
                result.ErrorMsg = ex.Message;
            }
            return(result);
        }
        public ResultPager <VueUserPointTrans> getPointTrans(QUserTrans query)
        {
            ResultPager <VueUserPointTrans> result = new ResultPager <VueUserPointTrans>();

            try
            {
                query.userId    = this.getUserId();
                result.PageData = _userFinanceServices.getPointTrans(query);
            }
            catch (CCException cex)
            {
                result.ErrorMsg = cex.Message;
            }
            catch (Exception ex)
            {
                result.ErrorMsg += "[积分明细查询失败]";
                NLogUtil.cc_ErrorTxt("[UserFinanceController]getPointTrans:" + ex.Message);
            }
            return(result);
        }
        public ResultEntity <VueUserFinanceOverview> getOverview(string userId)
        {
            ResultEntity <VueUserFinanceOverview> result = new ResultEntity <VueUserFinanceOverview>();

            try
            {
                userId        = this.getUserId();
                result.Entity = _userFinanceServices.getOverview(userId);
            }
            catch (CCException cex)
            {
                result.ErrorMsg = cex.Message;
            }
            catch (Exception ex)
            {
                result.ErrorMsg += "[钱包概况查询失败]";
                NLogUtil.cc_ErrorTxt("[UserFinanceController]getOverview:" + ex.Message);
            }
            return(result);
        }
        public ResultNormal addCommission(VueSubmitUserCommission submitData)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                submitData.userId = this.getUserId();
                // _userFinanceServices.add(submitData);
            }
            catch (CCException cex)
            {
                result.ErrorMsg = cex.Message;
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt("[UserFinanceController]addCommission:" + ex.Message);
                result.ErrorMsg += "[添加佣金失败]";
            }
            return(result);
        }
        public ResultNormal chargeMoney(VueSubmitUserCharge submitData)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                submitData.userId = this.getUserId();
                _userFinanceServices.submitUerChargeTrans(submitData);
            }
            catch (CCException cex)
            {
                result.ErrorMsg = cex.Message;
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt("[UserFinanceController]chargeMoney:" + ex.Message);
                result.ErrorMsg += "[充值失败]";
            }
            return(result);
        }
Пример #16
0
        public BaseRepository(ISqlSugarClient sqlSugarClient)
        {
            _db = sqlSugarClient;

            //_db.Aop.OnLogExecuted = (sql, pars) => //SQL执行完事件
            //{
            //    NLogUtil.cc_InfoTxt($"OnLogExecuted Sql:{sql}");
            //};
            //_db.Aop.OnLogExecuting = (sql, pars) => //SQL执行前事件
            //{
            //    Console.WriteLine(sql);
            //    NLogUtil.cc_InfoTxt($"Sql:{sql}");
            //};
            _db.Aop.OnError = (exp) =>//执行SQL 错误事件
            {
                NLogUtil.cc_ErrorTxt($"Sql:{exp.Sql}");
                //  Console.WriteLine(exp.Sql);
                //exp.sql exp.parameters 可以拿到参数和错误Sql
            };
        }
Пример #17
0
 public void InitForNewUser_Sync(string userId, bool hasWelComeMsg = true)
 {
     try
     {
         EMsgInfoOverview msgInfoOverview = new EMsgInfoOverview()
         {
             userId = userId,
         };
         if (hasWelComeMsg)
         {
             msgInfoOverview.nSystem           = 1;
             msgInfoOverview.notificationTotal = 1;
         }
         base.AddNoIdentity_Sync(msgInfoOverview);
     }
     catch (Exception ex)
     {
         NLogUtil.cc_ErrorTxt("[MsgInfoOverviewRepository]-InitForNewUser_Sync:" + ex.Message);
     }
 }
Пример #18
0
        public ResultPager <RBookList> searchBook(SearchReq searchRequest)
        {
            ResultPager <RBookList> result = new ResultPager <RBookList>();

            if (string.IsNullOrEmpty(searchRequest.userId))
            {
                result.ErrorMsg = "未知用户无法搜索";
                return(result);
            }

            if (string.IsNullOrEmpty(searchRequest.keyword.Trim()))
            {
                result.Message = "没有查询内容";
            }
            else
            {
                RefAsync <int> totalNumber = new RefAsync <int>();
                result.PageData.datas      = _bookRepository.searchByNameAndAuthor(searchRequest, totalNumber).Result;
                result.PageData.totalCount = totalNumber;
                try
                {
                    if (searchRequest.keyword.Length > 100)
                    {
                        searchRequest.keyword = searchRequest.keyword.Substring(0, 100);
                    }
                    logSearchKey(new ESearchKeyLog
                    {
                        UserId    = searchRequest.userId,
                        searchKey = searchRequest.keyword
                    });
                }
                catch (Exception logEx)
                {
                    NLogUtil.cc_ErrorTxt("searchBook: 添加搜索记录出错:" + logEx.Message);
                }
            }
            return(result);
        }
Пример #19
0
        public ResultNormal SwitchFavBook(reqUserBook userBook)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                userBook.userId = this.getUserId();
                if (userBook.direction == OperationDirection.plus)
                {
                    _userServices.AddFavBook(userBook.bookCode, userBook.userId);
                }
                else
                {
                    _userServices.DelFavBook(userBook.bookCode, userBook.userId);
                }
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt("[UserController]-AddFavBook:" + ex.Message);
                result.ErrorMsg = "操作失败,请之后再尝试";
            }
            return(result);
        }
Пример #20
0
        public ResultEntity <ResponseToken> GetUserPwdToken(requireUserPwdToken upToken)
        {
            ResultEntity <ResponseToken> result = new ResultEntity <ResponseToken>();
            string url = _configuration["Id4Config:Id4Url"] + "connect/token";

            upToken.grant_type    = _configuration["Id4Config:grant_type"];
            upToken.client_id     = _configuration["Id4Config:client_id"];
            upToken.client_secret = _configuration["Id4Config:client_secret"];

            // string json = JsonConvert.SerializeObject(upToken);
            try
            {
                var data = $"grant_type={upToken.grant_type}&client_id={upToken.client_id}&client_secret={upToken.client_secret}&username={upToken.username}&password={upToken.password}";
                var res  = HttpUtil.Send(url, HttpUtil.HttpMethod.Post, data, HttpUtil.application_form);
                result.Entity = JsonConvert.DeserializeObject <ResponseToken>(res);
            }
            catch (Exception ex)
            {
                NLogUtil.cc_ErrorTxt($"【UserController】GetUserPwdToken:{ex.Message}");
                result.ErrorMsg = CCWebMsg.Token_GetUserPwdToken;
            }

            return(result);
        }
Пример #21
0
        public ResultEntity <EResourceInfo> Upload([FromForm] IFormFile file)//,
        {
            ResultEntity <EResourceInfo> result = new ResultEntity <EResourceInfo>();
            EResourceInfo origRes  = null;
            string        filePath = _webHostEnvironment.ContentRootPath + _configuration["BookSiteConfig:uploadTemp"] + file.FileName;

            try
            {
                if (file != null)
                {
                    var uploadRes = this.RequestToUploadRes();

                    var verifyMsg = VerifyUpload(uploadRes);

                    if (verifyMsg != null)
                    {
                        result.ErrorMsg = verifyMsg;
                        return(result);
                    }

                    //写入到磁盘
                    using (FileStream fs = System.IO.File.Create(filePath)){
                        file.CopyTo(fs); //将上传的文件文件流,复制到fs中
                        fs.Flush();      //清空文件流
                    }
                    //上传到Oss
                    var ossKey = OssKeyManager.BookKey(filePath, uploadRes.refCode, getUserId());
                    //如果是重新提交,则需要删除Oss资源
                    if (uploadRes.isReset)
                    {
                        origRes = _resourceServices.get(uploadRes.resCode);
                        if (origRes.OssPath != ossKey)
                        {
                            _resourceServices.ossDelete(origRes.OssPath);
                        }
                    }
                    var uploadResult = _resourceServices.uploadToOss(filePath, ossKey);
                    if (uploadResult.IsSuccess)
                    {
                        var resourceInfo = GenerateResource(uploadRes, ossKey);
                        resourceInfo.OrigFileName = file.FileName;
                        //上传信息写入到数据库
                        result = _resourceServices.saveResToDb(resourceInfo);
                    }
                    else
                    {
                        result.ErrorMsg = "上传失败";
                    }
                }
            }
            catch (Exception ex)
            {
                result.ErrorMsg = "上传失败";
                NLogUtil.cc_ErrorTxt("BookController-Upload:" + ex.Message);
            }
            finally
            {
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }
            }
            return(result);
        }
Пример #22
0
        public ResultEntity <VueUserLogin> Register(RegUser regUser)
        {
            ResultEntity <VueUserLogin> result = new ResultEntity <VueUserLogin>();

            try
            {
                string verifyMsg = VerifyUser(regUser);
                if (verifyMsg == "")
                {
                    //先校验验证码(短信接口在ID4服务上)
                    var smsJson = RequireVerifySMSCode(new SMSRequire
                    {
                        mobilePhone = regUser.Phone,
                        VerifyCode  = regUser.VerifyCode
                    });
                    ResultEntity <OutSMS> smsResult = JsonConvert.DeserializeObject <ResultEntity <OutSMS> >(smsJson);
                    if (smsResult.IsSuccess)
                    {
                        if (smsResult.Entity.SMSVerifyStatus == SMSVerifyStatus.Success)
                        {
                            //注册用户写入数据库
                            var ui = _userServices.Register(regUser);
                            result.Entity = ui;

                            //获取Token
                            var tokenResult = this.GetUserPwdToken(new requireUserPwdToken
                            {
                                username = regUser.Account,
                                password = regUser.Pwd
                            });
                            if (tokenResult.IsSuccess)
                            {
                                result.Entity.UerInfo.Token = tokenResult.Entity;
                            }
                            else
                            {
                                result.ErrorMsg = "没有获取登陆令牌";
                            }
                        }
                        else
                        {
                            result.ErrorMsg = smsResult.Entity.Msg;
                        }
                    }
                    else
                    {
                        result.ErrorMsg = CCWebMsg.SMS_Verify_Failure;
                    }
                }
                else
                {
                    result.ErrorMsg = verifyMsg;
                }
            }
            catch (CCException cex)
            {
                result.ErrorMsg = cex.Message;
            }
            catch (Exception ex)
            {
                result.ErrorMsg = CCWebMsg.User_Reg_Failure;
                NLogUtil.cc_ErrorTxt($"User Controller Register Error:{ex.Message}");
            }
            return(result);
        }