Пример #1
0
        //private static bool _runState = false;
        //public void StartListenServer()
        //{
        //    if (_timer != null) return;
        //    _timer = new Timer();
        //    _timer.Interval = 3000;
        //    _timer.Elapsed += (sender, e) =>
        //    {
        //        DateTime dtDateTime = DateTime.Now;
        //        _timer.Interval = 3000;
        //        if (dtDateTime.Hour == 3 && dtDateTime.Minute == 0 && dtDateTime.Second > 1 &&
        //            dtDateTime.Second < 5)
        //        {
        //            lock (_objLock)
        //            {
        //                if (_runState)
        //                {
        //                    return;
        //                }
        //                _runState = true;
        //                _timer.Interval = (DateTime.Now.AddDays(1) - DateTime.Now).TotalMilliseconds - 30 * 60 * 1000;
        //            }
        //            LogHelper.info("矿机开始运行:" + dtDateTime.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
        //            try
        //            {
        //                RunCloudMinerServer();
        //            }
        //            catch (Exception exception)
        //            {
        //                LogHelper.error("矿机运行时出现未知错误:" + exception.Message);
        //            }
        //            _runState = false;
        //            LogHelper.info("矿机结束运行:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
        //        }
        //    };
        //    _timer.Enabled = true;
        //    _timer.AutoReset = true;
        //    _timer.Start();
        //    LogHelper.info("开启矿机服务:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        //}

        public async void StartListenServer()
        {
            LogHelper.info("矿机开始运行:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
            try
            {
                State = "1";
                await Task.Factory.StartNew(RunCloudMinerServer);
            }
            catch (Exception e)
            {
#if DEBUG
#else
                PhoneMessagesHelper.SendDdMessages("18696129948,13686847531", DateTime.Now.ToString("yyyy-MM-dd HH:mm") + " 矿机运行出错,请检查数据!");
#endif
                LogHelper.error(e.Message);
                State = e.Message;
            }
#if DEBUG
            PhoneMessagesHelper.SendDdMessages("18696129948,13686847531", string.Format("日期{0:yyyy-MM-dd HH:mm} 产量[现货通证:{1} 易货通证:{2} 理财通证{3}] 分润[现货通证:{4} 易货通证:{5} 理财通证{6}]",
                                                                                        DateTime.Now, _productionAmount * 0.5M, _productionAmount * 0.3M, _productionAmount * 0.2M, _distributionAmount * 0.5M, _distributionAmount * 0.3M, _distributionAmount * 0.2M));
#else
            PhoneMessagesHelper.SendDdMessages("18696129948,13686847531", string.Format("日期{0:yyyy-MM-dd HH:mm} 产量[现货通证:{1} 易货通证:{2} 理财通证{3}] 分润[现货通证:{4} 易货通证:{5} 理财通证{6}]",
                                                                                        DateTime.Now, _productionAmount * 0.5M, _productionAmount * 0.3M, _productionAmount * 0.2M, _distributionAmount * 0.5M, _distributionAmount * 0.3M, _distributionAmount * 0.2M));
#endif
            _productionAmount   = 0M;
            _distributionAmount = 0M;
            LogHelper.info("矿机结束运行:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        }
        public IHttpActionResult SendPhoneVerification(PhoneVerificationModelGet phoneVerificationModelGet)
        {
            try
            {
                if (phoneVerificationModelGet.PhoneAreaId != "86")
                {
                    return Json(new ResultDataModel<PhoneVerificationModelGet>() { Code = 0, Messages = "检测您当前地点为中国大陆境内,非中国大陆手机号接收验证可能会存在延迟" });
                }
                switch (phoneVerificationModelGet.Type)
                {
                    case "1":
                    case "3":
                        bool exisit = _userInfoDal.ExisitPhone(phoneVerificationModelGet.PhoneAreaId,
                            phoneVerificationModelGet.Phone);
                        if (exisit)
                        {
                            return Json(new ResultDataModel<PhoneVerificationModelGet> { Code = 4101, Messages = "手机号已绑定账号" });
                        }
                        break;
                    case "5":
                        exisit = _userInfoDal.ExisitPhone(phoneVerificationModelGet.PhoneAreaId,
                            phoneVerificationModelGet.Phone);
                        if (!exisit)
                        {
                            return Json(new ResultDataModel<PhoneVerificationModelGet> { Code = 4105, Messages = "手机号未绑定账号" });
                        }
                        break;
                }
                int verificationNo = 666666;
#if DEBUG

#else
                Random random = new Random();
                verificationNo= random.Next(100000, 999999);
                string msg = string.Format("【QQH】您的验证码为{0},有效期10分钟,如非本人操作,请勿回复此短信", verificationNo);
                  if (!PhoneMessagesHelper.SendDdMessages(phoneVerificationModelGet.Phone, msg))
                {
                    LogHelper.error("调用短信发送API失败");
                    throw new Exception();
                }
#endif
                PhoneVerificationCacheHelper.SetCache(phoneVerificationModelGet.PhoneAreaId, phoneVerificationModelGet.Phone, OutTime, phoneVerificationModelGet.Type, verificationNo.ToString());
                return Json(new ResultDataModel<PhoneVerificationModelGet>());
            }
            catch (Exception exception)
            {
                LogHelper.error("短信发送失败" + exception);
                return Json(new ResultDataModel<PhoneVerificationModelGet> { Code = -1, Messages = "短信发送失败" });
            }
        }