动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 移动短信技术
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ 移动短信技术 ]的信息

本月文章推荐
.一步一步搞定手机串口短信收发.
.在PC上通过手机发送短消息(续篇).
.基于Nokia S60的游戏开发之五.
.使用WinInet编写发送短信程序.
.利用手机模块实现短消息(二).
.MIDP2.0手机上手电筒程序的实现.
.英斯克的网关模拟器.
.用J2ME的通用联网框架开发联网的.
.CMPP CONNECT CODE SAMPLE.
.基于短信网关WAP推送的实现.
.各手机厂商开发规范(主要是铃声.
.免费实用!3步搞定电邮手机推送!.
.ERICSSON多媒体实验室提供的MMS和.
.联通SGIP模拟网关.
.基于CMPP2及东软API短信平台的开.
.利用J2ME在移动设备上实现动画的.
.基于Nokia S60的游戏开发之四.
.motorola铃声算法,是Java的!.
.基于CMPP3.0的企业短信网关API设.
.CMPP2.0协议升级.

用C#编写发手机中文短信息

发表日期:2003-6-11 |


最近在电脑城上买了一根NOKIA3210的数据线,玩了几天改LOGO、改铃声后也将数据线扔在一边。直到前几天在Http://oxygensoftware.com上看到有发手机短信息的二次开发控件,才想起多日不用的数据线,而且最近在学C#,觉得用C#做个发短信息的程序也不错,经过多天的测试,终于实现用电脑+数据线+手机的模式,实现在单位的局域网平台上发送短信息了。

  由于在单位使用到发手机短信息的地方有很多,可能是从网页、可能是OUTLOOK中的窗体、也可能是某台非Windows操作系统的主机的某个系统,所以经过思考探讨,觉得最好的解决方案是采用Windows的“服务”,定时从一个目录中固定格式的文本文件中读取出相应的信息,发送出去。而其它客户端只需往该目录写入文本信息即可。思路定下来后就让我们开始吧!

  先交待一下开发平台:Windows 2000 Advance Server操作系统、Visual Studio .Net 、Oxygen Sms ActiveX Control V2.3 (Share Ware)、 Nokia 3210手机通过数据线接在COM1上。运行Visual Studio .Net,新建一个C#的项目,选择“Windows Server”类型的项目,命名为“SmsServer”。在Server1的设计画面,将“ServerName”命名为“SmsServer”。点击“视图设计器按钮”切换到设计画面,在“Windows Forms”工具箱中拖一时钟控件,命名为“SmsTimer”,在“Components”工具箱中拖一“EventLog”控件。命名为“eventLog1”。在“项目”菜单中点击“添加引用”,选择“COM”页,浏览到安装Oxygen Sms ActiveX Control V2.3程序的目录,找到SMSControl.ocx添加到“选定的组件”中。

  将Server1.cs代码替换为
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.IO;
using System.Text ;
namespace SmsServer
{
public class SmsServer : System.ServiceProcess.ServiceBase
{
private System.Timers.Timer SmsTimer;
private System.Diagnostics.EventLog eventLog1;
public O2SMSXControl.O2SMSX SmsX1;//定义手机短信对象
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public SmsServer()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new SmsServer() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SmsTimer = new System.Timers.Timer();
this.eventLog1 = new System.Diagnostics.EventLog();
((System.ComponentModel.ISupportInitialize)(this.SmsTimer)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
//
// SmsTimer
//
this.SmsTimer.Enabled = true;
this.SmsTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.SmsTimer_Elapsed);
//
// SmsServer
//
this.ServiceName = "SmsServer";
((System.ComponentModel.ISupportInitialize)(this.SmsTimer)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
//开始服务时初始化手机.
SmsX1 = new O2SMSXControl.O2SMSXClass ();
SmsX1.ConnectionMode = 0; //联线类型cable
SmsX1.ComNumber = 1; //联接端口为com 1
SmsX1.Model = 0; //手机类型3210
SmsX1.Open (); //联接手机
SmsX1.SetSMSCNumber ("+8613800754500");//信息中心号码
}
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
SmsX1.Close ();
}
private void SmsTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//当f:\sms\data\filetosend有文件时,先关闭时钟,将其发送出去,并删除掉文件再启动时钟
this.SmsTimer.Enabled =false;
//目录对象
DirectoryInfo cd = new System.IO.DirectoryInfo("F:\\Sms\\Data\\FileToSend");
//数据库记录变量
string rsId;
string rsPhoneNum;
string rsSmsText;
string StrSql;
//首先,在当前目录中列举当前的所有SMS文件
foreach(FileInfo FileSend in cd.GetFiles ())
{
try
{
//依次打开每个文件读取文件内容
FileStream fs = new FileStream (cd.FullName + "\\" + FileSend.Name ,FileMode.Open,FileAccess.Read );
StreamReader sr;
sr = new StreamReader(fs,UnicodeEncoding.GetEncoding ("GB2312"));
rsId = FileSend.Name .ToString ();
rsId = rsId.Replace (".sms","");
rsId = rsId.Trim ();
rsPhoneNum = sr.ReadLine ();
rsPhoneNum = rsPhoneNum.Trim ();
if (rsPhoneNum.Length >11)
rsPhoneNum = rsPhoneNum.Substring (0,10);
rsSmsText = sr.ReadToEnd();
rsSmsText = rsSmsText.Trim ();
if (rsSmsText.Length >50)
rsSmsText.Substring (0,49);
fs.Close ();
sr.Close ();
//发送短信息
SmsX1.SendUnicodeSMSMessage (rsPhoneNum.ToString (),rsSmsText.ToString (),6,false,"");
//备份并删除文件
FileSend.CopyTo ("F:\\Sms\\Data\\HadBeenSend\\" + FileSend.Name ,true);
FileSend.Delete ();
}
catch(System.Exception E)
{
//出错写LOG文件
eventLog1.WriteEntry (E.Message.ToString ());
}
}
//重新启动时钟
this.SmsTimer.Enabled =true;
}
}

  在 Server1.cs切换设计画面,在属性窗口下点击“Add Installer”,系统自动增加ProjectInstaller.cs文件,点击serviceInstaller1,设置“Server Name”设置为“SmsServer”,点击“serviceProcessInstaller1”,设置Account为“LocalSystem”。

  选择菜单“生成”中的“生成SmsServer”,改正可能有的错误。进行DOS命令行,进行项目目录的\bin\debug目录下,执行“installutil SmsServer”,如果找不到installutil程序,就先Path一下。这时,在管理工具的“服务”下可以找到“SmsServer”服务了。启动该服务。这里默认源为目录F:\Sms\Data\FileToSend,如果这个目录有.SMS文件,就读取其第一行为发送的手机号码,第二行到文本结束为短信息内容,然后发送短信息,再将文本备份到F:\Sms\Data\HadBeenSend\。

  让我们再回头看一下Server1.cs中的代码。首先在命令空间要增加“using System.IO; using System.Text ; ”方便处理文件及文本对象,在命名类时
