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
  • 相关阅读:
    js搜索输入关键词
    pc端,自适应屏幕分辨率
    js获取锚点名称 #
    yourphp读取分类名称{$Categorys[$r[catid]]['catname']}
    收缩菜单 css变样
    ajax成功跨域_自己写的
    json 是个什么东西?
    json_encode详解,转义
    跨域代码 手机号码
    php json_decode
  • 原文地址:https://www.cnblogs.com/BobXie85/p/9724142.html
Copyright © 2011-2022 走看看