微信公众号开发之用户分组
2016-12-26 18:15
183 查看
具体参照微信官方文档。
创建用户分组
批量移动用户分组
我有空再来添加详细描述吧!
创建用户分组
/** * 创建分组 * @param groupName 分组名 * @return Integer 分组ID */ public static Integer createPrizeDrawGroup(String groupName){ String url = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token="+getGlobalToken(); JSONObject json = new JSONObject(); JSONObject jsonParent = new JSONObject(); json.put("name", groupName); jsonParent.put("group", json); JSONObject demoJson = null; try { URL urlGet = new URL(url); HttpURLConnection http = (HttpURLConnection) urlGet.openConnection(); http.setRequestMethod("POST"); // 必须是POST方式请求 http.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); http.setDoOutput(true); http.setDoInput(true); http.getOutputStream().write(jsonParent.toString().getBytes()); 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"); demoJson = JSONObject.fromObject(message); //System.out.println("JSON字符串:"+demoJson); is.close(); } catch (Exception e) { e.printStackTrace(); } return demoJson.getJSONObject("group").getInt("id"); }
批量移动用户分组
/** * 移动用户分组 * @param list openID list * @param id 分组ID * @return 操作成功:true 失败:false */ public boolean updateGroup(List<String> list,Integer id){ String url = "https://api.weixin.qq.com/cgi-bin/groups/members/batchupdate?access_token="+getGlobalToken(); JSONObject json = new JSONObject(); json.put("openid_list", list); json.put("to_groupid", id); JSONObject demoJson = null; try { URL urlGet = new URL(url); HttpURLConnection http = (HttpURLConnection) urlGet.openConnection(); http.setRequestMethod("POST"); // 必须是get方式请求 http.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); http.setDoOutput(true); http.setDoInput(true); http.getOutputStream().write(json.toString().getBytes()); //System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒 //System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒 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"); demoJson = JSONObject.fromObject(message); System.out.println("JSON字符串:"+demoJson); is.close(); } catch (Exception e) { e.printStackTrace(); } return demoJson.getInt("errcode")==1?true:false; }
我有空再来添加详细描述吧!
相关文章推荐
- 获取微信公众号用户分组-php开发管理公众号用户
- 微信公众号用户分组,新建公众号用户分组,php开发公众号
- 公众号修改用户分组-php开发微信公众号
- C#开发微信门户及应用(5)--用户分组信息管理
- 微信公众号开发中的用户账号绑定
- C#开发微信门户及应用(5)--用户分组信息管理
- 微信公众平台开发(88) 用户分组接口
- 微信公众平台开发文档 用户分组管理
- 微信公众号开发系列-网页授权获取用户基本信息
- C#开发微信门户及应用(5)--用户分组信息管理
- C#开发微信门户及应用(10)--在管理系统中同步微信用户分组信息
- 微信公众号开发中的用户账号绑定
- 微信公众平台开发(74) 用户分组管理
- C#微信公众号开发-高级接口-之网页授权oauth2.0获取用户基本信息(二)
- C#微信公众号接口开发,灵活利用网页授权、带参数二维码、模板消息,提升用户体验之完成用户绑定个人微信及验证码获取
- 微信公众号开发_如何获取用户信息?
- 微信公众平台开发(74) 用户分组管理
- 微信公众平台开发(74) 用户分组管理
- 微信公众平台开发文档 用户分组管理
- C#微信公众号开发之网页授权oauth2.0获取用户基本信息(一)