[转帖]J2EE--关于用JAVA开发短信方面的知识_Tomcat, WebLogic及J2EE讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Tomcat, WebLogic及J2EE讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3254 | 回复: 0   主题: [转帖]J2EE--关于用JAVA开发短信方面的知识        下一篇 
liulin_2
注册用户
等级:少校
经验:1143
发帖:85
精华:5
注册:2012-12-10
状态:离线
发送短消息息给liulin_2 加好友    发送短消息息给liulin_2 发消息
发表于: IP:您无权察看 2012-12-11 11:32:23 | [全部帖] [楼主帖] 楼主

J2EE--关于用JAVA开发短信方面的知识



现在流行的网络业务莫过于短信了.网易新浪等都因此而盈利,股价上涨.我凭自己的经验和公司支持,也就

乘着东风来研究一下了!

首先,你要选择一台移动或者联通的短信服务器做你们的发送短信接口.这是最关键的一步,也是最底层的,

当然这是需要much money的,呵呵.没办法!现实了点....

然后你就是在连接接口的服务器做技术了.用JAVA 的 SOCKET 来监听客户端的SOCKET,当然这是需要一定的

难度,和普通是有很多的区别,例如每秒钟可以同时接受3000条SOCKET... ...,要进行客户端的认证.要进行数据

流转输的加密... ...

最后就是来处理客户端的发送SOCKET了,其实他们传输都是字节Byte...

public class Client
{
      //构造函数
      public Client()
      {
            connectStatus = false;
            loginStatus = false;
            default_ip = "";
            default_port = 0;
            default_user = "";
            default_password = "";
            connection = null;
            input = null;
            out = null;
            binput = null;
      }
      //连接函数
      public boolean connect(String ip, int port)
      {
            boolean result = false;
            if(ip == null || ip.indexOf(".")
            //登录函数
            public int login(String userName, String password)
            {
                  int loginRes = -1;
                  if(!connectStatus)
                  return 1;
                  if(userName == null || userName.trim().equals(""))
                  return 24;
                  byte loginData[] = new byte[43];
                  setIntData(43, loginData, 0);
                  setIntData(1, loginData, 4);
                  setIntData(1, loginData, 8);
                  userName.getBytes(0, userName.length(), loginData, 12);
                  password.getBytes(0, password.length(), loginData, 22);
                  loginData[38] = 1;
                  setTime((new Date()).getTime() / (long)1000, loginData, 39);
                  try
                  {
                        out.write(loginData);
                        out.flush();
                        byte rec[] = new byte[30];
                        char ret = '\0';
                        int i = 0;
                        do
                        {
                              if(i >= 400)
                              break;
                              if(binput.available() > 0)
                              {
                                    input.read(rec, 0, 30);
                                    ret = (char)rec[12];
                                    break;
                              }
                              Thread.sleep(50L);
                              i++;
                        } while(true);
                        if(ret == 'T')
                        {
                              loginStatus = true;
                              default_user = userName;
                              default_password = password;
                              int k = 0;
                              return k;
                        }
                        loginRes = 1;
                  }
                  catch(Exception e)
                  {
                        int j = 1;
                        return j;
                  }
                  return loginRes;
            }
            //发送函数
            public int submit(String servicer_id, int msg_type, int status_report, String src_addr, String
            dest_addr, String schedule, String expire,
            int msg_fmt, byte msg_content[], String fee_type, String fee_code, String fee_mobile,
            String fee_by, int pid)
            {
                  int subRes = -1;
                  if(!connectStatus || !loginStatus)
                  return 1;
                  byte submitData[] = new byte[264];
                  setIntData(264, submitData, 0);
                  setIntData(4, submitData, 4);
                  setIntData(1, submitData, 8);
                  servicer_id.getBytes(0, servicer_id.length(), submitData, 12);
                  submitData[22] = (byte)msg_type;
                  submitData[23] = (byte)status_report;
                  if(src_addr == null || src_addr.trim().length() 1 && !setTime(schedule, submitData,
                  66))
                  return 16;
                  if(expire != null && expire.trim().length() > 1 && !setTime(expire, submitData, 70))
                  return 17;
                  submitData[74] = (byte)msg_fmt;
                  submitData[75] = (byte)msg_content.length;
                  System.arraycopy(msg_content, 0, submitData, 76, msg_content.length);
                  fee_type.getBytes(0, fee_type.length(), submitData, 236);
                  fee_code.getBytes(0, fee_code.length(), submitData, 244);
                  if(fee_mobile != null && fee_mobile.trim().length() > 11)
                  fee_mobile = fee_mobile.substring(2);
                  fee_mobile.getBytes(0, fee_mobile.length(), submitData, 250);
                  fee_by.getBytes(0, 2, submitData, 261);
                  if(pid 256)
                  pid = 0;
                  submitData[263] = (byte)pid;
                  boolean reSend = false;
                  try
                  {
                        out.write(submitData);
                        out.flush();
                  }
                  catch(Exception e)
                  {
                        reSend = true;
                  }
                  if(reSend)
                  {
                        int sendTimes = 0;
                        do
                        {
                              if(sendTimes >= 2)
                              break;
                              try
                              {
                                    connect(default_ip, default_port);
                                    login(default_user, default_password);
                                    out.write(submitData);
                                    out.flush();
                                    reSend = false;
                                    break;
                              }
                              catch(Exception exception)
                              {
                                    sendTimes++;
                              }
                        } while(true);
                  }
                  if(reSend)
                  {
                        connectStatus = false;
                        loginStatus = false;
                        return 1;
                  }
                  try
                  {
                        byte sub[] = new byte[17];
                        char sRet = '\0';
                        int i = 0;
                        do
                        {
                              if(i >= 1500)
                              break;
                              if(binput.available() > 0)
                              {
                                    input.read(sub, 0, 17);
                                    sRet = (char)sub[16];
                                    break;
                              }
                              Thread.sleep(10L);
                              i++;
                        } while(true);
                        if(sRet == 'T')
                        subRes = 0;
                        else
                        subRes = 11;
                  }
                  catch(Exception e)
                  {
                        subRes = 1;
                  }
                  return subRes;
            }




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论