This commit is contained in:
jinyu 2015-07-27 20:53:17 +08:00
parent 30b64dc54a
commit 0cca9d6d02
15 changed files with 184 additions and 20 deletions

View File

@ -72,6 +72,8 @@ weixin4j
接下来 接下来
------ ------
* 企业号消息服务
* 公众号第三方服务应用 * 公众号第三方服务应用
* 硬件设备 & 摇一摇周边 * 硬件设备 & 摇一摇周边

View File

@ -899,7 +899,120 @@
</error> </error>
<error> <error>
<code>85002</code> <code>85002</code>
<text>包含敏感词</text> <text>包含不合法的词语</text>
</error>
<!-- 企业号消息错误 -->
<error>
<code>86001</code>
<text>不合法的会话ID</text>
</error>
<error>
<code>86003</code>
<text>不存在的会话ID</text>
</error>
<error>
<code>86004</code>
<text>不合法的会话名</text>
</error>
<error>
<code>86005</code>
<text>不合法的会话管理员</text>
</error>
<error>
<code>86006</code>
<text>不合法的成员列表大小</text>
</error>
<error>
<code>86007</code>
<text>不存在的成员</text>
</error>
<error>
<code>86101</code>
<text>需要会话管理员权限</text>
</error>
<error>
<code>86201</code>
<text>缺少会话ID</text>
</error>
<error>
<code>86202</code>
<text>缺少会话名</text>
</error>
<error>
<code>86203</code>
<text>缺少会话管理员</text>
</error>
<error>
<code>86204</code>
<text>缺少成员</text>
</error>
<error>
<code>86205</code>
<text>非法的会话ID长度</text>
</error>
<error>
<code>86206</code>
<text>非法的会话ID数值</text>
</error>
<error>
<code>86207</code>
<text>会话管理员不在用户列表中</text>
</error>
<error>
<code>86208</code>
<text>消息服务未开启</text>
</error>
<error>
<code>86209</code>
<text>缺少操作者</text>
</error>
<error>
<code>86210</code>
<text>缺少会话参数</text>
</error>
<error>
<code>86211</code>
<text>缺少会话类型(单聊或者群聊)</text>
</error>
<error>
<code>86213</code>
<text>缺少发件人</text>
</error>
<error>
<code>86214</code>
<text>非法的会话类型</text>
</error>
<error>
<code>86215</code>
<text>会话已存在</text>
</error>
<error>
<code>86216</code>
<text>非法会话成员</text>
</error>
<error>
<code>86217</code>
<text>会话操作者不在成员列表中</text>
</error>
<error>
<code>86218</code>
<text>非法会话发件人</text>
</error>
<error>
<code>86219</code>
<text>非法会话收件人</text>
</error>
<error>
<code>86220</code>
<text>非法会话操作者</text>
</error>
<error>
<code>86221</code>
<text>单聊模式下,发件人与收件人不能为同一人</text>
</error>
<error>
<code>86222</code>
<text>不允许消息服务访问的API</text>
</error> </error>
<!-- 语义理解API错误 --> <!-- 语义理解API错误 -->
<error> <error>

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
/** /**
@ -33,7 +34,7 @@ public class Article implements Serializable {
/** /**
* 图片链接支持JPGPNG格式较好的效果为大图360*200小图200*200 * 图片链接支持JPGPNG格式较好的效果为大图360*200小图200*200
*/ */
@JSONField(name = "picurl") @JSONField(name = "pic_url")
@XmlElement(name = "PicUrl") @XmlElement(name = "PicUrl")
private String picUrl; private String picUrl;
/** /**
@ -42,7 +43,11 @@ public class Article implements Serializable {
@XmlElement(name = "Url") @XmlElement(name = "Url")
private String url; private String url;
public Article(String title, String desc, String picUrl, String url) { @JSONCreator
public Article(@JSONField(name = "title") String title,
@JSONField(name = "description") String desc,
@JSONField(name = "pic_url") String picUrl,
@JSONField(name = "url") String url) {
this.title = title; this.title = title;
this.desc = desc; this.desc = desc;
this.picUrl = picUrl; this.picUrl = picUrl;

View File

@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.tuple;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
/** /**
@ -32,7 +33,8 @@ public class Card implements MassTuple {
@XmlElement(name = "CardId") @XmlElement(name = "CardId")
private String cardId; private String cardId;
public Card(String cardId) { @JSONCreator
public Card(@JSONField(name = "card_id") String cardId) {
this.cardId = cardId; this.cardId = cardId;
} }

View File

@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.tuple;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
/** /**
@ -32,7 +33,8 @@ public class File implements NotifyTuple {
@XmlElement(name = "MediaId") @XmlElement(name = "MediaId")
private String mediaId; private String mediaId;
public File(String mediaId) { @JSONCreator
public File(@JSONField(name = "media_id") String mediaId) {
this.mediaId = mediaId; this.mediaId = mediaId;
} }

View File

@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.tuple;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
/** /**
@ -32,7 +33,8 @@ public class Image implements MassTuple, NotifyTuple {
@XmlElement(name = "MediaId") @XmlElement(name = "MediaId")
private String mediaId; private String mediaId;
public Image(String mediaId) { @JSONCreator
public Image(@JSONField(name = "media_id")String mediaId) {
this.mediaId = mediaId; this.mediaId = mediaId;
} }

View File

@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.tuple;
import java.io.Serializable; import java.io.Serializable;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
/** /**
@ -57,7 +58,10 @@ public class MpArticle implements Serializable {
@JSONField(name = "cover_url") @JSONField(name = "cover_url")
private String coverUrl; private String coverUrl;
public MpArticle(String thumbMediaId, String title, String content) { @JSONCreator
public MpArticle(@JSONField(name = "thumb_media_id") String thumbMediaId,
@JSONField(name = "title") String title,
@JSONField(name = "content") String content) {
this.thumbMediaId = thumbMediaId; this.thumbMediaId = thumbMediaId;
this.title = title; this.title = title;
this.content = content; this.content = content;

View File

@ -43,7 +43,6 @@ public class MpNews implements MassTuple, NotifyTuple {
/** /**
* 图文列表 * 图文列表
*/ */
@JSONField(serialize = false)
@XmlTransient @XmlTransient
private LinkedList<MpArticle> articles; private LinkedList<MpArticle> articles;

