调整了Tuple消息元件&新增视频上传接口&新增企业好聊天服务接口
This commit is contained in:
@@ -48,8 +48,8 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.tuple.MassTuple;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.tuple.MpVideo;
|
||||
import com.foxinmy.weixin4j.tuple.Tuple;
|
||||
import com.foxinmy.weixin4j.tuple.Video;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
|
||||
/**
|
||||
@@ -145,6 +145,29 @@ public class WeixinProxy {
|
||||
return mediaApi.uploadImage(is, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传群发中的视频素材
|
||||
*
|
||||
* @param is
|
||||
* 图片数据流
|
||||
* @param fileName
|
||||
* 文件名 为空时将自动生成
|
||||
* @param title
|
||||
* 视频标题 非空
|
||||
* @param description
|
||||
* 视频描述 可为空
|
||||
* @return 群发视频消息对象
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html">高级群发</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.MpVideo
|
||||
*/
|
||||
public MpVideo uploadVideo(InputStream is, String fileName, String title,
|
||||
String description) throws WeixinException {
|
||||
return mediaApi.uploadVideo(is, fileName, title, description);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传媒体文件 </br> <font color="red">此接口只包含图片、语音、缩略图、视频(临时)四种媒体类型的上传</font>
|
||||
* <p>
|
||||
@@ -640,25 +663,6 @@ public class WeixinProxy {
|
||||
return massApi.uploadArticle(articles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传分组群发的视频素材
|
||||
*
|
||||
* @param video
|
||||
* 视频对象 其中mediaId媒体文件中上传得到的Id 不能为空
|
||||
* @return 上传后的ID
|
||||
* @throws WeixinException
|
||||
*
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html">高级群发</a>
|
||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
||||
* @see com.foxinmy.weixin4j.tuple.Video
|
||||
* @see com.foxinmy.weixin4j.tuple.MpVideo
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File)}
|
||||
*/
|
||||
public String uploadMassVideo(Video video) throws WeixinException {
|
||||
return massApi.uploadVideo(video);
|
||||
}
|
||||
|
||||
/**
|
||||
* 群发消息
|
||||
* <p>
|
||||
@@ -673,7 +677,7 @@ public class WeixinProxy {
|
||||
* 选择false可根据group_id发送给指定群组的用户
|
||||
* @param groupId
|
||||
* 分组ID
|
||||
* @return 群发后的消息ID
|
||||
* @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
||||
* @see com.foxinmy.weixin4j.tuple.Text
|
||||
@@ -687,7 +691,7 @@ public class WeixinProxy {
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html#.E6.A0.B9.E6.8D.AE.E5.88.86.E7.BB.84.E8.BF.9B.E8.A1.8C.E7.BE.A4.E5.8F.91.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91">根据分组群发</a>
|
||||
*/
|
||||
public String massByGroupId(MassTuple tuple, boolean isToAll, int groupId)
|
||||
public String[] massByGroupId(MassTuple tuple, boolean isToAll, int groupId)
|
||||
throws WeixinException {
|
||||
return massApi.massByGroupId(tuple, isToAll, groupId);
|
||||
}
|
||||
@@ -699,14 +703,14 @@ public class WeixinProxy {
|
||||
* 图文列表
|
||||
* @param groupId
|
||||
* 分组ID
|
||||
* @return 群发后的消息ID
|
||||
* @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
|
||||
* @see {@link #massByGroupId(Tuple,int)}
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html#.E6.A0.B9.E6.8D.AE.E5.88.86.E7.BB.84.E8.BF.9B.E8.A1.8C.E7.BE.A4.E5.8F.91.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91">根据分组群发</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String massArticleByGroupId(List<MpArticle> articles, int groupId)
|
||||
public String[] massArticleByGroupId(List<MpArticle> articles, int groupId)
|
||||
throws WeixinException {
|
||||
return massApi.massArticleByGroupId(articles, groupId);
|
||||
}
|
||||
@@ -723,7 +727,7 @@ public class WeixinProxy {
|
||||
* 消息元件
|
||||
* @param openIds
|
||||
* openId列表
|
||||
* @return 群发后的消息ID
|
||||
* @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.model.User
|
||||
* @see com.foxinmy.weixin4j.tuple.Text
|
||||
@@ -738,7 +742,7 @@ public class WeixinProxy {
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File)}
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.UserApi#getUser(String)}
|
||||
*/
|
||||
public String massByOpenIds(MassTuple tuple, String... openIds)
|
||||
public String[] massByOpenIds(MassTuple tuple, String... openIds)
|
||||
throws WeixinException {
|
||||
return massApi.massByOpenIds(tuple, openIds);
|
||||
}
|
||||
@@ -750,14 +754,14 @@ public class WeixinProxy {
|
||||
* 图文列表
|
||||
* @param openIds
|
||||
* openId列表
|
||||
* @return 群发后的消息ID
|
||||
* @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html#.E6.A0.B9.E6.8D.AEOpenID.E5.88.97.E8.A1.A8.E7.BE.A4.E5.8F.91.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8D.E5.8F.AF.E7.94.A8.EF.BC.8C.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.8F.AF.E7.94.A8.E3.80.91">根据openid群发</a>
|
||||
* @see {@link #massByOpenIds(Tuple,String...)}
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String massArticleByOpenIds(List<MpArticle> articles,
|
||||
public String[] massArticleByOpenIds(List<MpArticle> articles,
|
||||
String... openIds) throws WeixinException {
|
||||
return massApi.massArticleByOpenIds(articles, openIds);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.foxinmy.weixin4j.tuple.MassTuple;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.tuple.MpNews;
|
||||
import com.foxinmy.weixin4j.tuple.Tuple;
|
||||
import com.foxinmy.weixin4j.tuple.Video;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
@@ -61,28 +60,6 @@ public class MassApi extends MpApi {
|
||||
return response.getAsJson().getString("media_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传分组群发的视频素材
|
||||
*
|
||||
* @param video
|
||||
* 视频对象 其中mediaId媒体文件中上传得到的Id 不能为空
|
||||
* @return 上传后的ID 可用于群发视频消息
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html">高级群发</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.Video
|
||||
* @see com.foxinmy.weixin4j.tuple.MpVideo
|
||||
*/
|
||||
public String uploadVideo(Video video) throws WeixinException {
|
||||
String video_upload_uri = getRequestUri("video_upload_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinClient.post(
|
||||
String.format(video_upload_uri, token.getAccessToken()),
|
||||
JSON.toJSONString(video));
|
||||
|
||||
return response.getAsJson().getString("media_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组群发
|
||||
* <p>
|
||||
@@ -97,7 +74,7 @@ public class MassApi extends MpApi {
|
||||
* 选择false可根据group_id发送给指定群组的用户
|
||||
* @param groupId
|
||||
* 分组ID
|
||||
* @return 群发后的消息ID
|
||||
* @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
||||
* @see com.foxinmy.weixin4j.tuple.Text
|
||||
@@ -105,12 +82,13 @@ public class MassApi extends MpApi {
|
||||
* @see com.foxinmy.weixin4j.tuple.Voice
|
||||
* @see com.foxinmy.weixin4j.tuple.MpVideo
|
||||
* @see com.foxinmy.weixin4j.tuple.MpNews
|
||||
* @see com.foxinmy.weixin4j.tuple.Card
|
||||
* @see com.foxinmy.weixin4j.tuple.MassTuple
|
||||
* @see {@link GroupApi#getGroups()}
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html#.E6.A0.B9.E6.8D.AE.E5.88.86.E7.BB.84.E8.BF.9B.E8.A1.8C.E7.BE.A4.E5.8F.91.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91">根据分组群发</a>
|
||||
*/
|
||||
public String massByGroupId(MassTuple tuple, boolean isToAll, int groupId)
|
||||
public String[] massByGroupId(MassTuple tuple, boolean isToAll, int groupId)
|
||||
throws WeixinException {
|
||||
if (tuple instanceof MpNews) {
|
||||
MpNews _news = (MpNews) tuple;
|
||||
@@ -139,7 +117,9 @@ public class MassApi extends MpApi {
|
||||
String.format(mass_group_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
|
||||
return response.getAsJson().getString("msg_id");
|
||||
obj = response.getAsJson();
|
||||
return new String[] { obj.getString("msg_id"),
|
||||
obj.getString("msg_data_id") };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,14 +129,14 @@ public class MassApi extends MpApi {
|
||||
* 图文列表
|
||||
* @param groupId
|
||||
* 分组ID
|
||||
* @return 群发后的消息ID
|
||||
* @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现。
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html#.E6.A0.B9.E6.8D.AE.E5.88.86.E7.BB.84.E8.BF.9B.E8.A1.8C.E7.BE.A4.E5.8F.91.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91">根据分组群发</a>
|
||||
* @see {@link #massByGroupId(Tuple,int)}
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String massArticleByGroupId(List<MpArticle> articles, int groupId)
|
||||
public String[] massArticleByGroupId(List<MpArticle> articles, int groupId)
|
||||
throws WeixinException {
|
||||
String mediaId = uploadArticle(articles);
|
||||
return massByGroupId(new MpNews(mediaId), false, groupId);
|
||||
@@ -169,7 +149,7 @@ public class MassApi extends MpApi {
|
||||
* 消息元件
|
||||
* @param openIds
|
||||
* openId列表
|
||||
* @return 群发后的消息ID
|
||||
* @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.model.User
|
||||
* @see com.foxinmy.weixin4j.tuple.Text
|
||||
@@ -177,12 +157,13 @@ public class MassApi extends MpApi {
|
||||
* @see com.foxinmy.weixin4j.tuple.Voice
|
||||
* @see com.foxinmy.weixin4j.tuple.MpVideo
|
||||
* @see com.foxinmy.weixin4j.tuple.MpNews
|
||||
* @see com.foxinmy.weixin4j.tuple.Card
|
||||
* @see com.foxinmy.weixin4j.tuple.MassTuple
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html#.E6.A0.B9.E6.8D.AEOpenID.E5.88.97.E8.A1.A8.E7.BE.A4.E5.8F.91.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8D.E5.8F.AF.E7.94.A8.EF.BC.8C.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.8F.AF.E7.94.A8.E3.80.91">根据openid群发</a>
|
||||
* @see {@link UserApi#getUser(String)}
|
||||
*/
|
||||
public String massByOpenIds(MassTuple tuple, String... openIds)
|
||||
public String[] massByOpenIds(MassTuple tuple, String... openIds)
|
||||
throws WeixinException {
|
||||
if (tuple instanceof MpNews) {
|
||||
MpNews _news = (MpNews) tuple;
|
||||
@@ -205,7 +186,9 @@ public class MassApi extends MpApi {
|
||||
String.format(mass_openid_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
|
||||
return response.getAsJson().getString("msg_id");
|
||||
obj = response.getAsJson();
|
||||
return new String[] { obj.getString("msg_id"),
|
||||
obj.getString("msg_data_id") };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,14 +198,14 @@ public class MassApi extends MpApi {
|
||||
* 图文列表
|
||||
* @param openIds
|
||||
* openId列表
|
||||
* @return 群发后的消息ID
|
||||
* @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中.
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html#.E6.A0.B9.E6.8D.AEOpenID.E5.88.97.E8.A1.A8.E7.BE.A4.E5.8F.91.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8D.E5.8F.AF.E7.94.A8.EF.BC.8C.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.8F.AF.E7.94.A8.E3.80.91">根据openid群发</a>
|
||||
* @see {@link #massByOpenIds(Tuple,String...)}
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String massArticleByOpenIds(List<MpArticle> articles,
|
||||
public String[] massArticleByOpenIds(List<MpArticle> articles,
|
||||
String... openIds) throws WeixinException {
|
||||
String mediaId = uploadArticle(articles);
|
||||
return massByOpenIds(new MpNews(mediaId), openIds);
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.foxinmy.weixin4j.model.MediaUploadResult;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.tuple.MpVideo;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.ErrorUtil;
|
||||
@@ -92,6 +93,40 @@ public class MediaApi extends MpApi {
|
||||
return response.getAsJson().getString("url");
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传群发中的视频素材
|
||||
*
|
||||
* @param is
|
||||
* 图片数据流
|
||||
* @param fileName
|
||||
* 文件名 为空时将自动生成
|
||||
* @param title
|
||||
* 视频标题 非空
|
||||
* @param description
|
||||
* 视频描述 可为空
|
||||
* @return 群发视频消息对象
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html">高级群发</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.MpVideo
|
||||
*/
|
||||
public MpVideo uploadVideo(InputStream is, String fileName, String title,
|
||||
String description) throws WeixinException {
|
||||
MediaUploadResult uploadResult = uploadMedia(false, is, fileName);
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("media_id", uploadResult.getMediaId());
|
||||
obj.put("title", title);
|
||||
obj.put("description", description);
|
||||
String video_upload_uri = getRequestUri("video_upload_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinClient.post(
|
||||
String.format(video_upload_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
|
||||
String mediaId = response.getAsJson().getString("media_id");
|
||||
return new MpVideo(mediaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传媒体文件:图片(image)、语音(voice)、视频(video)和缩略图(thumb) </br> <font
|
||||
* color="red">此接口只包含图片、语音、缩略图、视频(临时)四种媒体类型的上传</font>
|
||||
|
||||
@@ -83,6 +83,9 @@ public class TmplApi extends MpApi {
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/17/304c1885ea66dbedf7dc170d84999a9d.html#.E5.8F.91.E9.80.81.E6.A8.A1.E6.9D.BF.E6.B6.88.E6.81.AF">模板消息</a>
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/2/def71e3ecb5706c132229ae505815966.html"
|
||||
* >运营规范</a>
|
||||
* @see com.foxinmy.weixin4j.mp.message.TemplateMessage
|
||||
* @seee com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
|
||||
*/
|
||||
|
||||
@@ -41,18 +41,10 @@ public class NotifyMessage implements Serializable {
|
||||
return touser;
|
||||
}
|
||||
|
||||
public void setTouser(String touser) {
|
||||
this.touser = touser;
|
||||
}
|
||||
|
||||
public NotifyTuple getTuple() {
|
||||
return tuple;
|
||||
}
|
||||
|
||||
public void setTuple(NotifyTuple tuple) {
|
||||
this.tuple = tuple;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NotifyMessage [touser=" + touser + ", tuple=" + tuple + "]";
|
||||
|
||||
Reference in New Issue
Block a user