Пример #1
0
  /*
   * 签到时返回的图文消息
   */
  public static String signNewsMessage(String toUserName, String fromUserName) {
    String message = null;
    List<Article> articleList = new ArrayList<Article>();
    NewsMessage newsMessage = new NewsMessage();

    Article article = new Article();
    article.setTitle("打卡成功!");
    article.setDescription("↓↓↓戳我,就现在");
    article.setPicUrl(
        "http://imgsrc.baidu.com/forum/w%3D580/sign=5fac7d37253fb80e0cd161df06d12ffb/bf19852397dda144f3711db4b6b7d0a20df4868e.jpg");
    article.setUrl(SIGN_URL + "?openid=" + fromUserName);
    // article.setUrl("H7t11zWvCnnGk6Cg-v-IO2JfBwEAYWGLaNUWssLNPq1YcDts5V5SGwM9-q01SIgP");

    articleList.add(article);

    newsMessage.setFromUserName(toUserName);
    newsMessage.setToUserName(fromUserName);
    newsMessage.setArticles(articleList);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    newsMessage.setCreateTime(sdf.format(new Date()));
    newsMessage.setArticleCount(articleList.size());
    newsMessage.setMsgType(MESSAGE_NEWS);

    message = MessageUtil.newsMessageToXml(newsMessage);
    return message;
  }
Пример #2
0
  /*
   * 点击搞笑一则,随机获取图文消息
   */
  public static String getOneNews(String toUserName, String fromUserName) throws IOException {
    String message = null;
    List<Article> articleList = new ArrayList<Article>();
    NewsMessage newsMessage = new NewsMessage();
    Items[] items = GetItems.getItems();
    int random = (int) Math.round(Math.random() * 20);
    System.out.println(random);
    for (int i = 0; i < 10; i++) {
      Article article = new Article();
      article.setTitle(items[random].getHeader());
      article.setDescription(items[random].getContent());
      article.setPicUrl(items[random].getThumbnail());
      article.setUrl(ARTICLE_URL + "?articleId=" + items[random].getArticalId());

      articleList.add(article);
      ++random;
    }

    newsMessage.setFromUserName(toUserName);
    newsMessage.setToUserName(fromUserName);
    newsMessage.setArticles(articleList);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    newsMessage.setCreateTime(sdf.format(new Date()));
    newsMessage.setArticleCount(articleList.size());
    newsMessage.setMsgType(MESSAGE_NEWS);
    message = MessageUtil.newsMessageToXml(newsMessage);
    return message;
  }
Пример #3
0
  /*
   * 图片消息
   */
  public static String initImageMessage(String toUserName, String fromUserName) {
    String message = null;
    Image image = new Image();
    image.setMediaId("JiF1AlIFT4TgrALeExilEKTh7kNeukc3SLwS215UrTFMufsUlXx57Sn2HmZ0XVO7");
    ImageMessage im = new ImageMessage();
    im.setFromUserName(toUserName);
    im.setToUserName(fromUserName);
    im.setCreateTime("2016-3-9");
    im.setMsgType(MessageUtil.MESSAGE_IMAGE);
    im.setImage(image);

    message = MessageUtil.imageMessageToXml(im);
    return message;
  }
Пример #4
0
  /*
   * 音频、音乐消息
   */
  public static String initMusicMessage(String toUserName, String fromUserName) {
    String message = null;
    Music music = new Music();
    music.setTitle("test Music");
    music.setDescription("test description");
    music.setThumbMediaId("ABLgKOOwgusANliiMCrOfX55a5VabN0oTdx89MG6E4gCJJAYjrMSvA1PIUwMBmJx");
    music.setMusicUrl("http://tongyuan.tunnel.qydev.com/Weixin/resource/Sleep Away.mp3");
    music.setHQMusicUrl("http://tongyuan.tunnel.qydev.com/Weixin/resource/Sleep Away.mp3");

    MusicMessage mm = new MusicMessage();
    mm.setFromUserName(toUserName);
    mm.setToUserName(fromUserName);
    mm.setCreateTime("2016-3-9");
    mm.setMsgType(MessageUtil.MESSAGE_MUSIC);
    mm.setMusic(music);

    message = MessageUtil.musicMessageToXml(mm);
    return message;
  }