zoukankan      html  css  js  c++  java
  • java后端判断用户是否关注公众号

    /**
     * 判断用户是否关注了公众号
     * @param openid
     * @return
     */
    public static boolean judgeIsFollow(String openid){
        int subscribe = 0;
    //        String url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token="+token+"&openid="+openid+"&lang=zh_CN";
        try {  
    //        String token = getTicket();
            String token = "";
            if (StringUtil.isEmpty(token)) {
                token = getAccess_token();
            }
            String url = String.format(Constant.GzGzhUrl, token, openid);
            URL urlGet = new URL(url);  
            HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();  
            http.setRequestMethod("GET"); // 必须是get方式请求  
            http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");  
            http.setDoOutput(true);  
            http.setDoInput(true);  
            http.connect();  
            InputStream is = http.getInputStream();  
            int size = is.available();  
            byte[] jsonBytes = new byte[size];  
            is.read(jsonBytes);  
            String message = new String(jsonBytes, "UTF-8");  
            JSONObject demoJson = JSONObject.fromObject(message);  
            subscribe = demoJson.getInt("subscribe");
    
            is.close();  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return 1==subscribe?true:false;
    }
    View Code
  • 相关阅读:
    数据分析 ---上篇
    爬虫 ---模拟登录
    Spider -- 获取图片并处理中文乱码
    爬虫篇 ---增量式爬虫
    Django中间件深入理解
    认识casbin
    关于nginx开机自己启动配置
    更改redhat yum源
    sqlalchemy监听事件
    Linux命令 history
  • 原文地址:https://www.cnblogs.com/BobXie85/p/9724142.html
Copyright © 2011-2022 走看看