http://www.codeproject.com/asp/smsinasp.php?target=sms%7Cmessage

解决方案 »

  1.   

    不知是用来作什么的,如果只是加一个功能,你可以和一些ISP联系,利用它用的短信结口,
    如果想自己有发短信的功能,要和网通申请开通一下。然后他们会给你一个基于COM的源代码,
    修改一下就可以用了,注要是修改服务码!!!!
      

  2.   

    Zoujinyucn(不会游泳的鱼) 兄弟,哪个代码已经不存在了啊
      

  3.   

    移动、联通都有相关的短消息接口规范,调用接口规范即可
    very easy!!!
      

  4.   

    局域网你怎么发啊? 除非他们愿意买个gsm的专用设备,如果是通过internet还可以考虑用网关来发,你这个就只能买设备了吧?要不找个手机接到计算机上也行.
      

  5.   

    他们也不知道我也是第一次做这方面的工作,我想也是通过INTERNET发送的,不过我需要发送的手机用户,内容,和频率等这些参数,所以我想最好有源代码可以研究研究了.呵呵,,,不过你们的意见很有价值我会给分的,谢谢你们!
      

  6.   

    我也是第一次做这方面的工作,我想也是通过INTERNET发送的,不过我需要发送的手机用户,内容,和频率等这些参数,所以我想最好有源代码可以研究研究了.呵呵,,,不过你们的意见很有价值我会给分的,谢谢你们!
      

  7.   

    有一个是肯定的,单纯在局域网是没法发短信的,
    只有通过INTERNET发送,所以,要作这些就必须到移动,联通等地方去申请,他们会给你一个程序的源代码的,是用来给你的服务器提供短信服务的,不过好像用不着频率这个参数吧
      

  8.   

    好吧,帖一个.吼吼...俺短信传输协议规范
    1. 协议说明:
    本协议是xxx与其客户之间传送短信所用的接口协议,通过本协议客户可以与xxx通讯并使用xxx特服号码发送短消息,并且客户可以接收到手机用户上行的短消息;
    2. 通讯流程:
    使用本协议承载时,xxx讯与客户互为客户端、服务器端,客户在发送短信时为客户端,xxx为服务器端,客户在接收手机用户上行短信时为服务器端,xxx为客户端。当客户端有发送任务时,主动与服务器端建立链接,然后即可对服务器端发送命令,并随后接收命令应答;服务器端接收到客户端命令后,对其处理之后返回应答;链接建立后,客户端可以连续发送多条命令,处理完所有命令后,客户端应主动断开链接;当一条链路上空闲时间过长(60秒),服务器端会主动断开该链接;
    客户端与服务器端建立链接后,客户端首先要发送认证命令,服务器端确认客户端发送的用户名、密码有效后发送正确的认证结果给客户端,随后客户端才可以继续发送命令,在所有命令发送完毕后,客户端先断开链接,随后服务器端断开链接;
    3. 消息定义:
    3.1数据类型:
    消息中涉及到的数据类型有:类型 说明
    Integer  无符号整数
    Text 定长字符串,左对齐存储,空余位置补’\0’
    表1数据类型
    Integer 型字段中以网络字节序存放;
    3.2消息结构定义:
    本协议中涉及消息全部有“消息头”和“消息体”两部分构成;项目 说明
    消息头 消息头部分
    消息体 消息体部分
    表2消息结构
    3.3消息头定义:
    字段 长度(字节) 类型 说明
    Message Length 4 Integer 消息的总长度(字节)
    Command ID 4 Integer 命令ID
    表3消息头的格式
    命令ID见附录 A;
    3.4消息体定义:
    3.4.1 认证:
    字段 长度(字节) 类型 说明
    CorpID 16 Text 登录用户名
    Password 16 Text 登录密码
    Reserve 8 Text 保留,扩展用
    表4 认证消息格式
    3.4.2 认证回应:
    字段 长度(字节) 类型 说明
    Result 1 Integer 认证结果:0:成功;非0:失败(见附录B);
    Reserve 8 Text 保留,扩展用
    表5 认证回应消息格式
    3.4.3 发送单条短信:
    字段 长度(字节) 类型 说明
    ChargNumber 21 Text 付费手机号码
    DestNumber 21 Text 接收手机号码
    FeeType 1 Integer 计费类型:0:接收方付费1:预付费
    FeeClass 1 Integer 计费类别(金额):0:免费1:0.1圆2:0.2圆3:0.3圆……20:2圆
    SmType 1 Integer 0:针对MO的MT消息1:没有MO的MT消息
    ScheduleTime 16 Text 短消息定时发送的时间,如果为空,表示立刻发送该短消息。时间内容格式为“YYYYMMDDhhmmss”
    MessageCoding 1 Integer 短消息的编码格式。0:纯ASCII字符串3:写卡操作4:二进制编码8:UCS2编码15: GBK编码其它参见GSM3.38第4节:SMS Data Coding Scheme
    MessageLength 4 Integer 消息长度
    MessageContent MessageLength Text 消息内容
    Reserve 8 Text 保留,扩展用
    表6 发送短消息格式
    3.4.4 发送单条短信回应:
    字段 长度(字节) 类型 说明
    Result 1 Integer 发送结果:0:成功;非0:失败(见附录B);
    Reserve 8 Text 保留,扩展用
    表7 发送短消息回应格式
    3.4.5 余额查询:
    消息体为空;
    3.4.6 余额查询回应:
    字段 长度(字节) 类型 说明
    Value 4 Integer 剩余金额
    Reserve 8 Text 保留,扩展用
    表8 余额查询回应格式
    3.4.7 接收单条信息:
    字段 长度(字节) 类型 说明
    SrcNumber 21 Text 点播手机号码
    MessageContent 140 Text 信息内容不足为’\0’
    Reserve 8 Text 保留,扩展用
    表9 接收短消息回应格式
    3.4.8 接收单条信息回应:
    字段 长度(字节) 类型 说明
    Result 1 Integer 接收结果:0:成功;非0:失败(见附录B);
    Reserve 8 Text 保留,扩展用
    表10 接收短消息回应格式附录A:消息ID定义
    消息ID名称 消息ID取值
    认证 0x1
    认证回应 0x80000001
    发送短消息 0x2
    发送短消息回应 0x80000002
    余额查询 0x3
    余额查询回应 0x80000003
      

  9.   

    由于在单位使用到发手机短信息的地方有很多,可能是从网页、可能是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;   }}}
      

  10.   

    在 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的“事件查看器”就可以看到出错的信息了。  但是这里有个小小的遗憾,通过OCX控件发出的短信息前面有一串该网站的英文,但是注册版不会有这串字,注册“只需”¥399就可以了。//注意是抄来的嘿嘿