饶荣庆 -- 您今天UCWEB了吗?--http://www.ucweb.com

3G 手机开发网

   :: 首页 :: 联系 :: 聚合  :: 管理
  99 Posts :: 1 Stories :: 219 Comments :: 0 Trackbacks
这几天由于公司的需要,见到有些同事用手机刷卡,觉得很痛苦。
今天早上回来就产生了一个想法,不如用j2me实现一个短信发送机的程序,然后只需要填入几个数字就可以实现短信的自动发送等。
经过大概2个小时的奋斗,终于写好了,并且在多部不同品牌的机器运行良好,而且很实用,不过可以有些手机需要数字签名,否则的话,会不停的提示你。郁闷,不过索爱跟三星就可以设置。
现在公布源代码跟按照文件
先让大家看个图
 

java 代码
  1. /********************************************************************
  2. * 项目名称 :j2me学习
  3. *
  4. * Copyright 2005-2006 Wuhua. All rights reserved
  5. ********************************************************************/
  6. package org.fox.sms;

  7. import java.io.IOException;

  8. import javax.microedition.io.Connector;
  9. import javax.microedition.lcdui.Command;
  10. import javax.microedition.lcdui.CommandListener;
  11. import javax.microedition.lcdui.Displayable;
  12. import javax.microedition.lcdui.Form;
  13. import javax.microedition.lcdui.TextField;
  14. import javax.wireless.messaging.MessageConnection;
  15. import javax.wireless.messaging.TextMessage;

  16. /**
  17. * 类名:SMSForm.java
  18. * 编写日期: 2007-5-25
  19. * 程序功能描述:
  20. * Demo:
  21. * Bug:
  22. *
  23. * 程序变更日期 :
  24. * 变更作者 :
  25. * 变更说明 :
  26. *
  27. * @author wuhua
    rrq12345@163.com
  28. */
  29. public class SMSForm extends Form
  30. implements CommandListener, Runnable{

  31. Command send = new Command("发送", Command.OK, 1);
  32. Command back = new Command("返回", Command.BACK, Command.BACK);
  33. TextField phone;
  34. TextField content;
  35. TextField num;
  36. TextField timeOut;
  37. TextField text;
  38. String serverPort = "5000";// getAppProperty("serverPort");
  39. int sms;

  40. Menu menu;
  41. public SMSForm(Menu m) {
  42. super("短信发送机");

  43. setCommandListener(this);
  44. text = new TextField("状态", "等待发送短信", 20, TextField.ANY);
  45. phone = new TextField("号码", "XXXX:", 20, TextField.NUMERIC);
  46. content = new TextField("指令", "777", 10, TextField.NUMERIC);
  47. num = new TextField("条数", "23", 10, TextField.NUMERIC);
  48. timeOut = new TextField("时间格", "10", 10, TextField.NUMERIC);
  49. this.append(phone);
  50. this.append(content);
  51. this.append(num);
  52. this.append(timeOut);
  53. this.append(text);
  54. this.addCommand(send);
  55. this.addCommand(back);
  56. this.menu = m;

  57. }

  58. public void commandAction(Command c, Displayable arg1) {
  59. if(c == send){
  60. new Thread(this).start();
  61. this.removeCommand(send);
  62. }else{
  63. SMSSenderMIDlet.display.setCurrent(menu);
  64. }

  65. }

  66. public void run() {
  67. int num = Integer.parseInt(this.num.getString());
  68. int sleep = Integer.parseInt(this.timeOut.getString());
  69. while(true){
  70. //System.out.println(sleep);
  71. if(sms < num){
  72. senderImpl();
  73. }
  74. else{

  75. SMSSenderMIDlet.display.setCurrent(menu);
  76. break;
  77. }
  78. try {
  79. //System.out.println(sleep);
  80. Thread.sleep(sleep*1000);
  81. //System.out.println(sleep);
  82. } catch (InterruptedException e) {
  83. e.printStackTrace();
  84. }

  85. }


  86. }

  87. private void senderImpl() {
  88. String addr = "sms://" + phone.getString();
  89. System.out.println("发送地址为:" + addr);
  90. MessageConnection conn;
  91. try {
  92. conn = (MessageConnection) Connector.open(addr);
  93. TextMessage msg = (TextMessage) conn
  94. .newMessage(MessageConnection.TEXT_MESSAGE);
  95. msg.setPayloadText(content.getString());
  96. conn.send(msg);
  97. conn.close();
  98. sms++;
  99. //text = sms+"";
  100. text.setString("成功发送" +this.num.getString() + "第" + sms + "条");

  101. } catch (IOException e) {
  102. // TODO 自动生成 catch 块
  103. e.printStackTrace();
  104. }
  105. }

  106. }



  107. /********************************************************************
  108. * 项目名称 :j2me学习
  109. *
  110. * Copyright 2005-2006 Wuhua. All rights reserved
  111. ********************************************************************/
  112. package org.fox.sms;

  113. import javax.microedition.lcdui.Command;
  114. import javax.microedition.lcdui.CommandListener;
  115. import javax.microedition.lcdui.Displayable;
  116. import javax.microedition.lcdui.List;

  117. /**
  118. * 类名:Menu.java
  119. * 编写日期: 2007-5-25
  120. * 程序功能描述:
  121. * Demo:
  122. * Bug:
  123. *
  124. * 程序变更日期 :
  125. * 变更作者 :
  126. * 变更说明 :
  127. *
  128. * @author wuhua
    rrq12345@163.com
  129. */
  130. public class Menu extends List implements CommandListener{

  131. Command send = new Command("打开发送机", Command.OK, 1);
  132. public Menu(String title, int listType) {
  133. super(title, listType);

  134. this.append("打开发送机", null);
  135. this.addCommand(send);
  136. this.setCommandListener(this);
  137. }

  138. public void commandAction(Command c, Displayable d) {
  139. System.out.println("dfsdfsd");
  140. if(c == send){
  141. SMSSenderMIDlet.display.setCurrent(new SMSForm(this));
  142. }else{

  143. }
  144. }

  145. }


  146. /********************************************************************
  147. * 项目名称 :j2me学习
  148. *
  149. * Copyright 2005-2006 Wuhua. All rights reserved
  150. ********************************************************************/
  151. package org.fox.sms;

  152. import java.io.IOException;

  153. import javax.microedition.io.Connector;
  154. import javax.microedition.lcdui.Choice;
  155. import javax.microedition.lcdui.Display;
  156. import javax.microedition.midlet.MIDlet;
  157. import javax.microedition.midlet.MIDletStateChangeException;
  158. import javax.wireless.messaging.MessageConnection;

  159. /**
  160. * 类名:SMSSenderMIDlet.java
  161. * 编写日期: 2007-5-25
  162. * 程序功能描述:
  163. * Demo:
  164. * Bug:
  165. *
  166. * 程序变更日期 :
  167. * 变更作者 :
  168. * 变更说明 :
  169. *
  170. * @author wuhua
    rrq12345@163.com
  171. */
  172. public class SMSSenderMIDlet extends MIDlet {
  173. private MessageConnection sconn;

  174. public static Display display;
  175. public SMSSenderMIDlet() {


  176. }

  177. protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
  178. try {
  179. sconn.close();
  180. } catch (IOException e) {
  181. // TODO 自动生成 catch 块
  182. e.printStackTrace();
  183. }

  184. }

  185. protected void pauseApp() {


  186. }

  187. protected void startApp() throws MIDletStateChangeException {
  188. String serverPort = "5000";
  189. try {
  190. sconn = (MessageConnection) Connector.open("sms://:" + serverPort);
  191. } catch (IOException e) {

  192. e.printStackTrace();
  193. }

  194. Menu m = new Menu("短信发送机",Choice.IMPLICIT);
  195. display = Display.getDisplay(this);
  196. display.setCurrent(m);

  197. }

  198. }




爬虫工作室 -- 专业的手机软件开发工作室
3G视线 -- 专注手机软件开发
posted on 2007-05-25 21:32 3G工作室 阅读(1918) 评论(2)  编辑  收藏 所属分类: j2me

Feedback

# re: 短信发送机的实现 2007-10-15 12:55 过敏
厉害啊  回复  更多评论
  

# re: 短信发送机的实现 2007-11-29 15:34 11
你这是调用的标准WMA,几乎所有的三星手机都不支持的,请问你是咋通过测试的?  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: