使用NowSMS Gateway来接收发送短信和彩信
硬件准备:
GPRS Modem,不同的运营商波段可能不一样,比如Cingular是850/1900 MHz,而China Mobile是900/1800 MHz,购买时要注意.把SIM card插入Modem, SIM要开通GPRS service,把Modem接到COM Port,完成硬件准备。
软件准备:
下载SMS Gateway,我用的是NowSMS Gateway,觉得还可以,支持多种语言字符集,在http://www.nowsms.com/可以下载60天试用版本,网上也有其他的Gateway.
添加GPRS Modem:
由于不同Modem,NowSMS Gateway不一定都能认识,以至于在配置MMS的时候不能认出COM port,我用的WaveCOM的Modem,配彩信时救认不出.
所以要先通过在Windows里添加标准Modem以便NowSMS gateway识别.
Control Panel-->Phone and Modem options-->Modems:
Select Add, follow the wizard, and select appropriate COM port, GPRS Modem could be recognized.
怎样来配置NowSMS Gateway,大部分在其网站有如何配置说明,这里主要讲一下有几个要注意的地方,特别是配置MMS的时候。
如何配置短信可以参考网站的资料(http://www.nowsms.com/documentation/ProductDocumentation/2_way_sms_support.htm),这里就不多说
配置Gateway通过GPRS Modem收发彩信(http://www.nowsms.com/documentation/ProductDocumentation/2_way_mms_support.htm):
大部分内容在里面都有,这里我只提一下通过GPRS Modem来收发彩信,还可以通过网络连接来收发彩信,不过不同的Operator有一定的限制.
配置GPRS Modem接收彩信:
如果Modem加好了没问题,你可以在NowSMS Gateway的SMSC面板 Add的时候就能看到你刚才加的Modem,选择这个Modem就可以了,然后可以按一下Test可以测试一下Modem是否work.
接着可以在Properties里配置MMS Setting.
选择相应的Operator,选择Use Specific Network Connection(GPRS Modem),这时可以在Network Connection里找到刚才添加的Modem,选择即可,然后可以点击Test Connection测试连接是否工作
这样你就可以通过GPRS Modem接收彩信了,如果你配置为存在制定目录的话,接收的彩信将会存在那个目录,每个彩信会有一个.hdr的头文件,和一个放彩信内容
的子目录.
配置GPRS Modem发送彩信:
在MMSC Routing里面选择Add,添加一个Additional Routes,在配置MMS Outbound Routing的Dialog里的Route message to VASP via:选项里选MM1,选择Use Specific Network Connection(GPRS Modem),在Network Connection下拉框里选择刚才添加的Modem连接,OK后,把Default Route设置为这个新添的Route就可以了.
收到彩信后你可以写自己的程序去处理,NowSMS本身也支持配置Php来处理(http://www.nowsms.com/support/bulletins/tb-nowsms-016.htm).
如何用程序来发送SMS和MMS, NowSMS Gateway提供一种Web Menu Interface(http://www.nowsms.com/documentation/ProductDocumentation/the_web_interface/index.htm),你只要把要发的信息,和手机号提交给web server就可以了,接口比较方便易用, SMS用GET方式,MMS用的是POST方式.
发送短信函数(C#):
private void SendSMSMessage(String strMobile, String strText)
{
try
{
String request = "http://127.0.0.1:8800/Send%20Text%20Message.htm?PhoneNumber=" + strMobile + "&Text=" + strText + "&InfoCharCounter=&PID=&DCS=&Submit=Submit";
Uri myUri = new Uri(request);
// Create a new request to the above mentioned URL.
WebRequest myWebRequest = WebRequest.Create(myUri);
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse = myWebRequest.GetResponse();
}
catch (Exception)
{
throw;
}
}
发送彩信函数(C#):
protected byte[] CreateTextData(string boundary, string textFormName, string strText)
{
// Build up the post message header.
StringBuilder sb = new StringBuilder();
sb.Append("--");
sb.Append(boundary);
sb.Append("/r/n");
sb.Append("Content-Disposition: form-data; name=/"");
sb.Append(textFormName);
sb.Append("/"");
sb.Append("/r/n");
sb.Append("/r/n");
sb.Append(strText);
sb.Append("/r/n");
// Return te post message header in a byte array encoded as UTF8.
return Encoding.UTF8.GetBytes(sb.ToString());
}
protected byte[] CreateImageFile(string boundary, string fileFormName, string filePath)
{
// Build up the post message header.
StringBuilder sb = new StringBuilder();
sb.Append("--");
sb.Append(boundary);
sb.Append("/r/n");
sb.Append("Content-Disposition: form-data; name=/"");
sb.Append(fileFormName);
sb.Append("/"; filename=/"");
sb.Append(Path.GetFileName(filePath));
sb.Append("/"");
sb.Append("/r/n");
sb.Append("Content-Type: ");
sb.Append("image/pjpeg");
sb.Append("/r/n");
sb.Append("/r/n");
// Return te post message header in a byte array encoded as UTF8.
return Encoding.UTF8.GetBytes(sb.ToString());
}
private void SendMMSMessage(String strMobile, String strSubject, String strText, String strImagePath)
{
// Create a FileInfo object of the file.
FileInfo fileInfo = new FileInfo(strImagePath);
Uri myUri = new Uri("http://127.0.0.1:8800/Send%20MMS%20Message.htm");
// Instantiate a new WebRequest.
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(myUri);
webrequest.Method = "POST";
webrequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*";
webrequest.Referer = "http://127.0.0.1:8800/Send%20MMS%20Message.htm";
webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
webrequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)";
webrequest.KeepAlive = true;
// Create the post message header.
// Create PhoneNumber
byte[] postPhoneNumber = CreateTextData(boundary, "PhoneNumber", strMobile);
// Create MMSFrom
byte[] postMMSFrom = CreateTextData(boundary, "MMSFrom", "");
// Create MMSSubject
byte[] postMMSSubject = CreateTextData(boundary, "MMSSubject", strSubject);
// Create MMSText
byte[] postMMSText = CreateTextData(boundary, "MMSText", strText);
// Create MMSFile
byte[] postImageBytes = CreateImageFile(boundary, "MMSFile", strImagePath);
//Create Submit
byte[] postSubmitBytes = CreateImageFile(boundary, "Submit", "Submit");
// Build the trailing boundary string as a byte array
// ensuring the boundary appears on a line by itself
byte[] boundaryBytes = Encoding.ASCII.GetBytes("/r/n--" + boundary + "/r/n");
// Create the Stream objects.
FileStream fileStream = null;
Stream requestStream = null;
try
{
// Instantiate the local FileStream.
fileStream = new FileStream(strImagePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
long length = postPhoneNumber.Length + postMMSFrom.Length + postMMSSubject.Length + postMMSText.Length
+ postImageBytes.Length + fileStream.Length + postSubmitBytes.Length + boundaryBytes.Length;
webrequest.ContentLength = length;
// Get the request stream from the webrequest.
requestStream = webrequest.GetRequestStream();
// Write out our post header
requestStream.Write(postPhoneNumber, 0, postPhoneNumber.Length);
requestStream.Write(postMMSFrom, 0, postMMSFrom.Length);
requestStream.Write(postMMSSubject, 0, postMMSSubject.Length);
requestStream.Write(postMMSText, 0, postMMSText.Length);
requestStream.Write(postImageBytes, 0, postImageBytes.Length);
// Write out the file contents
byte[] buffer = new Byte[fileStream.Length];
int bytesRead = 0;
long totalBytes = 0;
// Read the bytes from the local file stream.
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
// Write the readed bytes to the request stream.
requestStream.Write(buffer, 0, bytesRead);
totalBytes += bytesRead;
}
// Write submit
requestStream.Write(postSubmitBytes, 0, postSubmitBytes.Length);
// Write out the trailing boundary
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
// Get response.
using (WebResponse response = webrequest.GetResponse())
{
Stream responseStream = null;
try
{
// Get response stream.
responseStream = response.GetResponseStream();
StreamReader streamRead = new StreamReader(responseStream);
streamRead.Close();
}
finally
{
// Close response stream when it exists.
if (responseStream != null)
{
responseStream.Close();
}
// Close the response.
response.Close();
}
}
}
finally
{
// Cleanup uses.
if (requestStream != null)
{
try
{
requestStream.Close();
}
catch
{
// Eat up exception.
}
}
if (fileStream != null)
{
try
{
fileStream.Close();
}
catch
{
// Eat up exception.
}
}
if (webrequest != null)
{
try
{
// Abort webrequest.
webrequest.Abort();
}
catch (WebException caught)
{
// Eat up exception and close
// response then exists.
if (caught.Response != null)
{
caught.Response.Close();
}
}
}
}
}
这里只是一些随写,更具体的信息可以参考NowSMS的网站,和GPRS Modem的厂商站点和手册.
如果Modem有问题,或者想知道Modem是否支持SMS和MMS,可以使用HyperTerminal连接Modem测试,有关GPRS Modem的一些Command可以在网络上搜到.
AT+CREG? - if registered on network second value should be 1
AT+COPS? - returns Network operator eg. Cingular
AT+CSQ - checks signal strength, value should be greater than 10
使用NowSMS Gateway来接收发送短信和彩信相关推荐
- 安卓短信功能全解:调用系统短信功能发送短信、彩信,使用SmsManager发送短信,并监听发送短信的投递情况,使用广播接收器监听接收的短信。
全栈工程师开发手册 (作者:栾鹏) 安卓教程全解 安卓短信功能全解:调用系统短信功能发送短信.彩信,使用SmsManager发送短信,并监听发送短信的投递情况,使用广播接收器监听接收的短信. 首先需要 ...
- Windows mobile PPC,利用tmail.exe发送短信、彩信、邮件
利用tmail.exe发送短信.彩信.邮件 在有关短信.邮件的开发中,我们经常会使用MAPI来开发,但此次在项目开发时却遇到些问题,就是首先MAPI不支持发送彩信,其次使用MAPI需要自己开发相应的U ...
- Windows mobile PPC 下利用 tmail.exe 发送短信、彩信、邮件
在有关短信.邮件的开发中,我们经常会使用MAPI来开发,但此次在项目开发时却遇到些问题,就是首先MAPI不支持发送彩信,其次使用MAPI需要自己开发相应的UI界面,若是自己开发UI界面同时还需负责相关 ...
- android 发送彩信监听,在Android中发送短信和彩信,监听短信并显示
发送短信: String body="this is sms demo"; Intent mmsintent = new Intent(Intent.ACTION_SENDTO, ...
- android 读取短信 彩信,Android系统中发送短信和彩信的代码
发送短信: String body="this is sms demo"; Intent mmsintent = new Intent(Intent.ACTION_SENDTO, ...
- java 彩信发送_Android系统中发送短信和彩信的代码
导读热词 下面是编程之家 jb51.cc 通过网络收集整理的代码片段. 编程之家小编现在分享给大家,也给大家做个参考. String body="this is sms demo" ...
- Android接收和发送短信
每一部手机都具有短信接收和发送功能,下面我们通过代码来实现接收和发送短信功能. 一.接收短信 1.创建内部广播接收器类,接收系统发出的短信广播 2.从获得的内容中解析出短信发送者和短信内容 3.在Ac ...
- Android接收短信和发送短信
一.布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...
- twilio php 发送短信,如何接收短信到一个twilio号码
Twilio福音传教士在这里. Twilio通知您传入短信和传入语音电话呼叫的方式是使用称为webhook的东西.这基本上是Twilio对您告诉我们的URL所做的HTTP请求.通常,这个网址是您创 ...
最新文章
- 什么样的电路仿真软件可以显示电流流动?
- linux创建进程读共享写复制,Linux下进程的创建、执行和终止
- C语言 | 基于DS1302 的万年历实现
- ZOJ - 4122 Triangle City(最短路+欧拉通路+思维)
- virtual box虚拟机分区后下一步看不见解决
- 【Envi风暴】Envi5.4经典安装图文教程
- 服务器批量修改代码,利用Redis实现多服务器批量操作
- apk android lite,APKPure Lite
- hlsl之ambient
- NASA好奇号发来战报,32368张火星路况实拍数据集上线 | 资源
- MySQL Err126错误[Err] 126 - Incorrect key file for table '.\device\table_name.MYI'; try to repair it
- 想不明白:为什么龙芯取消了MIPS版OpenJDK8开源
- Hibernate 关于配置Mapping不成功 Unknow Entity
- SpringApplication.run方法分析
- jquery 移动端 ui 组件库 移动端前端UI库—Frozen UI、SUI Mobile、light7、WeUI、jqweui
- 台式计算机识别不了u盘启动,台式机不认U盘启动解决方法
- Elasticsearch:使用向量搜索来查询及比较文字 - NLP text embedding
- layim之整合WebSocket即时通讯
- 跳一跳改分php源码,小游戏“跳一跳”居然可改分,微信小程序现漏洞
- 中国量化金融行业 全解 金融工程 计算机 统计学 金融 专业领域 就业指南
热门文章
- 使用Docker部署GitLab、Nexus、Registry私服
- linux设置默认启动桌面或是命令行,使用一个命令重置 Linux 桌面为默认设置
- android切换默认应用_如何在Android上设置默认应用
- php的exce函数删除,trim函数的作用是删除文本的什么
- i.MX6ULL终结者官方SDK简介
- 调用百度地图API,如何只显示某个省份的地图
- 竞价软件测试工资,我的人工智能软件加入了开盘集合竞价换手率检测功能
- 凯迪仕智能锁完成C轮6亿融资10亿综合授信,开启全球化战略新篇章
- 数据类型与数据类型分类
- 计算机组装大赛宣传,“能工巧匠”电脑硬件组装大赛活动报道