public class SmsServer : System.ServiceProcess.ServiceBase
{
private System.Timers.Timer SmsTimer;
private System.Diagnostics.EventLog eventLog1;
public O2SMSXControl.O2SMSX SmsX1;//定义手机短信对象
......
引用Oxygen控件中的定义SmsX1对象,然后在启动服务时初始化手机对象
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
//开始服务时初始化手机.
SmsX1 = new O2SMSXControl.O2SMSXClass ();
SmsX1.ConnectionMode = 0; //联线类型cable
SmsX1.ComNumber = 1; //联接端口为com 1
SmsX1.Model = 0; //手机类型3210
SmsX1.Open (); //联接手机
SmsX1.SetSMSCNumber ("+8613800754500");//信息中心号码

  其中要注意的是要初始化信息中心号码,如果不初始化,经常有发不去的情况。然后当时钟触发时要注意先将时钟关掉,再列举当前目录中的.SMS文件,逐一发送出去,再将时钟打开,同时在读文件时,要注意文件的编码 “sr=new StreamReader(fs,UnicodeEncoding.GetEncoding ("GB2312"));”采用GB2312编码读取才不会读出乱码出来,最后发送信息即可,“SmsX1.SendUnicodeSMSMessage (rsPhoneNum.ToString (),rsSmsText.ToString (),6,false,""); ”其中各个参数的含义可以参照Oxygen的帮助。最后在服务停止时释放短信息对象“SmsX1.Close ();” 如果出错,则写出错服务LOG文件“eventLog1.WriteEntry (E.Message.ToString ());”这样,在Windows的“事件查看器”就可以看到出错的信息了。

上一篇:编写SMS程序入门 人气:32419
下一篇:NOKIA封装的手机开发包SDK文档 人气:17497
浏览全部短信的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-9-7 站长中国企业(公司)网站系统 v4.2
2008-9-7 PBDigg v2.0 Build 20080821
2008-9-7 玩玩小游戏FLASH系统 v2.1
2008-9-7 522QQ在线电视直播程序 v1.1
2008-9-7 Pcook cms 文章管理系统 (老Y CM
2008-9-7 仿代码小说小偷系统 v1.0
2008-9-7 百度一搜集成搜索管理系统
2008-9-7 小贤统计器 v1.0
2008-9-6 Movie34电影搜索引擎 v3.0
2008-9-7 iBlacklist通话黑名单汉化破解补
2008-9-7 EndlessWalls无尽壁纸 v1.0.4破解
2008-9-7 Dynolicious车载测量仪v1.1破解版
2008-9-7 iVoodoo巫毒娃娃1.0.1破解版
2008-9-7 iWallpape精品墙纸1.2破解版
2008-9-7 iChillout自然音效工具1.1破解版
2008-9-7 Todo计划提醒1.2破解版
2008-9-7 allRadio电台集合1.01破解版
2008-9-7 My Money个人理财1.0破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | Html转换js | js/vbs加密 | md5加密 | 进制转换
实用工具:汉字翻译拼音 | 符号对照表 | 个税计算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