设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 运营中心 > 网站设计 > 正文

详细Java批量获取微信公众号方法(4)

发布时间:2021-02-21 17:01 所属栏目:12 来源:网络整理
导读:处理公众号文章页的方法: public String getWxPost() { // TODO Auto-generated method stub /** * 当前页面为公众号文章页面时,读取这个程序 * 首先删除采集队列表中load=1的行 * 然后从队列表中按照“order by

处理公众号文章页的方法:

public String getWxPost() {
    // TODO Auto-generated method stub
    /**
     * 当前页面为公众号文章页面时,读取这个程序
     * 首先删除采集队列表中load=1的行
     * 然后从队列表中按照“order by id asc”选择多行(注意这一行和上面的程序不一样)
     */
    tmpListMapper.deleteByLoad(1);
    List<TmpList> queues = tmpListMapper.selectMany(5);
    String url = "";
    if(queues != null && queues.size() != 0 && queues.size() > 1){
      TmpList queue = queues.get(0);
      url = queue.getContentUrl();
      queue.setIsload(1);
      int result = tmpListMapper.updateByPrimaryKey(queue);
      System.out.println("update result:"+result);
    }else{
      System.out.println("getpost queues is null?"+queues==null?null:queues.size());
      WeiXin weiXin = weiXinMapper.selectOne();
      String biz = weiXin.getBiz();
      if((Math.random()>0.5?1:0) == 1){
        url = "http://mp.weixin.qq.com/mp/getmasssendmsg?__biz=" + biz + 
            "#wechat_webview_type=1&wechat_redirect";//拼接公众号历史消息url地址(第一种页面形式)
      }else{
        url = "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=" + biz + 
            "#wechat_redirect";//拼接公众号历史消息url地址(第二种页面形式)
      }
      url = "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=" + biz + 
          "#wechat_redirect";//拼接公众号历史消息url地址(第二种页面形式)
      //更新刚才提到的公众号表中的采集时间time字段为当前时间戳。
      weiXin.setCollect(System.currentTimeMillis());
      int result = weiXinMapper.updateByPrimaryKey(weiXin);
      System.out.println("getPost weiXin updateResult:"+result);
    }
    int randomTime = new Random().nextInt(3) + 3;
    String jsCode = "<script>setTimeout(function(){window.location.href='"+url+"';},"+randomTime*1000+");</script>";
    return jsCode;
    
  }

 

处理公众号点赞量和阅读量的方法:

public void getMsgExt(String str,String url) {
    // TODO Auto-generated method stub
    String biz = "";
    String sn = "";
    Map<String,String> queryStrs = HttpUrlParser.parseUrl(url);
    if(queryStrs != null){
      biz = queryStrs.get("__biz");
      biz = biz + "==";
      sn = queryStrs.get("sn");
      sn = "%" + sn + "%";
    }
    /**
     * $sql = "select * from `文章表` where `biz`='".$biz."'
     * and `content_url` like '%".$sn."%'" limit 0,1;
     * 根据biz和sn找到对应的文章
     */
    Post post = postMapper.selectByBizAndSn(biz,sn);
    
    if(post == null){
      System.out.println("biz:"+biz);
      System.out.println("sn:"+sn);
      tmpListMapper.deleteByLoad(1);
      return;
    }
    
//    System.out.println("json数据:"+str);
    Integer read_num;
    Integer like_num;
    try{
      read_num = JsonPath.read(str,"['appmsgstat']['read_num']");//阅读量
      like_num = JsonPath.read(str,"['appmsgstat']['like_num']");//点赞量
    }catch(Exception e){
      read_num = 123;//阅读量
      like_num = 321;//点赞量
      System.out.println("read_num:"+read_num);
      System.out.println("like_num:"+like_num);
      System.out.println(e.getMessage());
    }    
    
    /**
     * 在这里同样根据sn在采集队列表中删除对应的文章,代表这篇文章可以移出采集队列了
     * $sql = "delete from `队列表` where `content_url` like '%".$sn."%'" 
     */
    tmpListMapper.deleteBySn(sn);
    
    //然后将阅读量和点赞量更新到文章表中。
    post.setReadnum(read_num);
    post.setLikenum(like_num);
    postMapper.updateByPrimaryKey(post);
    
  }

 

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读