Esempio n. 1
0
 /// <summary>
 /// Send SMS
 /// </summary>
 /// <param name="contactInfo"></param>
 /// <returns></returns>
 public bool SendSms(SmsRequestModel contactInfo)
 {
     try
     {
         var smsBody = string.Format(
             "Emergency contact first name: {0}, {0} has activated a safety feature through our YayYo ride-sharing application. " +
             "{0} was picked up at: {1} from: {2}. {0} was to be dropped off at: {3}.",
             contactInfo.FirstName, contactInfo.RideScheduledTime, contactInfo.RiderPickupLocation, contactInfo.DestinationAddress);
         if (!string.IsNullOrEmpty(contactInfo.GeolocationAddress))
         {
             var geolocationAddress = string.Format(" {0} last known location is: {1}", contactInfo.FirstName, contactInfo.GeolocationAddress);
             smsBody += geolocationAddress;
         }
         var fromPhone       = ConfigurationManager.AppSettings["TwilioFromPhone"];
         var messageResponse = _twilioService.SendMessage(fromPhone, contactInfo.ContactPhoneNumber, smsBody);
         if (messageResponse == null || messageResponse.ErrorCode != 0)
         {
             return(false);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 2
0
        public ApiResult SendCode([FromBody] SmsRequestModel request)
        {
            Argument.ThrowIfNullOrEmpty(request.PhoneNumber, "手机号码");

            var result = new ApiResult();
            var type   = request.RequestType;

            if (!Enum.IsDefined(typeof(SmsRequestType), type))
            {
                throw new WebApiInnerException("0001", "请求类型参数无效");
            }

            var smsContent = _smsService.SendCode(request.PhoneNumber, MemberCenterModule.Instance, type.ToString());

            if (string.IsNullOrWhiteSpace(smsContent.ErrorMessage))
            {
                var data = new
                {
                    smsContent.Key,
                    Code = smsContent.KeyValues["Code"]
                };

                if (Platform != Platform.Web)
                {
                    result.SetData(data, true);
                }
            }
            else
            {
                result.msg = smsContent.ErrorMessage;
            }

            return(result);
        }
Esempio n. 3
0
        public bool SendSms(string number, string message)
        {
            Authenticate();

            var smsSubscription = new SMSSubcriptionService();
            var IsSubscribed    = smsSubscription.Subscribe(number);
            var flag            = false;

            if (AuthModel != null)
            {
                try
                {
                    var smsRequest = new SmsRequestModel
                    {
                        OutboundSMSMessageRequest =
                        {
                            SenderName       = IdearMartSenderName,
                            SenderAddress    = IdearMartSenderAddress,
                            ClientCorrelator = "123456",
                            Address          = new List <string> {
                                "tel:+" + number
                            },
                            OutboundSMSTextMessage = { Message = message },
                            ReceiptRequest         =
                            {
                                CallbackData = "",
                                NotifyURL    = "http://128.199.174.220:1080/sms/report"
                            }
                        }
                    };

                    var response = request.RequestApi <SmsRequestModel, SmsResponseModel>(smsRequest, request.GetCommonHeaders(AuthModel.AccessToken), null, Method.POST, IdeaMartSmsEndPoint.Replace("{port}", "87711"));

                    var test = response.Fault;
                    if (response.Fault == null)
                    {
                        flag = true;
                    }
                }
                catch (System.Exception)
                {
                    throw;
                }
            }
            return(flag);
        }
Esempio n. 4
0
        public async Task <HttpResponseMessage> SendSmsMessage(SmsRequestModel messageVm)
        {
            var response = new ApiResultViewModel <List <dynamic> >();

            if (ModelState.IsValid)
            {
                var httpcontext = HttpContext.Current.Request;

                if (httpcontext.Files.Count > 0)
                {
                    var file = httpcontext.Files[0].InputStream;
                }

                var request = new HttpRequestMessage(HttpMethod.Post, IposConfig.SmsHost);

                var p = await _smsSvc.Send(request);
            }

            return(Request.CreateResponse());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SmsRequestModelValidator"/> class.
 /// </summary>
 /// <param name="notificationContentRequestModel">Notification content request model.</param>
 public SmsRequestModelValidator(NotificationContentRequestModel notificationContentRequestModel)
 {
     _model = notificationContentRequestModel as SmsRequestModel;
 }
        public async Task <IHttpActionResult> ActiveSos(ActiveSosModel model)
        {
            //validate model
            if (!ModelState.IsValid)
            {
                foreach (var key in ModelState.Keys.Where(key => ModelState[key].Errors.Count > 0))
                {
                    return(BadRequest(ModelState[key].Errors[0].ErrorMessage));
                }
            }
            //find safety settings
            var safetySetting = _safetySettingService.GetByYayYoId(model.YayYoId);

            try
            {
                if (safetySetting == null)
                {
                    return(BadRequest("User does not exist"));
                }
                //update safety status
                safetySetting.Active       = true;
                safetySetting.UpdatedOnUtc = DateTime.UtcNow;
                await _safetySettingService.UpdateAsync(safetySetting);

                //create new SOS ID
                var logSos = new LogSos
                {
                    YayYoId         = model.YayYoId,
                    SafetySettingId = safetySetting.Id
                };

                await _logSosService.CreateAsync(logSos);

                //get ride book info from YayYo
                var rideBookRequest = new GetLastestRideBookRequestModel {
                    yayYo_id = model.YayYoId
                };
                var rideBookReponse = _yayYoService.GetRideBook(rideBookRequest);
                if (rideBookReponse == null)
                {
                    return(BadRequest("Error when get GetRideBook info"));
                }

                //add ride info to ride Information
                var rideBook = new LogRideInformation
                {
                    DriverName          = rideBookReponse.driver_name,
                    CarMake             = rideBookReponse.car_make,
                    CarModel            = rideBookReponse.car_model,
                    CarColor            = rideBookReponse.car_color,
                    CarLicense          = rideBookReponse.car_license,
                    YayYoId             = model.YayYoId,
                    LocationPickup      = rideBookReponse.pickup_location,
                    TimeEta             = rideBookReponse.time_eta,
                    TimePickup          = rideBookReponse.time_pickup,
                    LocationDestination = rideBookReponse.destination_location,
                    LogSosId            = logSos.Id
                };
                await _rideInformationService.CreateAsync(rideBook);

                //add SosGeolocation info
                var location = new LogSosGeolocation
                {
                    LogSosId = logSos.Id,
                    Location = model.GeoLocation
                };
                await _sosGeolocationService.CreateAsync(location);

                //send SMS
                var contacts = await _contactService.GetBySafetySettingIdAsync(safetySetting.Id);

                foreach (var contact in contacts)
                {
                    var contactInfo = new SmsRequestModel
                    {
                        FirstName           = safetySetting.FirstName,
                        RiderPickupLocation = rideBook.LocationPickup,
                        DestinationAddress  = rideBook.LocationDestination,
                        RideScheduledTime   = rideBook.TimePickup ?? DateTime.MinValue,
                        GeolocationAddress  = model.GeoLocation,
                        ContactPhoneNumber  = contact.Phone
                    };
                    _yayYoService.SendSms(contactInfo);
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }