文档章节

微信公众平台深度开发JAVA版第一季 24.微信猜数字活动6

blueheart
 blueheart
发布于 2017/05/23 08:54
字数 3411
阅读 3
收藏 0
select * from huo t where date_format(t.createTime,'%Y%m%d') = '20150206';
select count(*) count_,t.shuzi from huo t where date_format(t.createTime,'%Y%m%d') = '20170523' group by t.shuzi order by count_,shuzi
select count(*) count_,t.shuzi  from huo t group by t.shuzi order by count_,shuzi;

搞了那么久,原来是网络不通的问题.

搞了半天原来是ngrok服务器断了

ngrok服务器停了或者是ngrok版本太低了.

注册花生壳

http://domain.oray.com/?ici=console_passport_register&icn=domain_home

http://getfrp.yzxx-soft.com/

https://github.com/fatedier/frp/releases

package net.wxinterface;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.MessageDigest;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.server.HouServer;
import wx.event.Subscribe_Unsubscribe;
import wx.in.In;
import wx.in.In_Text;
import wx.out.Out_Text;
import wx.util.Util;
public class WX_Interface extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public WX_Interface() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//΢�ż���ǩ��,signature����˿�������д��tocken����������е�timestamp����nonce����
		String signature = request.getParameter("signature");
		//ʱ���
		String timestamp = request.getParameter("timestamp");
		//����� 
		String nonce = request.getParameter("nonce");
		
		String echostr = request.getParameter("echostr");
		
		String tocken = "test";
		try{
			if(null != signature){
			String[] ArrTmp = {tocken,timestamp,nonce};	
			Arrays.sort(ArrTmp);
			StringBuffer sb = new StringBuffer();
			for(int i=0;i<ArrTmp.length;i++){
				sb.append(ArrTmp[i]);
			}
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			byte[] bytes = md.digest(new String(sb).getBytes());
			StringBuffer buf = new StringBuffer();
			for(int i=0;i<bytes.length;i++){
				if(((int)bytes[i] & 0xff)<0x10){
					buf.append("0");
				}
				buf.append(Long.toString((int) bytes[i] & 0xff,16));
				
			}
			if(signature.equals(buf.toString())){
				response.getOutputStream().println(echostr);
			}
		}
	}catch(Exception e){
			e.printStackTrace();
		}
		
		System.out.println("test0");

		
		System.out.println("doGet");
		System.out.println("signature     "+signature);
		System.out.println("timstamp      "+timestamp);
		System.out.println("nonce         "+nonce);
		System.out.println("echostr         "+echostr);
		
		
		System.out.println("doGet");
	
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		String requestStr = Util.getStringFromRequest(request);
		In in = new In(requestStr);
		System.out.println(in);
		System.out.println(requestStr);
		System.out.println("北风网");
		/**
		 * 关注微信号时的欢迎信息
		 * 欢迎你关注本微信号
		 */
		if("event".equals(in.getMsgType())){//如果接收的消息是事件类型的话
			Subscribe_Unsubscribe subscribe_Unsubscribe = new Subscribe_Unsubscribe(requestStr);
		if("subscribe".equals(subscribe_Unsubscribe.getEvent())){
			//Out_Text out_Text = new Out_Text(in);
			Out_Text out_Text = new Out_Text(subscribe_Unsubscribe);
			out_Text.setContent("欢迎你关注本微信号。本游戏说明");
			out.print(out_Text.getStr());
		}
		//判断是text类型
		}else if("text".equals(in.getMsgType())){					
					//得到文本类型的请求对象.
					In_Text in_Text = new In_Text(requestStr);
					System.out.println(in_Text);
					//得到文本类型的被动响应对象.
					//Out_Text out_Text = new Out_Text(in);
					Out_Text out_Text = new Out_Text(in_Text);
					//out_Text.setContent("这是您选择的数字"+in_Text.getContent());
					/*------日期判断------------start------------------------------*/
					Date date   =  new Date();
					System.out.println(date);
					SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
					//SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

					
						try {
							//2017年05月22日00时00分00秒
							Date date1 = simpleDateFormat.parse("20170522000000");
							//2017年05月23日00时00分00秒
							Date date2 = simpleDateFormat.parse("20170526000000");
						
						//判断是否是2017年05月22日
						/*
						 * 如果是在这个区间,执行后续程序
						 * 
						 * 如果不是,就给出提示,返回
						 * 
						 * 
						
						 * 
						 * 活动还没开始
						 * 
						 */ 
						 
						if(date.before(date1)){
							out_Text.setContent("活动还没开始");
							out.println(out_Text.getStr());
							return;
						}
						else if(date.after(date2)){
							out_Text.setContent("活动已经结束了");
							out.println(out_Text.getStr());
							return;
						}}catch (ParseException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
							return;
						}
					/*-------日期判断------------------end------------------*/
					/*--------------查询中奖名单--------start-------*/
					if("?".equals(in_Text.getContent())){

				/*	StringBuffer strb = new StringBuffer();
					strb.append("select");
					strb.append("count(*) count_,t.shuzi");
					strb.append("from huo t");
					strb.append("group by t.shuzi");
					strb.append("order by count_,shuzi");*/
				    try {
						String str = HouServer.getRs();
						out_Text.setContent(str);
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						out_Text.setContent("现在用户很踊跃,服务器太累了,您没有参与成功,请继续参与.");
						e.printStackTrace();
					}
					out.println(out_Text.getStr());
					return;
				}
					/*--------------查询中奖名单--------end-------*/
					
					
					/*--------------这是验证部分-------start-------------*/
					/*
					 * 需要验证的有:
					 * 必须是数字
					 * 必须在指定的范围内
					 */
					//判断,如果不是数字,抛出异常
					//提示手机用户"这不是数字"
					try {
						Integer.parseInt(in_Text.getContent());
					} catch (NumberFormatException e) {
						// TODO Auto-generated catch block
						//e.printStackTrace();
						out_Text.setContent("这个不是数字");
						System.out.println(out_Text.getStr());
						out.println(out_Text.getStr());
						return;
					}
					//判断,是否小于1000			
					//提示手机用户"这个数字太大了,应该小于1000"
					if(1000<Integer.parseInt(in_Text.getContent())){
						out_Text.setContent("这个数字太大了,应该小于1000");
						System.out.println(out_Text.getStr());
						out.println(out_Text.getStr());
						return;
					}
					/*--------------这是验证部分-------end-------------*/
					/*-------------验证结束--------start---------------------*/
					//记录到数据库
					try {//在Service层里面,这就需要处理异常了,要是这块真有数据库的异常比如说掉网或者是
					//说数据库怎么样怎么着了,要给用户一个提示,不能再随随便便往外抛出异常了,要友好地提示
					HouServer.saveJiLu(in.getFromUserName(),in_Text.getContent());
			}catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				//当SQL执行异常时,给用户提示
				out_Text.setContent("现在用户很踊跃,服务器太累了,您没有参与成功,请继续参与.");
				out.println(out_Text.getStr());
				return;
			}
			/*----------------------记录到数据库-----------end------------------*/		
			
			/*----------------------查询数据库,得到这个数字在数据库中的个数-------start--------------------------------------------*/
					String str = "";
					try {
						str = HouServer.getCountByShuZi(in_Text.getContent());
						out_Text.setContent("成功,"+in_Text.getContent()+"已经有"+str+"次被猜中了。");
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						out_Text.setContent("现在用户很踊跃,服务器太累了,您没有参与成功,请继续参与.");
						e.printStackTrace();
					}
					//out_Text.setContent("成功,"+in_Text.getContent()+"已经有"+str+"次被猜中了。");
					System.out.println(out_Text.getStr());
			out.print(out_Text.getStr());
			/*-----------查询数据库-----------------------end--------------------------------*/
					}else{
			Out_Text out_Text = new Out_Text(in);
			out_Text.setContent("请选择一个数字");
			out.print(out_Text.getStr());
			
		}
		
		out.flush();
		out.close();
		System.out.println("ok");
	}

}
package net.server;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.db.DBUtil;