View File

@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.tuple;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
/** /**
@ -32,7 +33,8 @@ public class MpVideo implements MassTuple {
@XmlElement(name = "MediaId") @XmlElement(name = "MediaId")
private String mediaId; private String mediaId;
public MpVideo(String mediaId) { @JSONCreator
public MpVideo(@JSONField(name = "media_id") String mediaId) {
this.mediaId = mediaId; this.mediaId = mediaId;
} }

View File

@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.tuple;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
/** /**
@ -39,13 +40,13 @@ public class Music implements NotifyTuple {
/** /**
* 音乐链接 * 音乐链接
*/ */
@JSONField(name = "musicurl") @JSONField(name = "music_url")
@XmlElement(name = "MusicUrl") @XmlElement(name = "MusicUrl")
private String musicUrl; private String musicUrl;
/** /**
* 高质量音乐链接WIFI环境优先使用该链接播放音乐 * 高质量音乐链接WIFI环境优先使用该链接播放音乐
*/ */
@JSONField(name = "hqmusicurl") @JSONField(name = "hq_music_url")
@XmlElement(name = "HQMusicUrl") @XmlElement(name = "HQMusicUrl")
private String hqMusicUrl; private String hqMusicUrl;
/** /**
@ -55,12 +56,16 @@ public class Music implements NotifyTuple {
@XmlElement(name = "ThumbMediaId") @XmlElement(name = "ThumbMediaId")
private String thumbMediaId; private String thumbMediaId;
public Music(String thumbMediaId) { @JSONCreator
public Music(@JSONField(name = "thumb_media_id") String thumbMediaId) {
this.thumbMediaId = thumbMediaId; this.thumbMediaId = thumbMediaId;
} }
public Music(String title, String desc, String musicUrl, String hqMusicUrl, public Music(@JSONField(name = "title") String title,
String thumbMediaId) { @JSONField(name = "description") String desc,
@JSONField(name = "music_url") String musicUrl,
@JSONField(name = "hq_music_url") String hqMusicUrl,
@JSONField(name = "thumb_media_id") String thumbMediaId) {
this.title = title; this.title = title;
this.desc = desc; this.desc = desc;
this.musicUrl = musicUrl; this.musicUrl = musicUrl;

View File

@ -1,5 +1,7 @@
package com.foxinmy.weixin4j.tuple; package com.foxinmy.weixin4j.tuple;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;
/** /**
* 文本对象 * 文本对象
@ -27,7 +29,8 @@ public class Text implements MassTuple, NotifyTuple {
*/ */
private String content; private String content;
public Text(String content) { @JSONCreator
public Text(@JSONField(name = "content") String content) {
this.content = content; this.content = content;
} }

View File

@ -3,6 +3,7 @@ package com.foxinmy.weixin4j.tuple;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlTransient;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
/** /**
@ -50,19 +51,37 @@ public class Video implements NotifyTuple {
@XmlElement(name = "Description") @XmlElement(name = "Description")
private String desc; private String desc;
public Video(String mediaId) { @JSONCreator
public Video(@JSONField(name = "media_id") String mediaId) {
this.mediaId = mediaId; this.mediaId = mediaId;
} }
/**
* 公众平台
*
* @param mediaId
* @param thumbMediaId
*/
public Video(String mediaId, String thumbMediaId) { public Video(String mediaId, String thumbMediaId) {
this(mediaId, thumbMediaId, null, null); this(mediaId, thumbMediaId, null, null);
} }
/**
* 企业号
*
* @param mediaId
* @param title
* @param desc
*/
public Video(String mediaId, String title, String desc) { public Video(String mediaId, String title, String desc) {
this(mediaId, null, title, desc); this(mediaId, null, title, desc);
} }
public Video(String mediaId, String thumbMediaId, String title, String desc) { @JSONCreator
public Video(@JSONField(name = "media_id") String mediaId,
@JSONField(name = "thumb_media_id") String thumbMediaId,
@JSONField(name = "title") String title,
@JSONField(name = "description") String desc) {
this.mediaId = mediaId; this.mediaId = mediaId;
this.thumbMediaId = thumbMediaId; this.thumbMediaId = thumbMediaId;
this.title = title; this.title = title;

View File

@ -1,5 +1,8 @@
package com.foxinmy.weixin4j.tuple; package com.foxinmy.weixin4j.tuple;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;
/** /**
* 语音对象 * 语音对象
* <p> * <p>
@ -21,7 +24,8 @@ public class Voice extends Image implements NotifyTuple {
return "voice"; return "voice";
} }
public Voice(String mediaId) { @JSONCreator
public Voice(@JSONField(name = "media_id") String mediaId) {
super(mediaId); super(mediaId);
} }
} }

View File

@ -65,6 +65,9 @@ public class NotifyApi extends MpApi {
throws WeixinException { throws WeixinException {
NotifyTuple tuple = notify.getTuple(); NotifyTuple tuple = notify.getTuple();
String msgtype = tuple.getMessageType(); String msgtype = tuple.getMessageType();
if ("mpnews".equals(msgtype)) {
throw new WeixinException("only support news message");
}
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put("touser", notify.getTouser()); obj.put("touser", notify.getTouser());
obj.put("msgtype", msgtype); obj.put("msgtype", msgtype);

View File

@ -38,10 +38,9 @@ public class NotifyMessage implements Serializable {
/** /**
* 消息对象 * 消息对象
*/ */
@JSONField(serialize = false)
private NotifyTuple tuple; private NotifyTuple tuple;
/** /**
* id参数 * 发送对象
*/ */
@JSONField(serialize = false) @JSONField(serialize = false)
private IdParameter target; private IdParameter target;