当前位置 : 主页 > 编程语言 > c++ >

java微信验证文件

来源:互联网 收集:自由互联 发布时间:2021-07-03
Validation.txt protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {// TODO Auto-generated method stubString signature = req.getParameter("signature");String timestamp = req.getParamete
Validation.txt
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String signature = req.getParameter("signature");
		String timestamp = req.getParameter("timestamp");
		String nonce = req.getParameter("nonce");
		String echostr = req.getParameter("echostr");
		
		System.out.println("验证签名"+signature);
		System.out.println("时间戳"+timestamp);
		System.out.println("随机数"+nonce);
		System.out.println("随机字符串"+echostr);
		
		
		//输出流
		PrintWriter out = resp.getWriter();
		if(ValidationTools.checkSignature(signature, timestamp, nonce))
		{
			out.print(echostr);//
			
		}
		
		out.close();
		out=null;
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/xml;charset=utf-8");
		resp.setCharacterEncoding("utf-8");
		
		PrintWriter out=resp.getWriter();
		try
		{
			Map
 
   map = MessageUtil.xmlToMap(req);
			String toUserName = map.get("ToUserName");
			String fromUserName = map.get("FromUserName");
			String msgType = map.get("MsgType");
			String content = map.get("Content");
			String createtime=map.get("CreateTime");
			

			String message = null ;
			if("text".equals(msgType))
			{
				TextMessage text = new TextMessage();
				text.setToUserName(fromUserName);
				text.setFromUserName(toUserName);
				text.setCreateTime(new Date().getTime());
				text.setMsgType("text");
				text.setConetent(""+content);
			
				
				message = MessageUtil.textMessageToXML(text);
				
			}
			System.out.println(message);
			out.print(message);//将返回的信息放在输出流里面
			
		}catch(DocumentException e)
		{
			e.printStackTrace();
		}
		finally{
			out.close();
		}
 
网友评论