c# 开发短信功能

上传人:第*** 文档编号:38820198 上传时间:2018-05-08 格式:DOC 页数:8 大小:132KB
返回 下载 相关 举报
c# 开发短信功能_第1页
第1页 / 共8页
c# 开发短信功能_第2页
第2页 / 共8页
c# 开发短信功能_第3页
第3页 / 共8页
c# 开发短信功能_第4页
第4页 / 共8页
c# 开发短信功能_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《c# 开发短信功能》由会员分享,可在线阅读,更多相关《c# 开发短信功能(8页珍藏版)》请在金锄头文库上搜索。

1、C#C#利用利用 WebWeb ServiceService 实现短信发送实现短信发送 2006-03-26 中文 C#技术站 通过编程方式实现短信息的发送对很多人来说是一件比较烦杂的事情,目 前一般的解决方法是通过计算机和手机的连线,通过可对手机编程的语言编写 相关的手机短信息程序来实现,而这种方法对于一般人来说是很难达到的,因 为此种方法不仅要有很多必备的硬件设备,也还需懂得手机编程的相关知识。 本文就来探讨一下另外一种通过 Visual C#发送短信息的简单实现方法,这种 方法在实现过程中比我们想象的要简单许多,只需拥有 Visual C#一般编程基 础,并确定您的计算机接入互联网即可。

2、下面就来详细介绍一下 Visual C#发 送短信息的具体实现过程。一一. . VisualVisual C#C#发送短信息的原理:发送短信息的原理:我想当很多读者一看到本文的题目一定会想本文内容一定非常深奥,并且 作者一定知道了电信的发送短信的网关地址,其实并非如此。本文其实是利用 一个现成的资源,一个可发送短信的 Web Serviec。这个 Web Service 就是新 浪网就提供的一个,可供用户直接调用的发送短消息的 Web Service。这个 Service 的地址是 http:/ Service 中提供了一个发送短消息的方法“sendXml“。此方法的语法格式如下:string

3、 sendXml (carrier , userid , password , mobilenumber , content , msgtype )sendXml 方法中的六个参数均为 string 类型,并且 sendXml 方法的返回值 也是 string 类型。以下是 sendXml 方法中的六个参数的具体说明:carrier:运营商名称,具体使用时此参数并没有什么具体要求,即这里 面可以随便输,输入的字符串也不会在对方手机中有任何显示。 userid:在新浪网上注册的手机号,注册手机所用的地址是: http:/,具体注册方法下面会具体介绍。 password:您在新浪网成功注册手机后,

4、新浪网所反馈来的密码。 mobilenumber:要发送短信到对方的手机号码。 content:所要发送短消息的内容。 msgtype:发送短消息的类型,由于本文发送的不是彩信,所以输入“Text“。调用此 Web Service 只需在 Visual C#开发环境中直接添加 Web 引用,把 该地址输入即可,就可以使用此 Web Service 中的 sendXml 方法发送短消息了。 当然发送短消息的机器必须接入互联网。二在新浪网上注册手机二在新浪网上注册手机:按照如下步骤就可在新浪网上注册手机:1. 打开浏览器,并在地址栏中输入新浪无线的地址: http:/.。在浏览器德左上角,可见如图

5、 01 界面:图 01:新浪网注册手机界面之一输入手机号后,单击图 01 中的“登陆“,如果你的手机没有在新浪,则提示 如图 02 所示信息。图 02:新浪网注册手机界面之二2. 按照图 02 中的选项输入相应的信息后,单击“登陆移动梦网“按钮,如 果注册成功,移动梦网则会向你注册的手机上发送一个 8 位长度的口令就可以 得到图 03 所示界面。图 03:新浪网注册手机界面之三这个口令要保留,下面发送短信就要使用这个口令。三本文程序设计、调试和运行的环境:三本文程序设计、调试和运行的环境:(1).微软公司视窗 2000 服务器版。(2).Visual Studio .Net 2003 企业构建

6、版,.Net FrameWork SDK 版本 号 4322。四四VisualVisual C#C#实现短信息发送的具体实现步骤:实现短信息发送的具体实现步骤:Visual C#发送短信息的关键就是通过 Web 引用新浪网提供的发送短信息的 Web Service,并在引用完成后。调用此 Service 的 sendXml 方法即可。以下就 是 Visual C#引用 Web Service 发送短信息的具体实现步骤:1. 启动 Visual Studio .Net。2. 选择菜单【文件】|【新建】|【项目】后,弹出【新建项目】对话框。3. 将【项目类型】设置为【Visual Basic 项目

