Updated SendSMS
This commit is contained in:
Родитель
1846e8eaa8
Коммит
33349ae31a
|
@ -7,6 +7,22 @@
|
|||
$(".header_main__button_back").off("click");
|
||||
|
||||
$(".button_send_sms").on("click", function () {
|
||||
$.post("https://trackiotathletes.azurewebsites.net/api/v1/devices/sendSMS", {});
|
||||
|
||||
var data = {
|
||||
deviceId: $(".js-new_device_id .text_copy_container__input--add_device_copy_table").val().trim(),
|
||||
domain: $(".js-new_device_provider .text_copy_container__input--add_device_copy_table").val().trim(),
|
||||
deviceKey: $(".js-new_device_key .text_copy_container__input--add_device_copy_table").val().trim(),
|
||||
phoneNumber: $(".js-send_sms_phone_number").val().trim()
|
||||
}
|
||||
|
||||
console.log(data);
|
||||
|
||||
$.ajax({
|
||||
"dataType": "json",
|
||||
"type": "POST",
|
||||
"url": "/api/v1/devices/sendSMS",
|
||||
"cache": false,
|
||||
"data": data
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,7 +20,7 @@ else
|
|||
<td class="table_credentials__label">
|
||||
@Strings.DeviceIdColon
|
||||
</td>
|
||||
<td class="table_credentials__value">
|
||||
<td class="table_credentials__value js-new_device_id">
|
||||
@IoTHelpers.TextCopy("DeviceId", classname, @Model.DeviceId)
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -28,7 +28,7 @@ else
|
|||
<td class="table_credentials__label">
|
||||
@Strings.AzureDevicesHostnameColon
|
||||
</td>
|
||||
<td class="table_credentials__value">
|
||||
<td class="table_credentials__value js-new_device_provider">
|
||||
@IoTHelpers.TextCopy("AzureDevicesHostname", classname, @Model.HostName)
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -36,7 +36,7 @@ else
|
|||
<td class="table_credentials__label">
|
||||
@Strings.DeviceKeyColon
|
||||
</td>
|
||||
<td class="table_credentials__value">
|
||||
<td class="table_credentials__value js-new_device_key">
|
||||
@IoTHelpers.TextCopy("PrimaryKey", classname, @Model.PrimaryKey)
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -47,7 +47,13 @@ else
|
|||
|
||||
<button type="button" class="button_base button_credentials" onclick="location.href = '@Url.Action("Index", "Device")' ">@Strings.Done</button>
|
||||
|
||||
<button type="button" class="button_base button_send_sms">@Strings.SendSMS</button>
|
||||
<div>
|
||||
Send Device info SMS To:
|
||||
|
||||
<input class="js-send_sms_phone_number" type="text" />
|
||||
|
||||
<button type="button" class="button_base button_send_sms">@Strings.SendSMS</button>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(Model.InstructionsUrl)) {
|
||||
<div class="content_instructions">
|
||||
|
|
|
@ -166,6 +166,10 @@
|
|||
<Reference Include="Owin">
|
||||
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RestSharp, Version=105.2.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\RestSharp.105.2.2\lib\net451\RestSharp.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
|
@ -236,6 +240,10 @@
|
|||
<Reference Include="System.Web.Optimization">
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Twilio.Api, Version=3.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Twilio.4.5.0\lib\3.5\Twilio.Api.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="WebGrease">
|
||||
<HintPath>..\..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
@ -10,8 +10,13 @@ using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infrastr
|
|||
using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infrastructure.Models;
|
||||
using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.DataTables;
|
||||
using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security;
|
||||
using System.Security.Cryptography;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using Twilio;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.WebApiControllers
|
||||
{
|
||||
|
@ -28,7 +33,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
// POST: api/v1/devices/sample/5
|
||||
[HttpPost]
|
||||
[Route("sample/{count}")]
|
||||
[WebApiRequirePermission(Permission.AddDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.AddDevices)]
|
||||
public async Task<HttpResponseMessage> GenerateSampleDevicesAsync(int count)
|
||||
{
|
||||
ValidatePositiveValue("count", count);
|
||||
|
@ -43,7 +48,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
// GET: api/v1/devices/5
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
[WebApiRequirePermission(Permission.ViewDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.ViewDevices)]
|
||||
public async Task<HttpResponseMessage> GetDeviceAsync(string id)
|
||||
{
|
||||
ValidateArgumentNotNullOrWhitespace("id", id);
|
||||
|
@ -63,7 +68,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
// Example: api/v1/devices?filterColumn=DeviceID&filterType=StartsWithCaseSensitive&filterValue=000&filterColumn=FirmwareVersion&filterType=ContainsCaseInsensitive&filterValue=564
|
||||
[HttpGet]
|
||||
[Route("")]
|
||||
[WebApiRequirePermission(Permission.ViewDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.ViewDevices)]
|
||||
public async Task<HttpResponseMessage> GetDevicesAsync(
|
||||
[FromUri]string search = null,
|
||||
[FromUri]string sortColumn = null,
|
||||
|
@ -109,7 +114,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
// This endpoint is used by the jQuery DataTables grid to get data (and accepts an unusual data format based on that grid)
|
||||
[HttpPost]
|
||||
[Route("list")]
|
||||
[WebApiRequirePermission(Permission.ViewDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.ViewDevices)]
|
||||
public async Task<HttpResponseMessage> GetDevices([FromBody]JObject requestData)
|
||||
{
|
||||
return await GetServiceResponseAsync<DataTablesResponse>(async () =>
|
||||
|
@ -148,25 +153,30 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
// POST: api/v1/devices/sendSMS
|
||||
[HttpPost]
|
||||
[Route("sendSMS")]
|
||||
[WebApiRequirePermission(Permission.ViewDevices)]
|
||||
public async Task<HttpResponseMessage> SendSMS([FromBody]JObject requestData)
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.ViewDevices)]
|
||||
public HttpResponseMessage SendSMS([FromBody]JObject requestData)
|
||||
{
|
||||
List<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>;
|
||||
parameters.Add(new KeyValuePair<string, string>("To", "+17038638414"));
|
||||
parameters.Add(new KeyValuePair<string, string>("From", "+12064881483"));
|
||||
parameters.Add(new KeyValuePair<string, string>("Body", "This is a test from the application"));
|
||||
|
||||
HttpContent content = new FormUrlEncodedContent(parameters);
|
||||
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
|
||||
// Download the twilio-csharp library from twilio.com/docs/csharp/install
|
||||
|
||||
return await new HttpClient().PostAsync("https://AC2314c6031b641c3b877d84ee0d58a021:ffd9483b5d66b68d9dbac234fe771952@api.twilio.com/2010-04-01/Accounts/AC2314c6031b641c3b877d84ee0d58a021/Messages", content);
|
||||
// Find your Account Sid and Auth Token at twilio.com/user/account
|
||||
string AccountSid = "AC2314c6031b641c3b877d84ee0d58a021";
|
||||
string AuthToken = "ffd9483b5d66b68d9dbac234fe771952";
|
||||
var twilio = new TwilioRestClient(AccountSid, AuthToken);
|
||||
|
||||
string messageBody = requestData["domain"].ToString() + ';' + requestData["deviceId"].ToString() + ';' + requestData["deviceKey"].ToString();
|
||||
|
||||
var message = twilio.SendMessage("+12064881483", requestData["phoneNumber"].ToString(), messageBody);
|
||||
Console.WriteLine(message.Sid);
|
||||
|
||||
return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
|
||||
// DELETE: api/v1/devices/5
|
||||
[HttpDelete]
|
||||
[Route("{id}")]
|
||||
[WebApiRequirePermission(Permission.RemoveDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.RemoveDevices)]
|
||||
public async Task<HttpResponseMessage> RemoveDeviceAsync(string id)
|
||||
{
|
||||
ValidateArgumentNotNullOrWhitespace("id", id);
|
||||
|
@ -181,7 +191,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
// POST: api/v1/devices
|
||||
[HttpPost]
|
||||
[Route("")]
|
||||
[WebApiRequirePermission(Permission.AddDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.AddDevices)]
|
||||
public async Task<HttpResponseMessage> AddDeviceAsync(dynamic device)
|
||||
{
|
||||
ValidateArgumentNotNull("device", device);
|
||||
|
@ -195,7 +205,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
//PUT: api/v1/devices
|
||||
[HttpPut]
|
||||
[Route("")]
|
||||
[WebApiRequirePermission(Permission.EditDeviceMetadata)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.EditDeviceMetadata)]
|
||||
public async Task<HttpResponseMessage> UpdateDeviceAsync(dynamic device)
|
||||
{
|
||||
ValidateArgumentNotNull("device", device);
|
||||
|
@ -210,7 +220,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
//GET: api/v1/devices/5/hub-keys
|
||||
[HttpGet]
|
||||
[Route("{id}/hub-keys")]
|
||||
[WebApiRequirePermission(Permission.ViewDeviceSecurityKeys)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.ViewDeviceSecurityKeys)]
|
||||
public async Task<HttpResponseMessage> GetDeviceKeysAsync(string id)
|
||||
{
|
||||
ValidateArgumentNotNullOrWhitespace("id", id);
|
||||
|
@ -224,7 +234,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
//PUT: api/v1/devices/5/enabledstatus
|
||||
[HttpPut]
|
||||
[Route("{deviceId}/enabledstatus")]
|
||||
[WebApiRequirePermission(Permission.DisableEnableDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.DisableEnableDevices)]
|
||||
public async Task<HttpResponseMessage> UpdateDeviceEnabledStatus(string deviceId, [FromBody]JObject request)
|
||||
{
|
||||
bool isEnabled;
|
||||
|
@ -260,7 +270,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
// POST: api/v1/devices/5/commands/{commandName}
|
||||
[HttpPost]
|
||||
[Route("{deviceId}/commands/{commandName}")]
|
||||
[WebApiRequirePermission(Permission.SendCommandToDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.SendCommandToDevices)]
|
||||
public async Task<HttpResponseMessage> SendCommand(string deviceId, string commandName, [FromBody]dynamic parameters)
|
||||
{
|
||||
ValidateArgumentNotNullOrWhitespace("deviceId", deviceId);
|
||||
|
@ -279,7 +289,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
// DELETE: api/v1/all-devices
|
||||
[HttpDelete]
|
||||
[Route("~/api/v1/all-devices")]
|
||||
[WebApiRequirePermission(Permission.RemoveDevices)]
|
||||
[WebApiRequirePermission(Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security.Permission.RemoveDevices)]
|
||||
public async Task<HttpResponseMessage> DeleteAllDevices()
|
||||
{
|
||||
return await GetServiceResponseAsync(async () =>
|
||||
|
@ -312,4 +322,5 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
<package id="Autofac.WebApi2.Owin" version="3.3.0" targetFramework="net451" />
|
||||
<package id="dotless" version="1.5.1" targetFramework="net451" />
|
||||
<package id="Dynamitey" version="1.0.2.0" targetFramework="net451" />
|
||||
<package id="Microsoft.RemoteMonitoring.Infrastructure.Connectivity" version="1.0.0" targetFramework="net451" />
|
||||
<package id="jQuery" version="1.11.2" targetFramework="net451" />
|
||||
<package id="jQuery.UI.Combined" version="1.11.4" targetFramework="net451" />
|
||||
<package id="jQuery.UI.i18n" version="1.10.2" targetFramework="net451" />
|
||||
|
@ -39,14 +38,17 @@
|
|||
<package id="Microsoft.Owin.Security.Jwt" version="3.0.1" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin.Security.WsFederation" version="3.0.1" targetFramework="net45" />
|
||||
<package id="Microsoft.RemoteMonitoring.Infrastructure.Connectivity" version="1.0.0" targetFramework="net451" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Web.WebJobs.Publish" version="1.0.7" targetFramework="net451" />
|
||||
<package id="Moment.js" version="2.10.6" targetFramework="net451" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" />
|
||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||
<package id="Respond" version="1.4.2" targetFramework="net451" />
|
||||
<package id="RestSharp" version="105.2.2" targetFramework="net451" />
|
||||
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net451" />
|
||||
<package id="System.Spatial" version="5.6.4" targetFramework="net451" />
|
||||
<package id="Twilio" version="4.5.0" targetFramework="net451" />
|
||||
<package id="Unofficial.Microsoft.WindowsAzure.Diagnostics" version="2.7.0.0" targetFramework="net451" />
|
||||
<package id="WebGrease" version="1.6.0" targetFramework="net451" />
|
||||
<package id="WindowsAzure.Storage" version="5.0.2" targetFramework="net451" />
|
||||
|
|
|
@ -102,6 +102,10 @@
|
|||
<Reference Include="Owin">
|
||||
<HintPath>$(SolutionDir)\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RestSharp, Version=105.2.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\RestSharp.105.2.2\lib\net451\RestSharp.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
|
@ -135,6 +139,10 @@
|
|||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Twilio.Api, Version=3.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Twilio.4.5.0\lib\3.5\Twilio.Api.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EventProcessorModule.cs" />
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.1.0" targetFramework="net451" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" />
|
||||
<package id="Owin" version="1.0" targetFramework="net451" />
|
||||
<package id="RestSharp" version="105.2.2" targetFramework="net451" />
|
||||
<package id="System.Spatial" version="5.6.4" targetFramework="net451" />
|
||||
<package id="Twilio" version="4.5.0" targetFramework="net451" />
|
||||
<package id="Unofficial.Microsoft.WindowsAzure.Diagnostics" version="2.7.0.0" targetFramework="net451" />
|
||||
<package id="WindowsAzure.ServiceBus" version="3.0.4" targetFramework="net451" />
|
||||
<package id="WindowsAzure.Storage" version="5.0.2" targetFramework="net451" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче