發送消息:
基於上面access_token的邏輯,在構造發送消息對象的時候請按照如下代碼.
wechat4j和微信強力推薦的方法
CustomerMsg customerMsg = new CustomerMsg(toUserOpenId);
CustomerMsg發送消息的方法
- sendText 發送文本消息
- sendImage 發送圖片消息
- sendVoice 發送語音消息
- sendVideo 發送視頻消息
- sendVideo 發送視頻消息
- sendMusic 發送音樂消息
- sendNew 發送圖文消息,單條圖文消息
- sendNews 發送圖文消息
示例:
微信平臺會在請求的post數據中帶有一些參數,例如用戶的openid之類的信息,當你使用了wechat4j之後,得到這些信息是非常方便的。
publicclass Lejian extends WechatSupport{
@Override
protected void onText() {
String fromUser = this.wechatRequest.getFromUserName();
}
}
上面代碼中的this.wechatRequest.getFromUserName()即可以得到微信post數據中的FromUserName節點數據.
獲取微信參數:
wechatRequest可以得到的post數據
wechatRequest成員方法中get的方法,名稱同微信開發文檔中xml形式的post數據的節點。
· getFromUserName()
· getContent()
· getCreateTime()
· getDescription()
· getLabel()
· getMsgId
· getEvent()
· getFormat()
· getLabel()
· getLocation_X()
· getLocation_X()
· getMediaId()
· getMsgId()
· getMsgType()
· getPicUrl()
· getScale()
· getTitle()
· getToUserName()
· getUrl()