Exemplo n.º 1
0
        public int AddAppClientId(AddAppClientIdModel query)
        {
            //判断是否存在该设备信息
            CustomerAppClientIdEntity entity = _customerAppClientIdDal.Query <CustomerAppClientIdEntity>(
                n => n.Cid == query.Cid, true).FirstOrDefault();

            if (entity != null)
            {
                if (entity.ClientId != query.ClientId)
                {
                    //更新
                    entity.ClientId   = query.ClientId;
                    entity.ClientType = query.ClientType;
                    entity.CreateTime = DateTime.Now;
                    _customerAppClientIdDal.Update(entity, new string[] { "ClientId", "ClientType", "CreateTime" });
                }
            }
            else
            {
                CustomerAppClientIdEntity customerAppClientIdEntity =
                    Mapper.Map <AddAppClientIdModel, CustomerAppClientIdEntity>(query);
                //新增
                customerAppClientIdEntity = _customerAppClientIdDal.Insert(customerAppClientIdEntity);
            }

            return(0);
        }
Exemplo n.º 2
0
        public bool MobileBindClientID(string verifyCode, string clientID, int cid, string clientType)
        {
            var customerInfo = _customerDal.Find <CustomerInfoEntity>(cid);
            var mobile       = customerInfo.Mobile;

            #region 检测验证码是否正确
            var r = RedisManager.GetData(CacheKeyEnum.CustomerMobileVerifyCode + mobile);
            if (r != null && r.Length > 0 && verifyCode == r)
            {
            }
            else
            {
                throw new MojoryException(MojoryApiResponseCode.VerifyCodeError);
            }
            #endregion

            var clientIdInfo = _customerDal.Query <CustomerAppClientIdEntity>(a => a.Cid == cid);
            if (clientIdInfo.Any())
            {
                var item = clientIdInfo.First();
                item.ClientId   = clientID;
                item.ClientType = clientType;

                #region 更新设备信息
                _customerDal.Update <CustomerAppClientIdEntity>(item);
                return(true);

                #endregion
            }
            else
            {
                var item = new CustomerAppClientIdEntity();
                item.Cid        = cid;
                item.ClientId   = clientID;
                item.ClientType = clientType;
                item.CreateTime = DateTime.Now;
                #region 更新设备信息
                _customerDal.Insert <CustomerAppClientIdEntity>(item);
                return(true);

                #endregion
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 发送待推送信息
        /// </summary>
        /// <param name="sendAppMessageModels"></param>
        /// <param name="sendAppMessageType"></param>
        public void SendAppMessage(List <SendAppMessageModel> sendAppMessageModels, SendAppMessageTypeEnum sendAppMessageType)
        {
            if (sendAppMessageModels == null || sendAppMessageModels.Count == 0)
            {
                return;
            }
            List <int> cidList = sendAppMessageModels.Select(n => n.Cid).ToList();
            List <CustomerAppClientIdEntity> customerAppClientIdEntities =
                _customerAppClientIdDal.Query <CustomerAppClientIdEntity>(n => cidList.Contains(n.Cid), true).ToList();

            foreach (SendAppMessageModel waitSend in sendAppMessageModels)
            {
                SendAppMessageEntity entity = new SendAppMessageEntity();
                entity.SendId    = waitSend.SendId;
                entity.SendCount = waitSend.SendCount + 1;
                if (!waitSend.SendFirstTime.HasValue)
                {
                    entity.SendFirstTime = DateTime.Now;
                }
                else
                {
                    entity.SendFirstTime = waitSend.SendFirstTime;
                }
                entity.SendLastTime = DateTime.Now;
                CustomerAppClientIdEntity customerAppClientIdEntity = customerAppClientIdEntities.Find(n => n.Cid == waitSend.Cid);
                entity.ClientId = customerAppClientIdEntity?.ClientId;
                if (waitSend.SendCount <= 10 && !string.IsNullOrEmpty(waitSend.SendContent))//发送记录少于10次
                {
                    if (!string.IsNullOrEmpty(entity.ClientId))
                    {
                        #region 推送app消息

                        string message = waitSend.SendContent;
                        if (sendAppMessageType != SendAppMessageTypeEnum.AuditUrgeNotice)
                        {
                            message = string.Format("message={0}&cid={1}&sendType={2}&id={3}&orderType={4}",
                                                    waitSend.SendContent,
                                                    waitSend.Cid, (int)waitSend.SendType, waitSend.OrderId, (int)waitSend.OrderType);
                        }

                        SendAppContentModel content = new SendAppContentModel();
                        content.ClientId   = entity.ClientId;
                        content.ClientType = customerAppClientIdEntity?.ClientType;
                        content.Content    = message;
                        content.Title      = waitSend.SendType.ToDescription();
                        content.Text       = waitSend.SendContent;
                        if (sendAppMessageType == SendAppMessageTypeEnum.AuditUrgeNotice &&
                            !string.IsNullOrEmpty(message) && message.Contains("&"))
                        {
                            content.Text = message.Split('&')[0].Replace("message=", "");
                        }
                        SendAppMessageResultModel resultModel = new SendAppMessageResultModel();
                        try
                        {
                            resultModel        = _sendAppMessageBll.SendAppMessage(content);
                            entity.SendContent = content.Content;
                            entity.SendResult  = resultModel.ResultInfo;
                            if (resultModel.Result.ToLower() == "ok")
                            {
                                entity.SendStatus = 1;
                            }
                            else
                            {
                                entity.SendStatus = -1;
                            }
                        }
                        catch (Exception ex)
                        {
                            entity.SendResult = ex.Message;
                            entity.SendStatus = -2;
                        }

                        #endregion
                    }
                    else
                    {
                        entity.SendStatus = -3;
                        entity.SendResult = "没有找到对应的设备Id";
                    }
                }
                else
                {
                    entity.SendStatus = -4;
                    entity.SendResult = "已经超过10次,不再发送";
                }

                _sendAppMessageDal.Update(entity, new string[] { "SendCount", "SendFirstTime", "SendLastTime", "ClientId", "SendContent", "SendResult", "SendStatus" });
            }
        }
Exemplo n.º 4
0
        public TokenResultModel CheckToken(HttpRequestMessage request)
        {
            TokenResultModel resultModel = new TokenResultModel();
            string           token       = "";

            try
            {
                token = request.Headers.GetValues("MojoryToken").First();
            }
            catch
            {
                //如果头部没有token 从参数中获取token
                if (string.IsNullOrEmpty(token))
                {
                    string url   = request.RequestUri.ToString();
                    Regex  regex = new Regex("token=(?<token>.+?)&");
                    token = regex.Match(url).Groups["token"].Value;
                }
            }


            /*
             * 如果传入的token是给定的token数据,则直接返回
             */
            if (token == AppSettingsHelper.GetAppSettings(AppSettingsEnum.OAToken))
            {
                resultModel.Code  = TokenResultEnum.Allow;
                resultModel.Token = token;

                IEnumerable <string> cidValuesList;
                if (request.Headers.TryGetValues("Cid", out cidValuesList))
                {
                    resultModel.Cid = Convert.ToInt32(cidValuesList.FirstOrDefault());
                }
                IEnumerable <string> oidValuesList;
                if (request.Headers.TryGetValues("Oid", out oidValuesList))
                {
                    resultModel.Oid = oidValuesList.FirstOrDefault();
                }
                else
                {
                    throw new Exception("请传入操作员id");
                }
                return(resultModel);
            }


            IEnumerable <string> valuesList;
            string fromSource = "O";

            if (request.Headers.TryGetValues("OrderSource", out valuesList))
            {
                fromSource = valuesList.FirstOrDefault();
            }

            TokenModel tokenModel = new TokenModel();

            //1.判断是否存在Token
            if (string.IsNullOrEmpty(token))//1.1 不存在,则生成Token,返回登录首页
            {
                tokenModel.Value = new TokenValueModel {
                    Status = TokenResultEnum.Initial, FromSource = fromSource
                };
                resultModel.Code  = TokenResultEnum.Initial;
                resultModel.Token = _tokenBll.SetToken(tokenModel);
                return(resultModel);
            }
            //2.根据传入的Token获取Redis中对应的信息
            tokenModel = _tokenBll.GetToken(token);
            if (tokenModel == null)//2.1 如果不存在Redis中,则生成初始Token
            {
                tokenModel = new TokenModel {
                    Value = new TokenValueModel {
                        Status = TokenResultEnum.Initial, FromSource = fromSource
                    }
                };
                resultModel.Code  = TokenResultEnum.Initial;
                resultModel.Token = _tokenBll.SetToken(tokenModel);
                return(resultModel);
            }

            if (tokenModel.Value.Status == TokenResultEnum.Initial)//2.2.2 Token为初始状态
            {
                resultModel.Code  = TokenResultEnum.Initial;
                resultModel.Token = token;
                return(resultModel);
            }
            if (tokenModel.Value.Status == TokenResultEnum.NoAllow)//2.2.2 Token为禁止访问Api
            {
                resultModel.Code  = TokenResultEnum.NoAllow;
                resultModel.Token = token;
                return(resultModel);
            }
            //2.2.3 判断当前传入的设备号是和保存的设备Id一致
            //TODO:如果新增个性化后,这个功能就需要根据个性化修改了
            string appClientId = string.Empty;

            if (request.Headers.TryGetValues("AppClientId", out valuesList))
            {
                appClientId = valuesList.FirstOrDefault();
            }
            if (!string.IsNullOrEmpty(appClientId) && tokenModel.Value.Cid.HasValue)
            {
                CustomerAppClientIdEntity customerAppClientIdEntity =
                    base.Context.Set <CustomerAppClientIdEntity>()
                    .FirstOrDefault(
                        n => n.Cid == tokenModel.Value.Cid.Value && n.ClientId.ToUpper() == appClientId.ToUpper());
                if (customerAppClientIdEntity == null)
                {
                    _tokenBll.DeleteToken(token);
                    resultModel.Code  = TokenResultEnum.MobileChanged;
                    resultModel.Token = token;
                    return(resultModel);
                }
            }

            //2.2.4 允许访问Api
            resultModel.Code  = TokenResultEnum.Allow;
            resultModel.Token = token;
            resultModel.Cid   = tokenModel.Value.Cid;

            //2.2.5 更新Token有效时间
            _tokenBll.ExpireToken(token, 24);
            return(resultModel);
        }