⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generatetoken.java

📁 聊天源码
💻 JAVA
字号:
/* * GenerateToken.java * * Created on 22 Август 2006 г., 21:16 */package org.vorobev.mgtalk;import com.twmacinta.util.MD5;import java.io.*;import java.net.*;import javax.servlet.*;import javax.servlet.http.*;/** * * @author kostya * @version */public class GenerateToken extends HttpServlet {        private String readLine(DataInputStream dis) {        String s = "";        byte ch = 0;        try {            while((ch = dis.readByte())!=-1) {//				System.out.println("ch = "+ch);                if(ch=='\n')                    return s;                s += (char)ch;            }        } catch (Exception e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        return s;    }    protected String generateToken(String email, String pass)    {        try {            String first = "Email="+email+"&Passwd="+pass+"&PersistentCookie=false&source=googletalk";            URL u = new URL("https://www.google.com:443/accounts/ClientAuth?"+first);            HttpURLConnection huc = (HttpURLConnection)u.openConnection();                        DataInputStream dis = new DataInputStream(huc.getInputStream());            String str = readLine(dis);            String SID = "";            String LSID = "";            if(str.startsWith("SID=")) {                SID = str.substring(4, str.length());                str = readLine(dis);                LSID = str.substring(5, str.length());                first = "SID="+SID+"&LSID="+LSID+"&service=mail&Session=true";                dis.close();                                u = new URL("https://www.google.com:443/accounts/IssueAuthToken?"+first);                huc = (HttpURLConnection)u.openConnection();                dis = new DataInputStream(huc.getInputStream());                                str = readLine(dis);                String token = MD5.toBase64(new String("\0"+email+"\0"+str).getBytes());                dis.close();                return token;            }        } catch (Throwable ex) {            ex.printStackTrace();        }                return "tokenError";    }        /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.     * @param request servlet request     * @param response servlet response     */    protected void processRequest(HttpServletRequest request, HttpServletResponse response)    {        try {            response.setContentType("text/html;charset=UTF-8");            PrintWriter out = response.getWriter();            out.println(generateToken(request.getParameter("email"), request.getParameter("pass")));            out.close();        } catch (IOException ex) {            ex.printStackTrace();        }    }    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">    /** Handles the HTTP <code>GET</code> method.     * @param request servlet request     * @param response servlet response     */    protected void doGet(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException {        processRequest(request, response);    }        /** Handles the HTTP <code>POST</code> method.     * @param request servlet request     * @param response servlet response     */    protected void doPost(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException {        processRequest(request, response);    }        /** Returns a short description of the servlet.     */    public String getServletInfo() {        return "Short description";    }    // </editor-fold>}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -