Java通过QQ群的API读取群组状态的代码

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

有好多群,懒得随时更新群的状态,特别是当前人数这个经常变的东西。这里根据QQ的一个API程序,读取状态,直接看看代码吧。

读取的接口程序和测试代码!
  1. package com.laozizhu.blog.util;
  2. import java.io.Reader;
  3. import java.io.StringReader;
  4. import java.util.List;
  5. import org.jdom.Document;
  6. import org.jdom.Element;
  7. import org.jdom.input.SAXBuilder;
  8. /**
  9.  * 读取的接口程序。
  10.  * 
  11.  * @author 老紫竹 www.laozizhu.com
  12.  */
  13. public class QQGroupBaseInfoAPI {
  14.   public static QQGroupBaseInfo get(String id) {
  15.     try {
  16.       String textXml = PageService.getPage("http://group.qq.com/cgi-bin/groupbaseinfo?groupid=" + id, "GBK");
  17.       char c = 0x1d;
  18.       String s = String.valueOf(c);
  19.       textXml = textXml.replaceAll(s, "");
  20.       SAXBuilder builder = new SAXBuilder();
  21.       Document doc = null;
  22.       Reader in = new StringReader(textXml);
  23.       doc = builder.build(in);
  24.       Element root = doc.getRootElement(); // 拿到 date
  25.       List date = root.getChildren(); // 下一级数据
  26.       Element result = (Element) date.get(0); // 结果标志
  27.       if (!"0".equals(result.getTextTrim())) {
  28.         System.out.println("没找到" + id);
  29.         return null// 没找到
  30.       }
  31.       Element item = (Element) date.get(1);
  32.       QQGroupBaseInfo o = new QQGroupBaseInfo();
  33.       o.setLogo(MyHTMLDecoder.decode(item.getChildTextTrim("logo")));
  34.       o.setMemo(MyHTMLDecoder.decode(item.getChildTextTrim("memo")));
  35.       o.setMale(MyHTMLDecoder.decode(item.getChildTextTrim("male")));
  36.       o.setFemale(MyHTMLDecoder.decode(item.getChildTextTrim("female")));
  37.       o.setRank(MyHTMLDecoder.decode(item.getChildTextTrim("rank")));
  38.       o.setGroupId(MyHTMLDecoder.decode(item.getChildTextTrim("groupid")));
  39.       o.setGroupType(MyHTMLDecoder.decode(item.getChildTextTrim("grouptype")));
  40.       o.setGroupOption(MyHTMLDecoder.decode(item.getChildTextTrim("logo")));
  41.       o.setBrief(MyHTMLDecoder.decode(item.getChildTextTrim("brief")));
  42.       o.setGroupClass(MyHTMLDecoder.decode(item.getChildTextTrim("groupclass")));
  43.       o.setCreator(MyHTMLDecoder.decode(item.getChildTextTrim("creator")));
  44.       o.setUin(MyHTMLDecoder.decode(item.getChildTextTrim("uin")));
  45.       o.setFaceId(MyHTMLDecoder.decode(item.getChildTextTrim("faceid")));
  46.       o.setCreateTime(MyHTMLDecoder.decode(item.getChildTextTrim("crttime")));
  47.       o.setGroupStatus(MyHTMLDecoder.decode(item.getChildTextTrim("gpstatus")));
  48.       o.setClassName(MyHTMLDecoder.decode(item.getChildTextTrim("class")));
  49.       o.setFlag(Long.parseLong(item.getChildTextTrim("flag")));
  50.       o.setTotal(Integer.parseInt(item.getChildTextTrim("total")));
  51.       o.setGuestDeny(Integer.parseInt(item.getChildTextTrim("guestdeny")));
  52.       o.setMemberMax(Integer.parseInt(item.getChildTextTrim("membermax")));
  53.       o.setGroupFace(Integer.parseInt(item.getChildTextTrim("groupface")));
  54.       o.setGroupName(MyHTMLDecoder.decode(item.getChildTextTrim("groupname")));
  55.       o.setOpen(Integer.parseInt(item.getChildTextTrim("isopen")) == 1);
  56.       o.setOpen(Integer.parseInt(item.getChildTextTrim("isopen")) == 1);
  57.       o.setCloseExpire(Integer.parseInt(item.getChildTextTrim("iscloseexpire")) == 1);
  58.       o.setSuperExpireDate(MyHTMLDecoder.decode(item.getChildTextTrim("superexpiredate")));
  59.       return o;
  60.     } catch (Exception ex) {
  61.       ex.printStackTrace();
  62.       return null;
  63.     }
  64.   }
  65.   /**
  66.    * @param args
  67.    */
  68.   public static void main(String[] args) {
  69.     QQGroupBaseInfo o = get("56763840");
  70.     System.out.println(o.getTotal());
  71.     System.out.println(o.getMemberMax());
  72.   }
  73. }


读取的接口信息
  1. package com.laozizhu.blog.util;
  2. /**
  3.  * QQ的基础信息。
  4.  * 
  5.  * @author 老紫竹 www.laozizhu.com
  6.  */
  7. public class QQGroupBaseInfo {
  8.   // 图标
  9.   private String logo;
  10.   // 公告
  11.   private String memo;
  12.   private String male;
  13.   private String female;
  14.   private String rank;
  15.   // 群号
  16.   private String groupId;
  17.   private String groupType;
  18.   private String groupOption;
  19.   // 简介
  20.   private String brief;
  21.   private String groupClass;
  22.   private String groupClassEx;
  23.   // 创建人
  24.   private String creator;
  25.   // 创建人的号码
  26.   private String uin;
  27.   private String faceId;
  28.   private String createTime;
  29.   // 是否为高级群
  30.   private String groupStatus;
  31.   // 分类,比如软件交流
  32.   private String className;
  33.   private long flag;
  34.   // 当前总人数
  35.   private int total;
  36.   private int guestDeny;
  37.   // 最高人数
  38.   private int memberMax;
  39.   private int groupFace;
  40.   // 群名字
  41.   private String groupName;
  42.   private boolean open;
  43.   private boolean mem;
  44.   private boolean closeExpire;
  45.   // 高级群过期日期
  46.   private String superExpireDate;
  47.   public String getLogo() {
  48.     return logo;
  49.   }
  50.   public void setLogo(String logo) {
  51.     this.logo = logo;
  52.   }
  53.   public String getMemo() {
  54.     return memo;
  55.   }
  56.   public void setMemo(String memo) {
  57.     this.memo = memo;
  58.   }
  59.   public String getGroupId() {
  60. <
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值