public class HouServer {
	/**
	 * 保存记录
	 * @param openid
	 * @param shuzi
	 * @throws SQLException 
	 */
    public static void saveJiLu(String openid,String shuzi) throws SQLException{//Server层的异常推荐使用向外抛出异常的方式.
    	//因为你要通知外面这个Server执行的有错误.
    	Connection conn = DBUtil.getConn();
    	Statement stmt = conn.createStatement();
    	//conn.prepareStatement(sql);//PrepareStatement是预编译/预处理,Statement就不行了
    	//Statement是PrepareSatement的父类/父接口.
    	String sql = "insert into huo (openid,shuzi) values ('"+openid+"','"+shuzi+"');";
    	//String sql = "insert into huo (openid,shuzi) values ('"+openid+"','"+shuzi+"')";
    	stmt.executeUpdate(sql);
    	if(null!=stmt){
    		stmt.close();
    	}
    	//关Connection涉及到一个数据源的问题.数据源/连接池,什么时候是真关闭(物理关闭),什么时候是逻辑关闭
    	//有人会用自己开发的数据源对Connection进行管理.关于数据库操作这一部分求职的时候会很容易被问到.
    	if(null!=conn){
    		conn.close();
    	}
    }
    /**
     * 根据数字查询数据库.得到这个数字在数据库中的个数。
     * @param shuZi
     * @return
     * @throws SQLException
     */
    public static String getCountByShuZi(String shuZi) throws SQLException{
    	Date date = new Date();
    	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
    	String str = "";
    	/*得到Connection*/
    	Connection conn = DBUtil.getConn();
    	/*得到Statement*/
    	Statement stmt = conn.createStatement();
    	
    	String sql = "select  count(*) count_ from huo t where t.shuzi='"+shuZi+"' and date_format(t.createTime,'%Y%m%d')='"+simpleDateFormat.format(date)+"'";
		//依赖注入的事,可能是拼接一个字符串
    	System.out.println(sql);
    	/*得到ResultSet*/
    	ResultSet rs = stmt.executeQuery(sql);
    	if(rs.next()){
    		str = rs.getString("count_");
    	}
    	
    	
    	/*关闭rs*/
    	if(null != rs){
    		rs.close();
    	}
    	/*关闭stmt*/
    	if(null != stmt){
    		stmt.close();
    	}
    	/*关闭conn*/
    	if(null != conn){
    		conn.close();
    	}
    	return str;
    	
    }
    public static String getRs() throws SQLException{

    	String str = "";
    	Date date = new Date();
    	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
    	/*
    	 * sql语句
    	 * 
    	 * 先按照根据结果分组
    	 * 按照选中的次数排序
    	 * 按照数字的大小排序
    	 * */
		StringBuffer strb = new StringBuffer();
		strb.append("select ");
		strb.append("count(*) count_,t.shuzi");
		strb.append(" from huo t");
		strb.append(" where date_format(t.createTime,'%Y%m%d') = '"+simpleDateFormat.format(date)+"'");
		strb.append(" group by t.shuzi");
		strb.append(" order by count_,shuzi");
		//String sql = "select count(*) count_,t.shuzi from huo t where date_format(t.createTime,'%Y%m%d') = ''"+simpleDateFormat.format(date)+"'' group by t.shuzi order by count_,shuzi";
		System.out.println(strb);
		//得到Connection
		Connection conn = DBUtil.getConn();
		//得到Statement
		Statement stmt = conn.createStatement();
		//得到结果集
		ResultSet rs = stmt.executeQuery(strb.toString());
		//ResultSet rs = stmt.executeQuery(sql);
		
		if(rs.next()){
			str = rs.getString("shuzi")+" 是最接近0的,  一共被选择"+rs.getString("count_")+"次";
		}
		
		/*关闭rs*/
		if(null!=rs){
			rs.close();
		}
		/*关闭stmt*/
		if(null!=stmt){
			stmt.close();
		}
		/*关闭conn*/
		if(null!=conn){
			conn.close();
		}
		return str;
    }
}
package wx.out;

