微信開發(一)---微信消息

一、前言
閒來有空,正好把這兩年開發微信的東西拿出來抖抖。從零基礎搭建一個微信開發基礎框架。閒來搭建微信消息實體,包括接收的用戶消息和回覆用戶消息兩個基本實體。
在這裏插入圖片描述
二、參考/說明
主要需要參看微信公衆平臺開發者文檔
網頁地址:微信開發者文檔
實體類中使用了lombok,所以省略了set ,get ,equal,hash以及ToString方法。
三、消息實體類
參看微信開發者文檔消息管理中的第一欄,接收用戶消息中分爲文本消息、圖片消息、語音消息,視頻消息、鏈接消息等等吧,有一些共同屬性,進行提取。包結構如下:
在這裏插入圖片描述
1)BaseEntity

package com.zlc.wechat.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 16:34
 **/
@Data
public class BaseEntity implements Serializable {
    
    private static final long serialVersionUID = 1L;
    /**
     * 媒體Id,用於從微信素材接口調用
     */
    private long mediaId;
    
}

2)ArticleEntity

package com.zlc.wechat.entity;

import lombok.Data;

/**
 * 微信圖文
 * @author :  追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 15:22
 **/
@Data
public class ArticleEntity extends BaseEntity{
    /**
     * 圖文消息標題
     */
    private String title;
    /**
     * 圖文消息描述
     */
    private String description;
    /**
     * 圖片的鏈接
     * 支持JPG、PNG格式,較好的效果爲大圖640*320,小圖80*80,限制圖片鏈接的域名需要與開發者填寫的基本資料中的Url一致
     */
    private String pictureUrl;
    /**
     * 點擊圖文消息後要跳轉的url
     */
    private String url;

}

3)ImageEntity

package com.zlc.wechat.entity;

import lombok.Data;

/**
 * 微信圖片
 * @author :  追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 15:22
 **/
@Data
public class ImageEntity extends BaseEntity{
	
	/**
	 * 圖片鏈接(由系統生成)
	 */
	private String picUrl;
	
}

4)LinkEntity

package com.zlc.wechat.entity;

import lombok.Data;

/**
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/24 9:47
 **/
@Data
public class LinkEntity extends BaseEntity{
    
    /**
     * 消息標題
     */
    private String title;
    /**
     * 消息描述
     */
    private String description;
    /**
     * 消息鏈接
     */
    private String url;
    
}

5)LocationEntity

package com.zlc.wechat.entity;

import lombok.Data;

/**
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 17:06
 **/
@Data
public class LocationEntity extends BaseEntity{

    /**
     * 地理位置維度
     */
    private String locationX;
    /**
     * 地理位置經度
     */
    private String locationY;
    /**
     * 地圖縮放大小
     */
    private String scale;
    /**
     * 地理位置信息
     */
    private String label;
    
}

6)MusicEntity

package com.zlc.wechat.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * 微信音樂
 * @author :  追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 15:22
 **/
@Data
public class MusicEntity implements Serializable {

	private static final long serialVersionUID = 1L;
	
	/**
	 * 音樂名稱
	 */
	private String title;
	/**
	 * 音樂描述
	 */
	private String description;
	/**
	 * 音樂鏈接
	 */
	private String musicUrl;
	/**
	 * 質量音樂鏈接,WIFI環境優先使用該鏈接播放音樂
	 */
	private String HQMusicUrl;
	/**
	 * 縮略圖的媒體id,通過上傳多媒體文件得到的id
	 */
	private String thumbMediaId;
	
}

7)TextEntity

package com.zlc.wechat.entity;

import lombok.Data;

/**
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 16:40
 **/
@Data
public class TextEntity extends BaseEntity{
    
    /**
     * 文本消息內容
     */
    private String content;
    
}

8)VideoEntity

package com.zlc.wechat.entity;

import lombok.Data;

/**
 * 微信視頻
 * @author :  追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 15:22
 **/
@Data
public class VideoEntity extends BaseEntity {
	
	/**
	 * 視頻縮略圖的媒體Id,(縮略圖就是微信中的那個小窗口視頻,圖片和視頻都會縮略)
	 */
	private String thumbMediaId;
	
}

9)VoiceEntity

package com.zlc.wechat.entity;

import lombok.Data;

/**
 * 微信語音
 * @author :  追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 15:22
 **/
@Data
public class VoiceEntity extends BaseEntity {
	
	/**
	 * 語音格式,如amr,speex等
	 */
	private String format;
	/**
	 * 開通語音識別後,用戶每次發送語音給公衆號時,微信會在推送的語音消息XML數據包中,增加
	 * 語音格式:amr
	 * 語音識別結果,UTF8編碼()
	 */
	private String recognition;
	
}

三、用戶發送消息類
1)BaseWeChatMsg

package com.zlc.wechat.message;

import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 16:08
 **/
@Data
public class BaseWeChatMsg implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 消息Id,64位整形
     */
    private long msgId;
    /**
     * 開發者微信號
     */
    private String toUserName;
    /**
     * 發送方帳號(一個OpenID)
     */
    private String fromUserName;
    /**
     * 消息創建時間 (整型)
     */
    private Date createTime;
    /**
     * 消息類型
     */
    private String msgType;
    /**
     * 位0x0001被標誌時,星標剛收到的消息
     */
    private int funcFlag;
    
}

2)ReceiveImageMsg

package com.zlc.wechat.message.receive;

import com.zlc.wechat.entity.ImageEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 圖片消息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 16:31
 **/
@Data
public class ReceiveImageMsg extends BaseWeChatMsg {
   
    /**
     * 圖片
     */
    private ImageEntity imageEntity;
    
}

3)ReceiveLinkMsg

package com.zlc.wechat.message.receive;

import com.zlc.wechat.entity.LinkEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/24 9:46
 **/
@Data
public class ReceiveLinkMsg extends BaseWeChatMsg {
    
    /**
     * 鏈接
     */
    private LinkEntity linkEntity;
    
}

4)ReceiveLocationMsg

package com.zlc.wechat.message.receive;

import com.zlc.wechat.entity.LocationEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 地理位置信息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 17:05
 **/
@Data
public class ReceiveLocationMsg extends BaseWeChatMsg {
   
    /**
     * 位置
     */
    private LocationEntity locationEntity;
    
}

5)ReceiveTextMsg

package com.zlc.wechat.message.receive;

import com.zlc.wechat.entity.TextEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 文本消息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 16:06
 **/
@Data
public class ReceiveTextMsg extends BaseWeChatMsg {
   
    /**
     * 文本
     */
    private TextEntity textEntity;
    
}

6)ReceiveVideoMsg

package com.zlc.wechat.message.receive;

import com.zlc.wechat.entity.VideoEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 視頻類消息(包括小視頻)
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 17:00
 **/
@Data
public class ReceiveVideoMsg extends BaseWeChatMsg {
   
    /**
     * 視頻
     */
    private VideoEntity videoEntity;
    
}

7)ReceiveVoiceMsg

package com.zlc.wechat.message.receive;

import com.zlc.wechat.entity.BaseEntity;
import com.zlc.wechat.entity.VoiceEntity;
import lombok.Data;

/**
 * 語音消息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/23 16:47
 **/
@Data
public class ReceiveVoiceMsg extends BaseEntity {
    
    /**
     * 語音
     */
    private VoiceEntity voiceEntity;
    
}

四、被動回覆用戶消息類
1)ReplyArticleMsg

package com.zlc.wechat.message.reply;

import com.zlc.wechat.entity.ArticleEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

import java.util.List;

/**
 * 被動回覆用戶圖文消息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/24 10:05
 **/
@Data
public class ReplyArticleMsg extends BaseWeChatMsg {
    
    /**
     * 圖文消息總條數
     */
    private int articleCount;
    /**
     * 圖文消息集合
     */
    private List<ArticleEntity> articles;
    
}

2)ReplyImageMsg

package com.zlc.wechat.message.reply;

import com.zlc.wechat.entity.ImageEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 被動回覆圖片信息,可以是多圖
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/24 9:56
 **/
@Data
public class ReplyImageMsg extends BaseWeChatMsg {
    
    /**
     * 圖片
     */
    private ImageEntity imageEntity;
    
}    

3)ReplyMusicMsg

package com.zlc.wechat.message.reply;

import com.zlc.wechat.entity.MusicEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 被動回覆用戶樂音消息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/24 10:02
 **/
@Data
public class ReplyMusicMsg extends BaseWeChatMsg {
  
    /**
     * 音樂
     */
    private MusicEntity musicEntity;
    
}

4)ReplyTextMsg

package com.zlc.wechat.message.reply;

import com.zlc.wechat.entity.TextEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 被動回覆用戶文本消息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/24 9:53
 **/
@Data
public class ReplyTextMsg extends BaseWeChatMsg {
    
    /**
     * 文本
     */
    private TextEntity textEntity;
    
}

5)ReplyVideoMsg

package com.zlc.wechat.message.reply;

import com.zlc.wechat.entity.VideoEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 被動回覆用戶視頻消息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/24 10:00
 **/
@Data
public class ReplyVideoMsg extends BaseWeChatMsg {
   
    /**
     * 視頻
     */    
    private VideoEntity videoEntity;
    
}

6)ReplyVoiceMsg

package com.zlc.wechat.message.reply;

import com.zlc.wechat.entity.VoiceEntity;
import com.zlc.wechat.message.BaseWeChatMsg;
import lombok.Data;

/**
 * 被動回覆用戶語音消息
 * @author : 追到烏雲的盡頭找太陽-(Jacob)
 * @date : 2019/10/24 9:58
 **/
@Data
public class ReplyVoiceMsg extends BaseWeChatMsg {
   
    /**
     * 語音
     */
    private VoiceEntity voiceEntity;
    
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章