public SendAccessResponseModel(Send send, GlobalSettings globalSettings)
            : base("send-access")
        {
            if (send == null)
            {
                throw new ArgumentNullException(nameof(send));
            }

            Id   = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray());
            Type = send.Type;

            SendData sendData;

            switch (send.Type)
            {
            case SendType.File:
                var fileData = JsonConvert.DeserializeObject <SendFileData>(send.Data);
                sendData = fileData;
                File     = new SendFileModel(fileData);
                break;

            case SendType.Text:
                var textData = JsonConvert.DeserializeObject <SendTextData>(send.Data);
                sendData = textData;
                Text     = new SendTextModel(textData);
                break;

            default:
                throw new ArgumentException("Unsupported " + nameof(Type) + ".");
            }

            Name           = sendData.Name;
            ExpirationDate = send.ExpirationDate;
        }
Ejemplo n.º 2
0
        public IHttpActionResult SendText(SendTextModel model)
        {
            ApiServerMsg result = new ApiServerMsg();

            try
            {
                if (XzyWebSocket._dicSockets.ContainsKey(model.uuid))
                {
                    var res = XzyWebSocket._dicSockets[model.uuid].weChatThread.Wx_SendMsg(model.wxid, model.text, model.atlist);
                    result.Success = true;
                    result.Context = res;
                    return(Ok(result));
                }
                else
                {
                    result.Success = false;
                    result.Context = "不存在该websocket连接";
                    return(Ok(result));
                }
            }
            catch (Exception e)
            {
                result.Success    = false;
                result.ErrContext = e.Message;
                return(Ok(result));
            }
        }
        public async Task <ActionResult <SendTextModel> > SendText(SendTextModel newTextData)
        {
            //data validation and filtering.  if going into a database one could encode on entry
            //log data from the request and what they attempted to request with.  Might want to encode this is you are not validation before logging.
            var response = await Task.Run(() => _redirect.Post(newTextData));

            return(Ok(response));
        }
Ejemplo n.º 4
0
        public SendResponseModel(Send send, GlobalSettings globalSettings)
            : base("send")
        {
            if (send == null)
            {
                throw new ArgumentNullException(nameof(send));
            }

            Id             = send.Id.ToString();
            AccessId       = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray());
            Type           = send.Type;
            Key            = send.Key;
            MaxAccessCount = send.MaxAccessCount;
            AccessCount    = send.AccessCount;
            RevisionDate   = send.RevisionDate;
            ExpirationDate = send.ExpirationDate;
            DeletionDate   = send.DeletionDate;
            Password       = send.Password;
            Disabled       = send.Disabled;
            HideEmail      = send.HideEmail.GetValueOrDefault();

            SendData sendData;

            switch (send.Type)
            {
            case SendType.File:
                var fileData = JsonSerializer.Deserialize <SendFileData>(send.Data);
                sendData = fileData;
                File     = new SendFileModel(fileData);
                break;

            case SendType.Text:
                var textData = JsonSerializer.Deserialize <SendTextData>(send.Data);
                sendData = textData;
                Text     = new SendTextModel(textData);
                break;

            default:
                throw new ArgumentException("Unsupported " + nameof(Type) + ".");
            }

            Name  = sendData.Name;
            Notes = sendData.Notes;
        }
        public String Post(Object o)
        {
            SendTextModel newTextData = (SendTextModel)o;

            try
            {
                //Log the requests that we are making if the Twilio app does not already store this information.

                TwilioClient.Init(Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"), Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"));
                var message = MessageResource.Create(
                    body: newTextData.Body,
                    from: new Twilio.Types.PhoneNumber(newTextData.From),
                    to: new Twilio.Types.PhoneNumber(newTextData.To)
                    );

                return(message.Sid);    //honestly a better error capture system would be better but with the time I have this works
            }
            catch (Exception)
            {
                //could send error to Logger with details
                return("Error in Twilio connection");
            }
        }
Ejemplo n.º 6
0
        public IHttpActionResult SendText(SendTextModel model)
        {
            ApiServerMsg apiServerMsg = new ApiServerMsg();

            try
            {
                if (XzyWebSocket._dicSockets.ContainsKey(model.uuid))
                {
                    string context = XzyWebSocket._dicSockets[model.uuid].weChatThread.Wx_SendMsg(model.wxid, model.text, model.atlist);
                    apiServerMsg.Success = true;
                    apiServerMsg.Context = context;
                    return(Ok(apiServerMsg));
                }
                apiServerMsg.Success = false;
                apiServerMsg.Context = "不存在该websocket连接";
                return(Ok(apiServerMsg));
            }
            catch (Exception ex)
            {
                apiServerMsg.Success    = false;
                apiServerMsg.ErrContext = ex.Message;
                return(Ok(apiServerMsg));
            }
        }