• 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
  • 相关阅读:
    hdu 5936 2016ccpc 杭州
    bzoj 1218: [HNOI2003]激光炸弹
    bzoj 1296: [SCOI2009]粉刷匠
    桃子到底有多少
    计算x的n次方
    计算x的n次方
    菲波拉契数列
    菲波拉契数列
    八皇后(N皇后)问题算法程序(回溯法)
    八皇后(N皇后)问题算法程序(回溯法)
  • 原文地址:https://www.cnblogs.com/BobXie85/p/9724142.html
Copyright © 2020-2023  润新知