-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.cs
More file actions
53 lines (43 loc) · 1.25 KB
/
Controller.cs
File metadata and controls
53 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestSMS.Models;
namespace TestSMS.Controllers
{
public class SMSController : Controller
{
SerialPort sp = new SerialPort();
public ActionResult SMSIndex()
{
return View();
}
[HttpPost]
public ActionResult SendSMS(SMSViewModel model)
{
try
{
sendSMS(model.TelNo, model.Message);
System.Threading.Thread.Sleep(3000);
sendSMS(model.TelNo, model.Message);
return RedirectToAction("SMSIndex");
}
catch (Exception ex)
{
throw;
}
}
public void sendSMS(string mobNo, string msg)
{
string telNo = Char.ConvertFromUtf32(34) + mobNo + Char.ConvertFromUtf32(34);
sp.PortName = "COM4";
sp.Open();
sp.Write("AT+CMGF=1" + Char.ConvertFromUtf32(13));
sp.Write("AT+CMGS=" + telNo + Char.ConvertFromUtf32(13));
sp.Write(msg + Char.ConvertFromUtf32(26) + Char.ConvertFromUtf32(13));
sp.Close();
}
}
}