小程序开发--登陆

 

登陆流程

  技术通常水平有限,有什么错的地方,望你们指正。小程序

  小程序的热度散的快差很少了,记录一下本身的开发中的坎坷。服务器

  登陆的照着官方的流程来便可:微信

  首先建立一个请求方法来实现本身的服务器和微信服务器的一个通讯:session

public static String GET(String url){
        String result = "";
        BufferedReader in = null;
        try {
            URL realUrl = new URL(url);
            URLConnection conn = realUrl.openConnection();
            conn.connect();
            Map<String, List<String>> map = conn.getHeaderFields();
            in = new BufferedReader(new InputStreamReader(
                    conn.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            
        }finally{
            try {
                if(in!=null){
                    in.close();
                }
            } catch (Exception e2) {
                //log中记录
            }
        }
        return result;
    }

   而后构建请求的url(把红圈变出的属性改为本身对应的数据):app

  经过GET()方法和微信服务器来通讯,若是请求正确咱们就可以获取到session_key和openid,把这两个值存在session中:dom

Jedis jedis = new Jedis("localhost");             
String openid = openid;
String session_key = session_key;
String uid = UUID.randomUUID().toString();
StringBuffer sb = new StringBuffer();
sb.append(openid);
sb.append(","+session_key);
jedis.set(uid, sb.toString());

  把uid返给客户端,之后客户端的每一次请求都带上uid。ui

问题处理

  在处理过程当中若是须要获取登陆用户的用户名和头像,若是用户名有中文就会出现乱码,解决方法以下:url

String nickNameDecode = new String(nickName.getBytes("ISO-8859-1"),"utf-8");
相关文章
相关标签/搜索