博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java后端判断用户是否关注公众号
阅读量:4633 次
发布时间:2019-06-09

本文共 1326 字,大约阅读时间需要 4 分钟。

/** * 判断用户是否关注了公众号 * @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

 

转载于:https://www.cnblogs.com/BobXie85/p/9724142.html

你可能感兴趣的文章
android+onTouchEventView+背景图片
查看>>
Tomcat工作原理
查看>>
【【2014年最新web前端开发面试题目】】
查看>>
dedecms标签大全(非常经典)
查看>>
关于Thread的Runnable和Callable接口
查看>>
vue添加jquery
查看>>
ubuntu hadoop环境搭建
查看>>
关于base64编码的原理和实现
查看>>
poj2676_数独
查看>>
几道动态规划
查看>>
指针数组学习
查看>>
(转载)虚幻引擎3--第三章–Unreal中的类
查看>>
SQL Server 系统表使用举例
查看>>
理解JavaScript里的 [].forEach.call() 写法
查看>>
eclipse 导入web项目时常见错误
查看>>
POM.XML文档汉化
查看>>
注册表中LEGACY残留项的清理技巧
查看>>
如何制作中文Javadoc包,并导入到Eclipse
查看>>
6月21 百度文本编辑器
查看>>
每日记载内容总结28
查看>>