import java.util.Date;

import wx.in.In;

public class Out_Video {
	private String ToUserName = null;//	是	接收方帐号(收到的OpenID)
	private String FromUserName =null;//	是	开发者微信号
	private String CreateTime = null;//	是	消息创建时间 (整型)
	private String MsgType =null;//	是	video
	private String MediaId	 = null;//是	通过素材管理中的接口上传多媒体文件,得到的id
	private String Title =null;//	否	视频消息的标题
	private String Description =null;//	否	视频消息的描述
	StringBuffer strb = new StringBuffer();
	StringBuffer strb_ = new StringBuffer();
	
	public Out_Video(In in) {
		super();
		Date date = new Date();
		strb.append("<ToUserName><![CDATA["+in.getFromUserName()+"]]></ToUserName>");
		strb.append("<FromUserName><![CDATA["+in.getToUserName()+"]]></FromUserName>");
		//strb.append("<CreateTime>"+date.getTime()+"</CreateTime>");
		strb.append("<CreateTime>"+in.getCreateTime()+"</CreateTime>");
		//strb.append("<MsgType><![CDATA[video]]></MsgType>");
		strb.append("<MsgType><![CDATA["+in.getMsgType()+"]]></MsgType>");
	}
	//public String getStr(String str){
	public String getStr(){

        strb_.append("<xml>");
		strb_.append(strb);
		strb_.append("<Video>");
		strb_.append("<MediaId><![CDATA["+this.getMediaId()+"]]></MediaId>");
		strb_.append("<Title><![CDATA["+this.getTitle()+"]]></Title>");
		strb_.append("<Description><![CDATA["+this.getDescription()+"]]></Description>");
		strb_.append("</Video>");
		strb_.append("</xml>");
		return strb_.toString();

		
	}
	public String getToUserName() {
		return ToUserName;
	}
	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}
	public String getFromUserName() {
		return FromUserName;
	}
	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}
	public String getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(String createTime) {
		CreateTime = createTime;
	}
	public String getMsgType() {
		return MsgType;
	}
	public void setMsgType(String msgType) {
		MsgType = msgType;
	}
	public String getMediaId() {
		return MediaId;
	}
	public void setMediaId(String mediaId) {
		MediaId = mediaId;
	}
	public String getTitle() {
		return Title;
	}
	public void setTitle(String title) {
		Title = title;
	}
	public String getDescription() {
		return Description;
	}
	public void setDescription(String description) {
		Description = description;
	}
	@Override
	public String toString() {
		/*return "Out_Video [ToUserName=" + ToUserName + ", FromUserName="
				+ FromUserName + ", CreateTime=" + CreateTime + ", MsgType="
				+ MsgType + ", MediaId=" + MediaId + ", Title=" + Title
				+ ", Description=" + Description + ", strb=" + strb
				+ ", strb_=" + strb_ + "]";*/
		return "Out_Video ["+this.getStr()+"]";
	}

}
package wx.in;

public class In_Video extends In{
/*	private String ToUserName =null;//	开发者微信号
	private String FromUserName =null;//	发送方帐号(一个OpenID)
	private String CreateTime =null;//	消息创建时间 (整型)
	private String MsgType =null;//	视频为video
*/	private String MediaId =null;;//	视频消息媒体id,可以调用多媒体文件下载接口拉取数据。
	private String ThumbMediaId	=null;//视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。
	private String MsgId	=null;//消息id,64位整型
	
	
	
	public In_Video() {
		super();
	}
	public In_Video(String requestStr) {
		super();
		this.setToUserName(In_Util.getStrByXML(requestStr,"ToUserName"));
		this.setFromUserName(In_Util.getStrByXML(requestStr,"FromUserName"));
		this.setCreateTime(In_Util.getStrByXML(requestStr,"CreateTime"));
		this.setMsgType(In_Util.getStrByXML(requestStr,"MsgType"));
		this.setMediaId(In_Util.getStrByXML(requestStr,"MediaId"));
		this.setThumbMediaId(In_Util.getStrByXML(requestStr,"ThumbMediaId"));
		this.setMsgId(In_Util.getStrByXML(requestStr,"MsgId"));
	}
	/*public String getToUserName() {
		return ToUserName;
	}
	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}
	public String getFromUserName() {
		return FromUserName;
	}
	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}
	public String getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(String createTime) {
		CreateTime = createTime;
	}
	public String getMsgType() {
		return MsgType;
	}
	public void setMsgType(String msgType) {
		MsgType = msgType;
	}*/
	public String getMediaId() {
		return MediaId;
	}
	public void setMediaId(String mediaId) {
		MediaId = mediaId;
	}
	public String getThumbMediaId() {
		return ThumbMediaId;
	}
	public void setThumbMediaId(String thumbMediaId) {
		ThumbMediaId = thumbMediaId;
	}
	public String getMsgId() {
		return MsgId;
	}
	public void setMsgId(String msgId) {
		MsgId = msgId;
	}
	@Override
	public String toString() {
		return "In_Video [MediaId=" + MediaId + ", ThumbMediaId="
				+ ThumbMediaId + ", MsgId=" + MsgId + "]";
	}
	
}
package net.wxinterface;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.MessageDigest;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.server.HouServer;
import wx.event.Subscribe_Unsubscribe;
import wx.in.In;
import wx.in.In_Text;
import wx.in.In_Video;
import wx.out.Out_Text;
import wx.out.Out_Video;
import wx.util.Util;
public class WX_Interface extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public WX_Interface() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//΢�ż���ǩ��,signature����˿�������д��tocken����������е�timestamp����nonce����
		String signature = request.getParameter("signature");
		//ʱ���
		String timestamp = request.getParameter("timestamp");
		//����� 
		String nonce = request.getParameter("nonce");
		
		String echostr = request.getParameter("echostr");
		
		String tocken = "test";
		try{
			if(null != signature){
			String[] ArrTmp = {tocken,timestamp,nonce};	
			Arrays.sort(ArrTmp);
			StringBuffer sb = new StringBuffer();
			for(int i=0;i<ArrTmp.length;i++){
				sb.append(ArrTmp[i]);
			}
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			byte[] bytes = md.digest(new String(sb).getBytes());
			StringBuffer buf = new StringBuffer();
			for(int i=0;i<bytes.length;i++){
				if(((int)bytes[i] & 0xff)<0x10){
					buf.append("0");
				}
				buf.append(Long.toString((int) bytes[i] & 0xff,16));
				
			}
			if(signature.equals(buf.toString())){
				response.getOutputStream().println(echostr);
			}
		}
	}catch(Exception e){
			e.printStackTrace();
		}
		
		System.out.println("test0");

		
		System.out.println("doGet");
		System.out.println("signature     "+signature);
		System.out.println("timstamp      "+timestamp);
		System.out.println("nonce         "+nonce);
		System.out.println("echostr         "+echostr);
		
		
		System.out.println("doGet");
	
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		String requestStr = Util.getStringFromRequest(request);
		In in = new In(requestStr);
		System.out.println(in);
		System.out.println(requestStr);
		System.out.println("北风网");
		/**
		 * 关注微信号时的欢迎信息
		 * 欢迎你关注本微信号
		 */
		if("event".equals(in.getMsgType())){//如果接收的消息是事件类型的话
			Subscribe_Unsubscribe subscribe_Unsubscribe = new Subscribe_Unsubscribe(requestStr);
		if("subscribe".equals(subscribe_Unsubscribe.getEvent())){
			//Out_Text out_Text = new Out_Text(in);
			Out_Text out_Text = new Out_Text(subscribe_Unsubscribe);
			out_Text.setContent("欢迎你关注本微信号。本游戏说明");
			out.print(out_Text.getStr());
		}
		//判断是text类型
		}else if("text".equals(in.getMsgType())){					
					//得到文本类型的请求对象.
					In_Text in_Text = new In_Text(requestStr);
					System.out.println(in_Text);
					//得到文本类型的被动响应对象.
					//Out_Text out_Text = new Out_Text(in);
					Out_Text out_Text = new Out_Text(in_Text);
					//out_Text.setContent("这是您选择的数字"+in_Text.getContent());
					/*------日期判断------------start------------------------------*/
					Date date   =  new Date();
					System.out.println(date);
					SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
					//SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

					
						try {
							//2017年05月22日00时00分00秒
							Date date1 = simpleDateFormat.parse("20170522000000");
							//2017年05月23日00时00分00秒
							Date date2 = simpleDateFormat.parse("20170526000000");
						
						//判断是否是2017年05月22日
						/*
						 * 如果是在这个区间,执行后续程序
						 * 
						 * 如果不是,就给出提示,返回
						 * 
						 * 
						
						 * 
						 * 活动还没开始
						 * 
						 */ 
						 
						if(date.before(date1)){
							out_Text.setContent("活动还没开始");
							out.println(out_Text.getStr());
							return;
						}
						else if(date.after(date2)){
							out_Text.setContent("活动已经结束了");
							out.println(out_Text.getStr());
							return;
						}}catch (ParseException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
							return;
						}
					/*-------日期判断------------------end------------------*/
					/*--------------查询中奖名单--------start-------*/
					if("?".equals(in_Text.getContent())){

				/*	StringBuffer strb = new StringBuffer();
					strb.append("select");
					strb.append("count(*) count_,t.shuzi");
					strb.append("from huo t");
					strb.append("group by t.shuzi");
					strb.append("order by count_,shuzi");*/
				    try {
						String str = HouServer.getRs();
						out_Text.setContent(str);
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						out_Text.setContent("现在用户很踊跃,服务器太累了,您没有参与成功,请继续参与.");
						e.printStackTrace();
					}
					out.println(out_Text.getStr());
					return;
				}
					/*--------------查询中奖名单--------end-------*/
					
					
					/*--------------这是验证部分-------start-------------*/
					/*
					 * 需要验证的有:
					 * 必须是数字
					 * 必须在指定的范围内
					 */
					//判断,如果不是数字,抛出异常
					//提示手机用户"这不是数字"
					try {
						Integer.parseInt(in_Text.getContent());
					} catch (NumberFormatException e) {
						// TODO Auto-generated catch block
						//e.printStackTrace();
						out_Text.setContent("这个不是数字");
						System.out.println(out_Text.getStr());
						out.println(out_Text.getStr());
						return;
					}
					//判断,是否小于1000			
					//提示手机用户"这个数字太大了,应该小于1000"
					if(1000<Integer.parseInt(in_Text.getContent())){
						out_Text.setContent("这个数字太大了,应该小于1000");
						System.out.println(out_Text.getStr());
						out.println(out_Text.getStr());
						return;
					}
					/*--------------这是验证部分-------end-------------*/
					/*-------------验证结束--------start---------------------*/
					//记录到数据库
					try {//在Service层里面,这就需要处理异常了,要是这块真有数据库的异常比如说掉网或者是
					//说数据库怎么样怎么着了,要给用户一个提示,不能再随随便便往外抛出异常了,要友好地提示
					HouServer.saveJiLu(in.getFromUserName(),in_Text.getContent());
			}catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				//当SQL执行异常时,给用户提示
				out_Text.setContent("现在用户很踊跃,服务器太累了,您没有参与成功,请继续参与.");
				out.println(out_Text.getStr());
				return;
			}
			/*----------------------记录到数据库-----------end------------------*/		
			
			/*----------------------查询数据库,得到这个数字在数据库中的个数-------start--------------------------------------------*/
					String str = "";
					try {
						str = HouServer.getCountByShuZi(in_Text.getContent());
						out_Text.setContent("成功,"+in_Text.getContent()+"已经有"+str+"次被猜中了。");
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						out_Text.setContent("现在用户很踊跃,服务器太累了,您没有参与成功,请继续参与.");
						e.printStackTrace();
					}
					//out_Text.setContent("成功,"+in_Text.getContent()+"已经有"+str+"次被猜中了。");
					System.out.println(out_Text.getStr());
			out.print(out_Text.getStr());
			/*-----------查询数据库-----------------------end--------------------------------*/
					}else{
						if("video".equals(in.getMsgType())){
							In_Video in_Video = new In_Video(requestStr);
							System.out.println(in_Video);
							Out_Video out_video = new Out_Video(in_Video);
							out_video.setMediaId(in_Video.getMediaId());
							System.out.println(out_video.toString());
							System.out.println(out_video.getStr());
							out.println(out_video.getStr());
						}else{
			Out_Text out_Text = new Out_Text(in);
			out_Text.setContent("请选择一个数字");
			out.print(out_Text.getStr());
						}
					}
		
		
		out.flush();
		out.close();
		System.out.println("ok");
	}

}

 

