在线短信平台.

BaseDao:

public class BaseDao {

    protected Connection con = null;
    protected PreparedStatement ps = null;
    protected ResultSet rs = null;

    private final static String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
       private final static String url="jdbc:sqlserver://192.168.16.19:1433;DatabaseName=BBS_Message";
       private static String user="sa";
       private static String password="";
       public void openConnection(){
           try {
            Class.forName(driver);
             if(con==null||con.isClosed()){
                 con=DriverManager.getConnection(url,user,password);
             }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
       }

    //获取连接
    protected void openConnection2(){
            try {
                Context ctx = new InitialContext();
                DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Message");
                con = ds.getConnection();
            } catch (NamingException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
    }    

    //更新新据库
    public int executeUpdata(String sql, List<Object> list){
        openConnection();
        try {
            ps = con.prepareStatement(sql);
            if(list == null)
                return ps.executeUpdate();
            int i = 1;
            for(Object obj:list){
                ps.setObject(i, obj);
                i++;
            }
            return ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            closeResource();
        }
        return 0;
    }

    //关闭流
    protected void closeResource(){
    try {
        if(rs != null)
            rs.close();
        if(ps != null)
            ps.close();
        if(con != null)
            con.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}

BBSMessageDao:

public interface BBSMessageDao {
    //查询短信息
    public List<BBSMessage>  getMessagesByPage(Map<String,Object> elements);
    //更新短信息
    public int executeUpdate(String operate, Map<String,Object> elements, Map<String,Object> conditions);
    //获取短信条数
    public int getMsgsCount(String username);
}

UserinfoDao:

public interface UserinfoDao {
    //查找用户
    public List<UserInfo> getUsers(Map<String,String> contitions);
    //添加或更新用户
    public int executeUpdate(String operate, UserInfo userinfo);
}

BBSMessageDao :

public class BBSMessageDaoImpl extends BaseDao implements BBSMessageDao {
    /*
     * 执行update操作
     * @param
     *     operate:执行插入、更新还是删除
     *     elements:需要插入或者更新的值集合,key对应column,value是插入或者更新的值
     *     conditions:update执行的条件集合,key对应column,value是条件值
     */
    public int executeUpdate(String operate, Map <String,Object>elements, Map <String,Object>conditions) {
        List<Object> list = null;
        String sql = null;
        String msgid= null ,username= null,title= null,msgcontent= null,state= null,sendto= null;
        Date msg_create_date=null;
        /*
         * 获取需要变更的值
         */
        if(elements!=null && elements.size()>0){
            msgid = (String)elements.get("msgid");
            username = (String)elements.get("username");
            title = (String)elements.get("title");
            msgcontent = (String)elements.get("msgcontent");
            state = (String)elements.get("state");
            sendto = (String)elements.get("sendto");
            msg_create_date = (Date)elements.get("msg_create_date");
        }

        /*
         * 更新操作
         */
        if(operate.equals("update")){
            /*
             * 拼写更新sql
             */
            sql = "update msg set ";
            /*
             * 获取条件元素
             */
            String ctn_msgid = (String)conditions.get("msgid");
            String ctn_username = (String)conditions.get("username");
            String ctn_title = (String)conditions.get("title");
            String ctn_msgcontent = (String)conditions.get("msgcontent");
            String ctn_state = (String)conditions.get("state");
            String ctn_sendto = (String)conditions.get("sendto");
            Date ctn_msg_create_date = (Date)conditions.get("msg_create_date");
            /*
             * 写出sql更新语句
             */
            String and = "";
            sql += msgid!=null ? and + " msgid=? ":"";
            and = msgid!=null ? " and ":"";
            sql += username!=null ? and + " username=? ":"";
            and = username!=null ? " and ":"";
            sql += title!=null ? and + " title=‘" + title + "‘ ":"";
            and = title!=null ? " and ":"";
            sql += msgcontent!=null ? and + " msgcontent=? ":"";
            and = msgcontent!=null ? " and ":"";
            sql += sendto!=null ? and + " sendto=? ":"";
            and = sendto!=null ? " and ":"";
            sql += state!=null ? and + " state=? ":"";
            and = state!=null ? " and ":"";
            sql += msg_create_date != null ? and + " msg_create_date=? ":"";
            /*
             * 写出sql条件语句
             */
            sql = sql + " where 1=1 ";
            sql += ctn_msgid != null ? " and msgid=? ":"";
            sql += ctn_username != null ? " and username=? ":"";
            sql += ctn_title != null ? " and title=‘" + title + "‘ ":"";
            sql += ctn_msgcontent != null ? " and msgcontent=? ":"";
            sql += ctn_sendto != null ? " and sendto=? ":"";
            sql += ctn_state != null ? " and state=? ":"";
            sql += ctn_msg_create_date != null ? " and msg_create_date=? ":"";

            list = new ArrayList<Object>();
            /*
             * 设置更新参数
             */
            if(msgid != null)
                list.add(msgid);
            if(username != null)
                list.add(username);
            if(title != null)
                list.add(title);
            if(msgcontent != null)
                list.add(msgcontent);
            if(sendto != null)
                list.add(sendto);
            if(state != null)
                list.add(state);
            if(msg_create_date != null)
                list.add(new Timestamp(msg_create_date.getTime()));
            /*
             * 设置条件参数
             */
            if(ctn_msgid != null)
                list.add(ctn_msgid);
            if(ctn_username != null)
                list.add(ctn_username);
            if(ctn_title != null)
                list.add(ctn_title);
            if(ctn_msgcontent != null)
                list.add(ctn_msgcontent);
            if(ctn_sendto != null)
                list.add(ctn_sendto);
            if(ctn_state != null)
                list.add(ctn_state);
            if(ctn_msg_create_date != null)
                list.add(new Timestamp(ctn_msg_create_date.getTime()));
        }
        /*
         * 添加操作
         */
        else if(operate.equals("insert")){
            sql = "insert into msg values(?,?,?,?,?,?,?)";
            list = new ArrayList<Object>();
            list.add(msgid);
            list.add(username);
            list.add(title);
            list.add(msgcontent);
            list.add(state);
            list.add(sendto);
            list.add(new Timestamp(msg_create_date.getTime()));
        }
        /*
         * 删除操作
         */
        else if(operate.equals("delete")){
            sql = "delete from msg where msgid = ?";
            list = new ArrayList<Object>();
            msgid = (String)conditions.get("msgid");
            list.add(msgid);
        }
        return executeUpdata(sql, list);
    }
    /*
     * 执行查询操作
     * @param
     *     elements:查询条件集合
     */
    public List<BBSMessage> getMessagesByPage(Map<String,Object> elements) {
        /*
         * 获取查询语句中的条件参数
         */
        Integer msgs_in_one_page = (Integer)elements.get("msgs_in_one_page");
        Integer page_no = (Integer)elements.get("page_no");
        String username = (String)elements.get("username");
        String msgid = (String)elements.get("msgid");
        String title = (String)elements.get("title");
        String msgcontent = (String)elements.get("msgcontent");
        String sendto = (String)elements.get("sendto");
        Integer state = (Integer)elements.get("state");
        Date msg_create_date = (Date)elements.get("msg_create_date");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        /*
         * 拼写sql
         */
        String sql = null;
        if(page_no == null){
            sql = "select * from msg where 1 = 1 ";
        }else{
            sql = "select * from" +
            "(select msg.*,rownum r from msg where 1=1 and " +
            username + title + msgcontent + sendto + state + msg_create_date +
            " and rownum <= " + msgs_in_one_page*page_no + ") " +
            "t where t.r >" + msgs_in_one_page*(page_no - 1);
        }
        /*
         * 编写条件语句
         */
        sql += msgid!=null ? " and msgid=‘" + msgid + "‘ ":"";
        sql += username != null?" and username=‘" + username + "‘ ":"";
        sql += title!=null ? " and title=‘" + title + "‘ ":"";
        sql += msgcontent!=null ? " and msgcontent=‘" + msgcontent + "‘ ":"";
        sql += sendto!=null ? " and sendto=‘" + sendto + "‘ ":"";
        sql += state!=null ? " and state=" + state + " ":"";
        sql += msg_create_date!=null ? " and msg_create_date=‘" + sdf.format(msg_create_date) + "‘ ":"";    

        /*
         * 返回结果
         */
        List <BBSMessage>list = null;
        openConnection();
        list = new ArrayList<BBSMessage>();
        try {
            ps = con.prepareStatement(sql);
            rs = ps.executeQuery();
            while(rs.next()){
                BBSMessage bms = new BBSMessage();
                bms.setMsgid(rs.getString("msgid"));
                bms.setTitle(rs.getString("title"));
                bms.setContent(rs.getString("msgcontent"));
                bms.setSendto(rs.getString("sendto"));
                bms.setState(rs.getInt("state"));
                bms.setDatetime(rs.getDate("msg_create_date"));
                bms.setUsername(rs.getString("username"));
                list.add(bms);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            closeResource();
        }
        return list;
    }

    public int getMsgsCount(String username) {
        String always_true = " where 1=1 ";
        int count = 0;
        if(username == null){
            username = "";
        }else{
            username = " and username = ‘" + username + "‘";
        }
        String sql = "select count(*) from msg " + always_true + username;

        openConnection();
        try {
            ps = con.prepareStatement(sql);
            rs = ps.executeQuery();
            while(rs.next())
                count = rs.getInt(1);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;
    }

}

UserinfoDaoImpl:

public class UserinfoDaoImpl extends BaseDao implements UserinfoDao {

    //添加或更新用户
    public int executeUpdate(String operate, UserInfo userinfo) {
        List<Object> list = null;
        String sql = null;
        if(operate.equals("update")){
            sql = "update msg_userinfo set password=? where username = ‘" + userinfo.getUsername() + "‘";
            list = new ArrayList<Object>();
            list.add(userinfo.getPassword());
        }else if(operate.equals("insert")){
            sql = "insert into msg_userinfo values(?,?,?)";
            list = new ArrayList<Object>();
            list.add(userinfo.getUsername());
            list.add(userinfo.getPassword());
            list.add(userinfo.getEmail());
        }
        return executeUpdata(sql, list);
    }

    //查找用户
    public List<UserInfo> getUsers(Map<String,String> contitions) {
        String username = (String) contitions.get("username");
        String pwd = (String) contitions.get("pwd");
        String operate = (String)contitions.get("operate");
        String sql = "select * from msg_userinfo where 1=1 ";
        if(operate != null && operate.equals("except")){
            sql += username != null ? " and username != ‘" + username + "‘":"";
        }else{
            sql += username != null ? " and username = ‘" + username + "‘":"";
        }
        sql += pwd != null ? " and password = ‘" + pwd + "‘":"";
        openConnection();
        List<UserInfo> users = new ArrayList<UserInfo>();
        try {
            ps = con.prepareStatement(sql);
            rs = ps.executeQuery();
            while(rs.next()){
                UserInfo uf = new UserInfo();
                uf.setUsername(rs.getString("username"));
                uf.setPassword(rs.getString("password"));
                uf.setEmail(rs.getString("email"));
                users.add(uf);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            closeResource();
        }
        return users;
    }
}

BBSMessage:

public class BBSMessage{

    private String msgid = null;//ID
    private String username = null;//发送方
    private String title = null;//标题
    private String content = null;//内容
    private int state = 0;//用户名
    private String sendto=null;//收件方
    private Date datetime = null;//发送时间
    public String getMsgid() {
        return msgid;
    }
    public void setMsgid(String msgid) {
        this.msgid = msgid;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public int getState() {
        return state;
    }
    public void setState(int state) {
        this.state = state;
    }
    public String getSendto() {
        return sendto;
    }
    public void setSendto(String sendto) {
        this.sendto = sendto;
    }
    public Date getDatetime() {
        return datetime;
    }
    public void setDatetime(Date datetime) {
        this.datetime = datetime;
    }
}

UserInfo:

public class UserInfo{

    private String username = null;//用户名
    private String password = null;//密码
    private String email = null;//电子邮箱

    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}

注册:

<script type="text/javascript">
$(function(){
    $(".btn-reg").bind("click", function(){
        window.location.href = "register.jsp";
    });
});

function check(){
    var username = document.getElementById("username");
    var password = document.getElementById("password");
    var error = document.getElementById("error");
    if(username.value == ""){
        error.innerHTML="<font color=\"red\">用户名不能为空!</font>";
        username.focus();
        return false;
    }else if(password.value == ""){
        error.innerHTML="<font color=\"red\">密码不能为空!</font>";
        password.focus();
        return false;
    }
    return true;
}
</script>
</head>
<body>
   <!--

    jsp_Writer(){
   } -->
   <%
     int i=5;
   %>
   <%
    i++;
   %>
   <%=i %>

<div id="loginTitle" class="png"></div>
<div id="loginForm" class="userForm png">
    <form method="post" name="loginform" action="UserServlet?action=login" onsubmit = "return check()">
        <dl>
            <div id="error">${error}</div>
            <dt>用户名:</dt>
            <dd><input type="text" name="username" /></dd>
            <dt>密 码:</dt>
            <dd><input type="password" name="password" /></dd>
        </dl>
        <div class="buttons">
            <input class="btn-login png" type="submit" name="submit" value=" " /><input class="btn-reg png" type="button" name="register" value=" " />
        </div>        

当前用户,退出:

<script type="text/javascript">
$(function(){
    $(".btn-reg").bind("click", function(){
        window.location.href = "register.jsp";
    });
});

function check(){
    var username = document.getElementById("username");
    var password = document.getElementById("password");
    var error = document.getElementById("error");
    if(username.value == ""){
        error.innerHTML="<font color=\"red\">用户名不能为空!</font>";
        username.focus();
        return false;
    }else if(password.value == ""){
        error.innerHTML="<font color=\"red\">密码不能为空!</font>";
        password.focus();
        return false;
    }
    return true;
}
</script>
</head>
<body>
   <!--

    jsp_Writer(){
   } -->
   <%
     int i=5;
   %>
   <%
    i++;
   %>
   <%=i %>

<div id="loginTitle" class="png"></div>
<div id="loginForm" class="userForm png">
    <form method="post" name="loginform" action="UserServlet?action=login" onsubmit = "return check()">
        <dl>
            <div id="error">${error}</div>
            <dt>用户名:</dt>
            <dd><input type="text" name="username" /></dd>
            <dt>密 码:</dt>
            <dd><input type="password" name="password" /></dd>
        </dl>
        <div class="buttons">
            <input class="btn-login png" type="submit" name="submit" value=" " /><input class="btn-reg png" type="button" name="register" value=" " />
        </div>        

当前用户发送:

 function check(){
            var title = document.getElementById("title");
            var content = document.getElementById("content");
            if(title.value == ""){
                alert("标题不能为空!");
                return false;
            }else if(content.value == ""){
                alert("内容不能为空!");
                return false;
            }
            return true;
    }
</script>

 <body>
 <form action="MsgServlet?action=send" method="post" onsubmit="return check()">
    <div id="main">
        <div class="mainbox">
            <div class="menu">
                <span>当前用户:<a href="MsgServlet?action=list">${sessionScope.loginuser}</a></span>
                <span><a href="UserServlet?action=findUsers">发短消息</a></span>
                <span><a href="UserServlet?action=logout">退出</a></span>
            </div>
            <div class="content">
                <div class="message">

                        <div class="tmenu">
                            <ul class="clearfix">
                                <li>
                                    发送给:<%String to=request.getParameter("sendto");request.setAttribute("sendto",to ); %>
                                    <select name="toUser">

                                           <c:forEach var="user" items="${users}">
                                           <c:choose>
                                             <c:when test="${user.username eq (sendto)}">
                                               <option selected="selected">${user.username}</option>
                                             </c:when>
                                             <c:when test="${user.username ne (sendto)}">
                                              <option>${user.username}</option>
                                             </c:when>
                                           </c:choose>

                                           </c:forEach>
                                       </select>
                                </li>
                                <li>标题:<input type="text" name="title" id="title"/></li>
                            </ul>
                        </div>
                        <div class="view">
                            <textarea name="content" id="content"></textarea>
                            <div class="send"><input type="submit" name="submit" value=" " /></div>
                        </div>

                </div>
            </div>
        </div>
    </div>
</form>
</body>
</html>
时间: 2024-10-08 09:47:57

在线短信平台.的相关文章

可用的国内免费虚拟手机号平台 在线接收短信 在线短信接收

关键词 虚拟手机号短信接码平台 在线接收短信 在线短信接收 在线接收短信 | 免费接码平台 https://www.pdflibr.com/ https://www.becmd.com/ http://z-sms.com/ 原文地址:https://www.cnblogs.com/kaibindirver/p/12287926.html

Java通过SMS短信平台实现发短信功能

在项目中使用过发短信的功能,但那个由于公司内部的限制很麻烦,今天在网上找到一个简单的,闲来无事就把它记录如下: 本程序是通过使用中国网建提供的SMS短信平台实现的(该平台目前为注册用户提供5条免费短信,3条免费彩信,这足够用于我们测试用了.在使用前需要注册,注册地址为http://sms.webchinese.cn/reg.shtml),下面是程序源码: /** * @Author dengsilinming * @Date 2012-9-18 * */ package com.dengsili

【原创】起步互联网公司内部短信平台杂谈

前言 陆陆续续间间隔隔开发公司短信平台接口已经一段时间了,在年末的时候找个空闲把觉得实际可行的东西记录下来. 想了想,感觉这东西应该没啥好说的,但是又觉得哪里需要记一记,以后换个工作环境,还来一发呢,不就可以避免不必要的坑. 毕竟在实现短信接口的过程中,看似简单,但是有许多需要注意的地方和可以一步到位的地方可以记录下来,请大牛们分享探讨不足指正. 来吧,整理整理思绪. 开发背景 由于公司的APP端.微信公众号端.各种后台端和报警机制端等等的一系列应用和系统都需要用到一个基础功能:发短信.所以一开

Laravel框架接入短信平台进行用户注册短信验证

今天刚接触了一个短信接口平台,云通讯第三方短信提供服务商.http://www.yuntongxun.com/ 然后介绍一下怎么使用该短信平台来接入到自己的项目中. 首先你的去注册一个账号,然后根据提供的一些信息,作为接口进行接入. 将account sid.auth token.Rest url.等信息写入代码中.稍后会由示例代码上传的. 然后就是实例化SMS类,调用里面的方法就好了,很多方法都已经封装好了,直接用就好了. public function sendSMS(Request $re

狠怼酒店的在线短租平台们只“秀外”不“慧中”?

现在,最火的词恐怕非共享经济莫属了,先是共享单车,再是共享充电宝,毋庸置疑,共享经济正在引领21世纪的经济模式潮流.近年来,在线短租可谓风生水起,前有共享经济的光环,后有国务院政策的支持和各大资本的力挺.据易观发布的<2016中国在线短租C2C市场专题分析>报告显示,2016年10月在线短租活跃用户占在线酒店预订活跃用户超过1/5,已经成为旅游住宿的主要形式之一.作为共享经济的一员,在线短租不甘示弱,迎合了年轻用户消费需求的它正在改变人们的出游居住习惯,即民宿取代酒店. 政策.资本与消费升级助

短信平台收集及选择

短信平台选择原则: 1.最好选择三网合一,发送的号码统一一个. 2.不建议使用大充值的后用,一般选择小预付费使用,按需充值 3.要保障的选择大厂或中厂 大厂: 1.阿里大于 2.网易云信 中厂: 1.聚合数据 2.亿美软通 3.美联软通 4.华兴软通 5.SendCloud 小厂(不推荐,多数是大额充值,有延迟等,不是运营商不行,而是本身系统就有些问题等): 1.欣易辰 2.瑞信通 3.253 4.华兴软通 5.互亿无线 6.九天企信王 7.乐信 8.北斗通 9.第一信息 10.企信通 11.秒

C#调用短信接口(通过简单的工厂模式整合多个短信平台)

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Web; namespace DUANXIN { public class SendSmsFactory { public static SendSmsBase CreateFactory(string className) { S

短信平台营销 甩其他营销方式好几条街

营销之于企业的重大意义不用多说,如果一个企业的营销做的不到位,这个企业很有可能就会在这个大浪淘沙的社会中被淘汰.那么选择一个什么样的宣传平台才能以小博大,甩同行好几条街呢?短信平台从发展至今,在经历各种竞争角逐后,依然活跃在企业中间,给企业带来丰厚的经济收益,成为企业推销产品的利器,可见短信群发平台营销却有不同其他营销方式之处. 在这个手机横行的世道,利用人手一部甚至好几部的手机做营销,你认为会有错吗?短信平台是以传送手机短信为目的的一个宣传工具,企业有任何宣传计划和客服需要,都可以通过短信平台

2、架构设计 --短信平台开发

二.架构设计 1.网络架构设计 由于单位网络问题,平常使用的内网(管理网)不能直接连接互联网,需要由外联网中介.同时由于安全策略的缘故,外联网与管理网是单向访问(外联网不能访问管理网,管理网可以访问外联网),所以数据库只能放在外联网上. 网站架构图如下 2.下行短信发送 这个流程画时序图比流程图更直观一点. 首先第三方系统调用短信平台的WebService接口,将下行短信数据存入数据库. 然后由外联网的Windows服务循环访问数据库,若有数据则调用移动云MAS组件,将短信信息发送到云MAS平台