在程序中,发送短信息的方式一般有三种:
1、 使用程序在网络上发送短信息,例如各大网站的短信业务。这种方式是通过程序将信息发送给运营商的网关服务器,然后通过运营商的网络发送给手机。
2、 在计算机中,通过数据线连接到手机,然后通过手机来发送短信息。这种方式是通过使用at指令来实现。爱立信手机的at指令你可以在以下地址找到:http://mobilityworld.ericsson.com.cn/development/download_hit.asp
3、 通过在手机中运行的程序来发送短信息。这个正是本文实现的方式。
在j2me中,如果想发送短信息,需要使用wma包,midp2.0中已经包含,midp1.0中可以通过厂商提供的扩展api实现,和wma的类库基本一样。
下面是使用wma向指定手机号码发送短信息的一个方法,很简单。当然wma也提供了其他的方式来发送更多的内容。 // smsutil.java
package my.util;
import javax.wireless.messaging.*;
import javax.microedition.io.*;
/**
* 发送文本短信息的方法
*/
public class smsutil
{
/**
* 给指定号码发送短信息
* @param content 短信息内容
* @param phonenumber 手机号码
* @return 发送成功返回true,否则返回false
*/
public static boolean send(string content,string phonenumber)
{
//返回值
boolean result = true;
try
{
//地址
string address = "sms://+" + phonenumber;
//建立连接
messageconnection conn = (messageconnection)connector.open(address);
//设置短信息类型为文本,短信息有文本和二进制两种类型
textmessage msg = (textmessage)conn.newmessage(messageconnection.text_message);
//设置信息内容
msg.setpayloadtext(content);
//发送
conn.send(msg);
}
catch(exception e)
{
result = false;
//未处理
}
return result;
}
}
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器