© 著作权归作者所有

blueheart
粉丝 0
博文 35
码字总数 29716
作品 0
佛山
程序员
私信 提问
分享java微信开发视频

课程讲师:翟东平 课程分类:Java适合人群:高级课时数量:24(41节)课时更新程度:完毕服务类型:C类(普通服务类课程)用到技术:微信公众平台,微信,java涉及项目:超市促销活动,微信限时...

双层牛堡
2015/04/07
0
0
Java微信开发_00_资源汇总贴

1.微信公众平台技术文档(https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1445241432) 2.微信企业号开发接口文档(http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%BB%E......

rayner
2017/08/07
0
0
JeeWx 捷微 2.3 发布,JAVA微信管家平台

JeeWx,敏捷微信开发,简称“捷微”,捷微是一款免费开源的JAVA微信管家平台 一、简介 Jeewx是一个开源、高效、敏捷的微信开发平台,采用JAVA语言基于Jeecg快速开发框架实现,Jeewx开源版实现...

Jeecg
2016/03/24
10.6K
0
微信公众平台开发教程新手解惑40则

【编者按】由CSDN和《程序员》杂志联合主办的 2014年微信开发者大会 将于8月23日在北京举行,邀请了来自于一线的微信开发商技术负责人或资深工程师从企业应用开发高级篇、智能客服与LBS、微信...

DavidBao
2015/04/29
0
0
JFinal Weixin 1.8 发布,微信极速 SDK

离上一次 JFinal weixin 1.7 发布,已经过去了 6 个月。在过去的半年时间里 JFinal Weixin 紧随微信公众平台的演化,不断增加了新的 API,同时也在不断完善原有 API,力求打造一个完备的微信...

JFinal
2016/07/13
11.4K
96

没有更多内容

加载失败,请刷新页面

加载更多

Docker搭建Mysql集群、主从同步复制

1、创建数据挂载点: mkdir /opt/mysql-master/mysql、/opt/mysql-master/conf.d、/opt/mysql-slave/conf.d、/opt/mysql-slave/conf.d 2、分别在master、slave节点文件目录conf.d下创建touch......

WALK_MAN
14分钟前
0
0
手把手教你做中间件开发(分布式缓存篇)-借助redis已有的网络相关.c和.h文件,半小时快速实现一个epoll异步网络框架,程序demo

本文档配合主要对如下demo进行配合说明: 借助redis已有的网络相关.c和.h文件,半小时快速实现一个epoll异步网络框架,程序demo 0. 手把手教你做中间件、高性能服务器、分布式存储技术交流群 ...

y123456yz
15分钟前
0
0
阿里技术男的成长史:越想证明自己死得越快……

在上海工作8年后,身为部门经理的钱磊,管理着一家ERP公司的百十来号员工,“再往上爬就是老板和他儿子了……从这个领域的技术角度来讲算是做到了顶。”05年,钱磊就开始关注一家名字奇怪,做...

阿里云云栖社区
19分钟前
1
0
Spring-boot单元测试(私有方法测试)

Spring-boot的单元测试网上有了很多,当项目是可以使用spring-boot正常运行时,只要在测试类上添加如下配置就使用@Autowired的方式进行单元测试 @RunWith(SpringJUnit4ClassRunner.class)@...

琴兽
36分钟前
0
0
spring cloud(第一部)框架概述

关于微服务 近几年,'微服务'这个词越来越多的被身边的人所提及,到底什么是微服务,为什么微服务总是伴随着spring cloud被人们所提及,这里笔者结合多年的技术经历跟大家分享下自己的理解:...

白中墨
37分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部