示例#1
0
        public async Task SendSmsVerifyMobile(string userId, string mobile)
        {
            var profile = _dbSet.AsNoTracking().SingleOrDefault(x => x.Id == userId);

            if (profile != null)
            {
                Guid   id   = Guid.NewGuid();
                string code = new Random().Next(1001, 9999).ToString();

                var r = new Services.SmsService().Send(mobile, $"Ma xac nhan tai khoan cua ban tren Punnel: {code}");
                if (r == true)
                {
                    uow.Token.DeleteByUser(userId);
                    uow.Token.AddToken(new Token()
                    {
                        Id          = id,
                        Code        = code,
                        UserId      = userId,
                        CreatedDate = DateTime.Now,
                        ExpiredDate = DateTime.Now.AddMinutes(10)
                    });
                }
                else
                {
                    throw new BusinessException("Không thể gửi SMS đển số của bạn, bạn vui lòng xác nhận tài khoản qua email");
                }
            }
        }
        public void sendSMS(Guid?userId)
        {
            using (MashadCarpetEntities db = new MashadCarpetEntities())
            {
                Users user = db.Users.Find(userId);

                if (user != null)
                {
                    Services.SmsService sms  = new Services.SmsService();
                    List <string>       list = new List <string>();
                    string mobile            = user.Mobile;
                    if (!string.IsNullOrEmpty(mobile))
                    {
                        list.Add(mobile);
                        sms.Send(list,
                                 "مشتری گرامی سفارش شما با موفقیت ثبت گردید. کارشناسان ما با شما تماس خواهند گرفت.", "");
                    }

                    list.Clear();
                    string number = WebConfigurationManager.AppSettings["CompanyNumber"];
                    list.Add(number);
                    sms.Send(list, "سفارش جدیدی در وب سایت ثبت گردید.", "");
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Services.SmsService sms  = new Services.SmsService();
            List <string>       list = new List <string>();

            list.Add("09124806404");
            sms.Send(list, "messageBody", "");
        }
        public async Task <ApiResponse> Refresh(Guid id, string userId)
        {
            ApiResponse res  = new ApiResponse();
            var         site = _dbSet.FirstOrDefault(x => x.Id == id && x.UserId == userId);

            if (site != null)
            {
                switch (site.SiteId)
                {
                case (int)IntegrationType.GetResponse:
                    res = new GetResponseTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.MailChimp:
                    res = new MailChimpTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.Autopilot:
                    res = new AutopilotTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.ActiveCampain:
                    res = new IntegrationServices.ActiveCampain.ActiveCampainTask(site.AccId, site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.InfusionSoft:
                    res = new IntegrationServices.InfusionSoft.InfusionSoftTask(site.ApiKey, site.Password).GetCampaigns();
                    if (res.Code == System.Net.HttpStatusCode.Unauthorized)
                    {
                        var newToken = new IntegrationServices.InfusionSoft.InfusionSoftTask(site.ApiKey, site.Password).Refresh();
                        if (newToken != null && !string.IsNullOrEmpty(newToken.access_token))
                        {
                            site.ApiKey = newToken.access_token;
                            this.Commit();
                            res.Code = System.Net.HttpStatusCode.OK;
                        }
                    }
                    break;

                case (int)IntegrationType.Gmail:
                    res = new EmailServices.GmailPersonalSvc(site.ApiKey, site.TokenJson).Auth();
                    break;

                case (int)IntegrationType.GoogleSheet:
                    res = new EmailServices.GoogleSheetSvc(site.ApiKey, site.TokenJson).Auth();
                    break;

                case (int)IntegrationType.Wordpress:
                    res = new Utils.WordpressUtils(site.AccId, site.ApiKey).Auth();
                    if (res.Code == System.Net.HttpStatusCode.NotFound)
                    {
                        throw new BusinessException("Không kiểm tra được kết nối WP. Cấu hình này được dùng để xuất bản từ phía WP");
                    }
                    break;

                case (int)IntegrationType.Shopify:
                    res = await new ShopifyService.ShopifyService(site.AccId, site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Haravan:
                    res = await new HaravanService.HaravanService(site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Sapo:
                    res = await new SapoService.SapoService(site.AccId, site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Sms:
                    string sim     = string.IsNullOrEmpty(site.AccId) == false ? "sim1" : "sim2";
                    var    profile = uow.UserProfile.Get(userId);
                    var    mobile  = profile == null ? "0968152579" : profile.Mobile;
                    var    r       = new Services.SmsService().Send(site.Phone, site.Password, sim, mobile, $"Chao {profile.FullName}. Punnel sms dang dung tot nhe");
                    if (r == true)
                    {
                        res.Code = System.Net.HttpStatusCode.OK;
                    }
                    else
                    {
                        res.Code    = System.Net.HttpStatusCode.BadRequest;
                        res.Message = "Thiết thị không thể gửi tin nhắn sms. Vui lòng kiểm tra lại thiết bị & ứng dụng SMS đã cài đặt";
                    }
                    break;
                }
                if (res.Code != System.Net.HttpStatusCode.OK)
                {
                    site.IsExpired = true;
                    this.Commit();
                }
                else
                {
                    site.IsExpired = false;
                    this.Commit();
                }
            }
            return(res);
        }