Esempio n. 1
0
        /// <summary>
        /// 检测口令是否为汉字
        /// </summary>
        /// <param name="textCmd"></param>
        private void CheckText(string text)
        {
            string textCmd = (string)text.Clone();

            textCmd = textCmd.Replace(",", "");
            textCmd = textCmd.Replace(",", "");
            textCmd = textCmd.Replace("?", "");
            textCmd = textCmd.Replace("?", "");
            textCmd = textCmd.Replace(".", "");
            textCmd = textCmd.Replace("。", "");
            textCmd = textCmd.Replace(":", "");
            textCmd = textCmd.Replace(":", "");
            textCmd = textCmd.Replace("!", "");
            textCmd = textCmd.Replace("!", "");
            textCmd = textCmd.Trim();
            for (int i = 0; i < textCmd.Length; i++)
            {
                if (!Regex.IsMatch(textCmd[i].ToString(), @"[\u4e00-\u9fbb]+$"))
                {
                    var e = new ExceptionModel()
                    {
                        MethodFullName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
                        ExceptionDate  = DateTime.Now,
                        ExceptionParam = ActionParams.packets_text_no_chinese
                    };
                    e.Save();
                    throw e;
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 检测人数
 /// </summary>
 /// <param name="packetsModel"></param>
 /// <returns></returns>
 private bool CheckPeopleNum(VoicePacketsModel packetsModel)
 {
     if (packetsModel.PeopleNum == 0)
     {
         var e = new ExceptionModel()
         {
             MethodFullName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
             ExceptionDate  = DateTime.Now,
             ExceptionParam = ActionParams.packets_people_none
         };
         e.Save();
         throw e;
     }
     if (packetsModel.Amount.ConvertToMoneyCent() / packetsModel.PeopleNum < 1)
     {
         var e = new ExceptionModel()
         {
             MethodFullName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
             ExceptionDate  = DateTime.Now,
             ExceptionParam = ActionParams.packets_people_too_many
         };
         e.Save();
         throw e;
     }
     return(true);
 }
Esempio n. 3
0
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="uniacid">商户ID</param>
        /// <param name="phoneNumber">手机号码</param>
        /// <returns></returns>
        public IActionResult GetSmsVerifyCode(string uniacid, string phoneNumber)
        {
            var filter = Builders <VerifyCodeModel> .Filter;
            var mongo  = new MongoDBTool();

            var company = mongo.GetMongoCollection <CompanyModel>().Find(x => x.uniacid.Equals(uniacid)).FirstOrDefault();

            if (company == null || company.YTX == null)
            {
                var em = new ExceptionModel()
                {
                    Content = "商户未设置云通信信息"
                };
                em.Save();
                return(this.JsonErrorStatus());
            }

            var collection = mongo.GetMongoCollection <VerifyCodeModel>();
            var date       = DateTime.Now.AddMinutes(VerifyTimeOut);

            collection.DeleteMany(filter.Lt(x => x.CreateTime, date) & filter.Eq(x => x.uniacid, uniacid));
            var             filterSum = filter.Eq(x => x.PhoneNumber, phoneNumber) & filter.Gt(x => x.CreateTime, date);
            VerifyCodeModel vcm       = collection.FindOneAndDelete(filterSum);

            if (vcm == null)
            {
                vcm = new VerifyCodeModel()
                {
                    PhoneNumber = phoneNumber,
                    CreateTime  = DateTime.Now,
                    uniacid     = uniacid
                };
            }
            string jsonData = JsonConvert.SerializeObject(new SMSModel()
            {
                appid  = company.YTX.AppID,
                mobile = vcm.PhoneNumber,
                datas  = new string[] { vcm.VerifyCode, VerifyTimeOut + "" }
            });
            string url = "/sms/TemplateSMS.wx";

            string result = new PhoneHelper(company.YTX).SendRequest(url, jsonData);
            var    jObj   = (JObject)JsonConvert.DeserializeObject(result);
            JToken statuscode;
            bool   hasVal = jObj.TryGetValue("statusCode", out statuscode);

            if (hasVal && statuscode.ToString().Equals("0"))
            {
                collection.InsertOne(vcm);
                return(this.JsonErrorStatus());
            }
            return(this.JsonErrorStatus());
        }
Esempio n. 4
0
 internal void SetPhoneNumber(string uniacid, ObjectId accountID, string phoneNumber)
 {
     if (string.IsNullOrEmpty(phoneNumber))
     {
         var em = new ExceptionModel()
         {
             ExceptionParam = Tools.Response.ResponseStatus.请求参数不正确
         };
         em.Save();
         throw em;
     }
     collection.UpdateOne(x => x.uniacid.Equals(uniacid) && x.AccountID.Equals(accountID), Builders <AccountModel> .Update.Set(x => x.AccountPhoneNumber, phoneNumber));
 }
        /// <summary>
        /// 微信支付成功返回数据
        /// </summary>
        /// <param name="data"></param>
        private void OnPaySuccess(WxPayData data)
        {
            var attach    = (string)data.GetValue("attach");
            var wxOrderId = (string)data.GetValue("transaction_id");

            if (string.IsNullOrEmpty(attach))
            {
                var em = new ExceptionModel()
                {
                    Content = "微信支付返回:attach为空"
                };
                em.Save();
                throw em;
            }
            if (string.IsNullOrEmpty(wxOrderId))
            {
                var em = new ExceptionModel()
                {
                    Content = "微信支付返回:微信订单号为空"
                };
                em.Save();
                throw em;
            }
            string[] aa                = attach.Split(',');
            string   uniacid           = aa[0];
            string   accountID         = aa[1];
            string   orderID           = aa[2];
            var      mongo             = new MongoDBTool();
            var      accountCollection = mongo.GetMongoCollection <AccountModel>();

            var filter    = Builders <AccountModel> .Filter;
            var filterSum = filter.Eq(x => x.AccountID, new ObjectId(accountID)) & filter.Eq("Orders.OrderID", new ObjectId(orderID));
            var account   = accountCollection.Find(filterSum).FirstOrDefault();
            var wcOrder   = account.Orders.Find(x => x.OrderID.Equals(new ObjectId(orderID)) && !x.IsPaid);

            if (wcOrder == null)
            {
                var em = new ExceptionModel()
                {
                    Content = "微信支付返回:订单不存在或者已经生成"
                };
                em.Save();
                throw em;
            }
            var update = Builders <AccountModel> .Update
                         .Set("Orders.$.WeChatOrderID", wxOrderId)
                         .Set("Orders.$.IsPaid", true);

            accountCollection.UpdateOne(filterSum, update);
        }
Esempio n. 6
0
        /// <summary>
        /// 创建语音口令红包
        /// </summary>
        /// <param name="uniacid"></param>
        /// <param name="accountID"></param>
        /// <param name="packetsModel"></param>
        /// <returns></returns>
        internal async Task <string> CreateVoicePackets(string uniacid, ObjectId accountID, VoicePacketsModel packetsModel)
        {
            CheckPeopleNum(packetsModel);
            CheckText(packetsModel.TextCmd);

            packetsModel.uniacid    = uniacid;
            packetsModel.CreateTime = DateTime.Now;
            return(await Task.Run(() =>
            {
                var account = GetModelByIDAndUniacID(accountID, uniacid);
                if (account == null)
                {
                    var e = new ExceptionModel()
                    {
                        MethodFullName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
                        Content = $"用户为空:accountID={accountID.ToString()},uniacid={uniacid}",
                        ExceptionDate = DateTime.Now
                    };
                    e.Save();
                    throw e;
                }

                var serviceMoney = GetServiceMoney(uniacid, packetsModel.Amount);
                var balance = account.Balances - (packetsModel.Amount + serviceMoney);

                packetsModel.PacketsID = ObjectId.GenerateNewId();
                packetsModel.CreatePeople = new Participant
                {
                    AccountID = account.AccountID,
                    AccountAvatar = account.AccountAvatar,
                    AccountName = account.AccountName,
                    CreateTime = DateTime.Now
                };
                if (balance < 0)
                {
                    WeChatOrder weChatOrder;
                    WXPayModel wXPayModel = GetCreatePacketsPayParams(-balance, packetsModel, uniacid, account, out weChatOrder);
                    return new BaseResponseModel3 <bool, string, WXPayModel>()
                    {
                        StatusCode = ActionParams.code_ok, JsonData = false, JsonData1 = packetsModel.PacketsID.ToString(), JsonData2 = wXPayModel
                    }.ToJson();
                }
                CreateVoicePackets(account, packetsModel, serviceMoney, balance);
                return new BaseResponseModel2 <bool, string>()
                {
                    StatusCode = ActionParams.code_ok, JsonData = true, JsonData1 = packetsModel.PacketsID.ToString()
                }.ToJson();
            }));
        }
Esempio n. 7
0
        /// <summary>
        /// 获取红包列表
        /// </summary>
        /// <param name="uniacid"></param>
        /// <param name="accountID"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        internal List <VoicePacketsModel> GetPacketsList(string uniacid, ObjectId accountID, PacketsDoType type)
        {
            var account       = GetModelByIDAndUniacID(accountID, uniacid);
            var vpmCollection = mongo.GetMongoCollection <VoicePacketsModel>();

            switch (type)
            {
            case PacketsDoType.send:
                if (account.SendPackets == null)
                {
                    var em = new ExceptionModel()
                    {
                        ExceptionParam = ActionParams.code_null
                    };
                    em.Save();
                    throw em;
                }
                for (int i = 0; i < account.SendPackets.Count; i++)
                {
                    account.SendPackets[i] = vpmCollection.Find(x => x.PacketsID.Equals(account.SendPackets[i].PacketsID)).FirstOrDefault();
                }
                return(account.SendPackets);

            case PacketsDoType.receive:
                if (account.ReceivePackets == null)
                {
                    var em = new ExceptionModel()
                    {
                        ExceptionParam = ActionParams.code_null
                    };
                    em.Save();
                    throw em;
                }
                for (int i = 0; i < account.ReceivePackets.Count; i++)
                {
                    account.ReceivePackets[i] = vpmCollection.Find(x => x.PacketsID.Equals(account.ReceivePackets[i].PacketsID)).FirstOrDefault();
                }
                return(account.ReceivePackets);

            default:
                var e = new ExceptionModel()
                {
                    Content = "获取红包列表type类型未知"
                };
                e.Save();
                throw e;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 提现完成
        /// </summary>
        /// <param name="uniacid"></param>
        /// <param name="accountID"></param>
        /// <param name="money"></param>
        internal void PullBalanceFinish(string uniacid, ObjectId accountID, decimal money)
        {
            var account  = GetModelByIDAndUniacID(accountID, uniacid);
            var balances = account.Balances - money;

            if (balances < 0)
            {
                var em = new ExceptionModel()
                {
                    ExceptionParam = ActionParams.code_insufficient_balance
                };
                em.Save();
                throw em;
            }
            collection.UpdateOne(x => x.AccountID.Equals(accountID), Builders <AccountModel> .Update.Set(x => x.Balances, balances));
        }
Esempio n. 9
0
        internal void SaveCarInfo(string uniacid, ObjectId accountID, string carNumber, string accountPhone)
        {
            if (string.IsNullOrEmpty(carNumber) || string.IsNullOrEmpty(accountPhone))
            {
                var em = new ExceptionModel()
                {
                    Content = "参数为空"
                };
                em.Save();
                throw em;
            }
            var filter    = Builders <AccountModel> .Filter;
            var filterSum = filter.Eq(x => x.uniacid, uniacid) & filter.Eq(x => x.AccountID, accountID);
            var update    = Builders <AccountModel> .Update.Set(x => x.CarNumber, carNumber).Set(x => x.AccountPhoneNumber, accountPhone);

            collection.UpdateOne(filterSum, update);
        }
Esempio n. 10
0
        /// <summary>
        /// 提现
        /// </summary>
        /// <param name="uniacid"></param>
        /// <param name="objectId"></param>
        /// <param name="money"></param>
        internal void PullBalance(string uniacid, ObjectId accountID, decimal money)
        {
            var account = GetModelByIDAndUniacID(accountID, uniacid);

            if (account.Balances - money < 0)
            {
                var em = new ExceptionModel()
                {
                    ExceptionParam = ActionParams.code_insufficient_balance
                };
                em.Save();
                throw em;
            }
            WeChatOrder weChatOrder;

            DoCompanyPay(money, uniacid, account, "提现", out weChatOrder);
        }
Esempio n. 11
0
        /// <summary>
        /// 获取手续费
        /// </summary>
        /// <param name="uniacid"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        internal decimal GetServiceMoney(string uniacid, decimal amount)
        {
            var company = mongo.GetMongoCollection <CompanyModel>().Find(x => x.uniacid.Equals(uniacid)).FirstOrDefault();

            if (company == null)
            {
                var e = new ExceptionModel()
                {
                    MethodFullName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
                    Content        = $"商户为空:uniacid={uniacid}",
                    ExceptionDate  = DateTime.Now
                };
                e.Save();
                throw e;
            }
            return(Math.Round(amount * company.ServiceRate, 2, MidpointRounding.AwayFromZero));
        }
Esempio n. 12
0
        internal void CallAccount(string uniacid, ObjectId currentAccountID, ObjectId anotherAccountID)
        {
            var currentAccount = GetModelByIDAndUniacID(currentAccountID, uniacid);
            var anotherAccount = GetModelByIDAndUniacID(anotherAccountID, uniacid);

            CheckCallNull(currentAccount, anotherAccount);
            var company = mongo.GetMongoCollection <CompanyModel>().Find(x => x.uniacid.Equals(uniacid)).FirstOrDefault();

            if (company == null || company.YTX == null)
            {
                var em = new ExceptionModel()
                {
                    Content        = "商户未设置云通信信息",
                    ExceptionParam = Tools.Response.ResponseStatus.请求失败
                };
                em.Save();
                throw em;
            }
            string jsonData = JsonConvert.SerializeObject(new TwoPhoneModel()
            {
                appid = company.YTX.AppID,
                src   = currentAccount.AccountPhoneNumber,
                dst   = anotherAccount.AccountPhoneNumber
            });
            string url = "/call/DailbackCall.wx";

            string result = new PhoneHelper(company.YTX).SendRequest(url, jsonData);
            var    jObj   = (JObject)JsonConvert.DeserializeObject(result);
            JToken statuscode;
            bool   hasVal = jObj.TryGetValue("statusCode", out statuscode);

            if (!hasVal || !statuscode.ToString().Equals("0"))
            {
                var em = new ExceptionModel()
                {
                    Content        = "呼叫不成功!",
                    ExceptionParam = Tools.Response.ResponseStatus.请求失败
                };
                em.Save();
                throw em;
            }
        }
Esempio n. 13
0
        internal void CheckVerify(string uniacid, string accountPhone, string verifyCode)
        {
            var filter       = Builders <VerifyCodeModel> .Filter;
            var vcCollection = mongo.GetMongoCollection <VerifyCodeModel>();
            var date         = DateTime.Now.AddMinutes(-ToolsController.VerifyTimeOut);

            vcCollection.DeleteMany(filter.Lt(x => x.CreateTime, date) & filter.Eq(x => x.uniacid, uniacid));
            var vc = vcCollection.FindOneAndDelete(filter.Eq(x => x.uniacid, uniacid) & filter.Eq(x => x.PhoneNumber, accountPhone) & filter.Eq(x => x.VerifyCode, verifyCode));

            if (vc == null)
            {
                var em = new ExceptionModel()
                {
                    Content        = "验证码错误",
                    ExceptionParam = Tools.Response.ResponseStatus.验证失败
                };
                em.Save();
                throw em;
            }
        }
Esempio n. 14
0
        public IActionResult CallMany()
        {
            var mongo = new MongoDBTool();

            var company = mongo.GetMongoCollection <CompanyModel>().Find(x => x.uniacid.Equals("24")).FirstOrDefault();

            if (company == null || company.YTX == null)
            {
                var em = new ExceptionModel()
                {
                    Content = "商户未设置云通信信息"
                };
                em.Save();
                return(this.JsonErrorStatus());
            }


            string jsonData = JsonConvert.SerializeObject(new MeetingPhoneModel()
            {
                appid       = company.YTX.AppID,
                creator     = "15501022450",
                meetingname = "ceshi",
                parties     = new Party[] { new Party()
                                            {
                                                name = "22", phone = "13245437784"
                                            } }
            }
                                                          );
            string url = "/call/TeleMeeting.wx";

            string result = new PhoneHelper(company.YTX).SendRequest(url, jsonData);
            var    jObj   = (JObject)JsonConvert.DeserializeObject(result);
            JToken statuscode;
            bool   hasVal = jObj.TryGetValue("statusCode", out statuscode);

            if (hasVal && statuscode.ToString().Equals("0"))
            {
                return(this.JsonSuccessStatus());
            }
            return(this.JsonErrorStatus());
        }
Esempio n. 15
0
        /// <summary>
        /// 对比口令
        /// </summary>
        /// <param name="word"></param>
        /// <param name="textCmd"></param>
        /// <returns></returns>
        private void CompareCmd(string word, string textCmd)
        {
            //new ExceptionModel() { Content = $@"{word}<compare>{textCmd}" }.Save();
            word = word.Replace(",", "");
            word = word.Replace(",", "");
            word = word.Replace("?", "");
            word = word.Replace("?", "");
            word = word.Replace(".", "");
            word = word.Replace("。", "");
            word = word.Replace(":", "");
            word = word.Replace(":", "");
            word = word.Replace("!", "");
            word = word.Replace("!", "");
            word = word.Trim();

            textCmd = textCmd.Replace(",", "");
            textCmd = textCmd.Replace(",", "");
            textCmd = textCmd.Replace("?", "");
            textCmd = textCmd.Replace("?", "");
            textCmd = textCmd.Replace(".", "");
            textCmd = textCmd.Replace("。", "");
            textCmd = textCmd.Replace(":", "");
            textCmd = textCmd.Replace(":", "");
            textCmd = textCmd.Replace("!", "");
            textCmd = textCmd.Replace("!", "");
            textCmd = textCmd.Trim();
            bool eq = textCmd.Equals(word);

            if (!eq)
            {
                var em = new ExceptionModel()
                {
                    Content = $@"{word}<compare:{eq}>{textCmd}", ExceptionParam = ActionParams.code_error_verify
                };
                em.Save();
                throw em;
            }
        }
Esempio n. 16
0
 private void CheckCallNull(AccountModel currentAccount, AccountModel anotherAccount)
 {
     if (string.IsNullOrEmpty(currentAccount.AccountPhoneNumber))
     {
         var em = new ExceptionModel()
         {
             Content        = "呼叫者电话为空",
             ExceptionParam = Tools.Response.ResponseStatus.呼叫者手机号为空
         };
         em.Save();
         throw em;
     }
     if (string.IsNullOrEmpty(anotherAccount.AccountPhoneNumber))
     {
         var em = new ExceptionModel()
         {
             Content        = "被呼叫者电话为空",
             ExceptionParam = Tools.Response.ResponseStatus.被呼叫者手机号为空
         };
         em.Save();
         throw em;
     }
 }
Esempio n. 17
0
        /// <summary>
        /// 微信支付成功返回数据
        /// </summary>
        /// <param name="data"></param>
        private void OnPaySuccess(WxPayData data)
        {
            var attach    = (string)data.GetValue("attach");
            var wxOrderId = (string)data.GetValue("transaction_id");

            if (string.IsNullOrEmpty(attach))
            {
                var em = new ExceptionModel {
                    Content = "微信支付返回:attach为空"
                };
                em.Save();
                throw em;
            }
            if (string.IsNullOrEmpty(wxOrderId))
            {
                var em = new ExceptionModel {
                    Content = "微信支付返回:微信订单号为空"
                };
                em.Save();
                throw em;
            }
            var aa        = attach.Split(',');
            var uniacid   = aa[0];
            var accountID = aa[1];
            var orderID   = aa[2];
            var orderType = (OrderType)Convert.ToInt32(aa[3]);

            switch (orderType)
            {
            case OrderType.LessonOrder:
                NotifyLessonOrder(uniacid, accountID, orderID, wxOrderId);
                break;

            default:
                break;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// 微信支付成功返回数据
        /// </summary>
        /// <param name="data"></param>
        private void OnPaySuccess(WxPayData data)
        {
            var attach    = (string)data.GetValue("attach");
            var wxOrderId = (string)data.GetValue("transaction_id");

            if (string.IsNullOrEmpty(attach))
            {
                var em = new ExceptionModel()
                {
                    Content = "微信支付返回:attach为空"
                };
                em.Save();
                throw em;
            }
            if (string.IsNullOrEmpty(wxOrderId))
            {
                var em = new ExceptionModel()
                {
                    Content = "微信支付返回:微信订单号为空"
                };
                em.Save();
                throw em;
            }
            string[] aa                = attach.Split(',');
            string   accountID         = aa[1];
            string   orderID           = aa[2];
            var      mongo             = new MongoDBTool();
            var      accountCollection = mongo.GetMongoCollection <AccountModel>();

            var filter    = Builders <AccountModel> .Filter;
            var filterSum = filter.Eq(x => x.AccountID, new ObjectId(accountID)) & filter.Eq("WeChatOrders.WeChatOrderID", new ObjectId(orderID));
            var account   = accountCollection.Find(filterSum).FirstOrDefault();
            var wcOrder   = account.WeChatOrders.Find(x => x.WeChatOrderID.Equals(new ObjectId(orderID)) && x.WXOrderId == null);

            if (wcOrder == null)
            {
                var em = new ExceptionModel()
                {
                    Content = "微信支付返回:订单不存在或者已经生成"
                };
                em.Save();
                throw em;
            }

            var update = Builders <AccountModel> .Update
                         .Set("WeChatOrders.$.WXOrderId", wxOrderId)
                         .Set(x => x.Balances, account.Balances + wcOrder.Total);

            if (wcOrder.VoicePackets != null)
            {
                var ad           = new AccountData();
                var serviceMoney = ad.GetServiceMoney(account.uniacid, wcOrder.VoicePackets.Amount);
                var balance      = account.Balances + wcOrder.Total;
                balance = balance - (wcOrder.VoicePackets.Amount + serviceMoney);
                if (balance >= 0)
                {
                    update = Builders <AccountModel> .Update.Set("WeChatOrders.$.WXOrderId", wxOrderId);

                    ad.CreateVoicePackets(account, wcOrder.VoicePackets, serviceMoney, balance);
                }
            }
            accountCollection.UpdateOne(filterSum, update);
        }