7、】。4. 将【模板】设置为【Windows 应用程序】。5. 在【名称】文本框中输入【短信】。6. 在【位置】的文本框中输入【E:VS.NET 项目】,然后单击【确定】按 钮,这样在“E:VS.NET 项目“目录中就产生了名称为“短信“的文件夹,并在里 面创建了名称为“短信“的项目文件。7. 把 Visual Studio .Net 的当前窗口切换到【Form1.cs(设计)】窗口, 并从【工具箱】中的【Windows 窗体组件】选项卡中往 Form1 窗体中拖入下列 组件,并执行相应的操作:四个 Label 组件。四个 TextBox 组件。一个 Button 组件,其作用是发送短信息。并在

8、这个 Button 组件拖入 Form1 的设计窗体后,双击它,则系统会在 Form1.cs 文件分别产生这个组件的 Click 事件对应的处理代码。8. 把 Visual Studio .Net 的当前窗口切换到 Form1.vb 的代码编辑窗口, 并用下列代码替换 Form1.cs 中的 InitializeComponent 过程对应的代码,下列 代码作用是初始化窗体中加入的组件:private void InitializeComponent ( ) this.textBox1 = new System.Windows.Forms.TextBox ( ) ; this.textBox2

9、 = new System.Windows.Forms.TextBox ( ) ; this.textBox3 = new System.Windows.Forms.TextBox ( ) ; this.button1 = new System.Windows.Forms.Button ( ) ; this.label1 = new System.Windows.Forms.Label ( ) ; this.label2 = new System.Windows.Forms.Label ( ) ; this.label3 = new System.Windows.Forms.Label ( )

10、 ; this.label4 = new System.Windows.Forms.Label ( ) ; this.textBox4 = new System.Windows.Forms.TextBox ( ) ; this.SuspendLayout ( ) ; this.textBox1.Location = new System.Drawing.Point ( 144 , 16 ) ; this.textBox1.Name = “textBox1“ ; this.textBox1.Size = new System.Drawing.Size ( 184 , 21 ) ; this.te

11、xtBox1.TabIndex = 0 ; this.textBox1.Text = “ ; this.textBox2.Location = new System.Drawing.Point ( 144 , 69 ) ; this.textBox2.Name = “textBox2“ ; this.textBox2.PasswordChar = * ; this.textBox2.Size = new System.Drawing.Size ( 184 , 21 ) ; this.textBox2.TabIndex = 1 ; this.textBox2.Text = “ ; this.te

12、xtBox3.Location = new System.Drawing.Point ( 144 , 122 ) ; this.textBox3.Name = “textBox3“ ; this.textBox3.Size = new System.Drawing.Size ( 184 , 21 ) ; this.textBox3.TabIndex = 2 ; this.textBox3.Text = “ ; this.button1.Location = new System.Drawing.Point ( 152 , 256 ) ; this.button1.Name = “button1

13、“ ;this.button1.Size = new System.Drawing.Size ( 80 , 32 ) ; this.button1.TabIndex = 4 ; this.button1.Text = “发送“ ; this.button1.Click += new System.EventHandler ( this.button1_Click ) ; this.label1.Location = new System.Drawing.Point ( 56 , 24 ) ; this.label1.Name = “label1“ ; this.label1.Size = ne

14、w System.Drawing.Size ( 88 , 16 ) ; this.label1.TabIndex = 5 ; this.label1.Text = “注册手机号:“ ; this.label2.Location = new System.Drawing.Point ( 88 , 77 ) ; this.label2.Name = “label2“ ; this.label2.Size = new System.Drawing.Size ( 72 , 16 ) ; this.label2.TabIndex = 6 ; this.label2.Text = “口令:“ ; this

15、.label3.Location = new System.Drawing.Point ( 56 , 128 ) ; this.label3.Name = “label3“ ; this.label3.Size = new System.Drawing.Size ( 96 , 16 ) ; this.label3.TabIndex = 7 ; this.label3.Text = “目标手机号:“ ; this.label4.Location = new System.Drawing.Point ( 96 , 176 ) ; this.label4.Name = “label4“ ; this

16、.label4.Size = new System.Drawing.Size ( 72 , 16 ) ; this.label4.TabIndex = 8 ; this.label4.Text = “内容:“ ; this.textBox4.Location = new System.Drawing.Point ( 144 , 175 ) ; this.textBox4.Multiline = true ; this.textBox4.Name = “textBox4“ ; this.textBox4.Size = new System.Drawing.Size ( 184 , 48 ) ; this.textBox4.TabIndex = 3 ; this.textBox4.Text = “

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号