weixin4j-qy:创建标签时可以指定ID
This commit is contained in:
parent
98a86108ae
commit
4ab6fef02e
@ -367,4 +367,8 @@
|
||||
|
||||
+ **weixin4j-qy**: 新增[媒体素材接口](weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/MediaApi.java)
|
||||
|
||||
+ released 1.5.1
|
||||
+ released 1.5.1
|
||||
|
||||
* 2015-07-22
|
||||
|
||||
+ **weixin4j-qy**: 创建标签时可以指定ID
|
||||
@ -56,7 +56,7 @@ public class Music implements NotifyTuple {
|
||||
private String thumbMediaId;
|
||||
|
||||
public Music(String thumbMediaId) {
|
||||
this(null, null, null, null, thumbMediaId);
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
}
|
||||
|
||||
public Music(String title, String desc, String musicUrl, String hqMusicUrl,
|
||||
|
||||
@ -5,17 +5,18 @@ import com.foxinmy.weixin4j.http.ContentType;
|
||||
/**
|
||||
* 上传的媒体类型</br>
|
||||
* <p>
|
||||
* 公众平台上传限制:</br> 图片(image): 128K,支持JPG,PNG格式</br>
|
||||
* 语音(voice):256K,播放长度不超过60s,支持AMR\MP3格式</br> 视频(video):1MB,支持MP4格式</br>
|
||||
* 公众平台上传限制:</br> 图片(image): 2MB,支持bmp/png/jpeg/jpg/gif格式</br>
|
||||
* 语音(voice):2MB,播放长度不超过60s,支持mp3/wma/wav/amr格式</br>
|
||||
* 视频(video):10MB,支持rm/rmvb/wmv/avi/mpg/mpeg/mp4格式</br>
|
||||
* 缩略图(thumb):64KB,支持JPG格式</br>
|
||||
* </p>
|
||||
* <p>
|
||||
* 企业号上传限制:</br> 图片(image):1MB,支持JPG格式</br>
|
||||
* 语音(voice):2MB,播放长度不超过60s,支持AMR格式</br> 视频(video):10MB,支持MP4格式</br>
|
||||
* 普通文件(file):20MB</br>
|
||||
* 企业号上传限制:</br> 图片(image):1MB,支持bmp/png/jpeg/jpg/gif格式</br>
|
||||
* 语音(voice):2MB,播放长度不超过60s,支持mp3/wma/wav/amr格式</br>
|
||||
* 视频(video):10MB,支持rm/rmvb/wmv/avi/mpg/mpeg/mp4格式</br> 普通文件(file):20MB</br>
|
||||
* </p>
|
||||
* <p>
|
||||
* <font color='red'>媒体文件在后台保存时间为3天,即3天后media_id失效</font>
|
||||
* <font color='red'>临时媒体文件在后台保存时间为3天,即3天后media_id失效</font>
|
||||
* </p>
|
||||
*
|
||||
* @author jy.hu
|
||||
|
||||
@ -78,7 +78,7 @@ public class MediaApi extends MpApi {
|
||||
mediaType = MediaType.image;
|
||||
} else if ("mp3/wma/wav/amr".contains(mediaTypeKey)) {
|
||||
mediaType = MediaType.voice;
|
||||
} else if ("mp4".equals(mediaTypeKey)) {
|
||||
} else if ("rm/rmvb/wmv/avi/mpg/mpeg/mp4".equals(mediaTypeKey)) {
|
||||
mediaType = MediaType.video;
|
||||
} else {
|
||||
throw new WeixinException("cannot handle mediaType:" + mediaTypeKey);
|
||||
|
||||
@ -74,4 +74,8 @@
|
||||
|
||||
+ 新增[媒体素材接口](src/main/java/com/foxinmy/weixin4j/qy/api/MediaApi.java)
|
||||
|
||||
+ released 1.5.1
|
||||
+ released 1.5.1
|
||||
|
||||
* 2015-07-22
|
||||
|
||||
+ 创建标签时可以指定ID
|
||||
@ -702,16 +702,17 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 创建标签(创建的标签属于管理组;默认为未加锁状态)
|
||||
*
|
||||
* @param tagName
|
||||
* 标签名称
|
||||
* @param tag
|
||||
* 标签对象;</br>标签名称,长度为1~64个字节,标签名不可与其他标签重名;</br>标签id,整型,
|
||||
* 指定此参数时新增的标签会生成对应的标签id,不指定时则以目前最大的id自增。
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E5.88.9B.E5.BB.BA.E6.A0.87.E7.AD.BE">创建标签说明</a>
|
||||
* @see com.foxinmy.weixin4j.qy.api.TagApi
|
||||
* @return 标签ID
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public int createTag(String tagName) throws WeixinException {
|
||||
return tagApi.createTag(tagName);
|
||||
public int createTag(Tag tag) throws WeixinException {
|
||||
return tagApi.createTag(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -83,7 +83,7 @@ public class MediaApi extends QyApi {
|
||||
mediaType = MediaType.image;
|
||||
} else if ("mp3/wma/wav/amr".contains(mediaTypeKey)) {
|
||||
mediaType = MediaType.voice;
|
||||
} else if ("mp4".equals(mediaTypeKey)) {
|
||||
} else if ("rm/rmvb/wmv/avi/mpg/mpeg/mp4".equals(mediaTypeKey)) {
|
||||
mediaType = MediaType.video;
|
||||
} else {
|
||||
mediaType = MediaType.file;
|
||||
|
||||
@ -32,26 +32,32 @@ public class TagApi extends QyApi {
|
||||
/**
|
||||
* 创建标签(创建的标签属于管理组;默认为加锁状态。加锁状态下只有本管理组才可以增删成员,解锁状态下其它管理组也可以增删成员)
|
||||
*
|
||||
* @param tagName
|
||||
* 标签名称
|
||||
* @param tag
|
||||
* 标签对象;</br>标签名称,长度为1~64个字节,标签名不可与其他标签重名;</br>标签id,整型,
|
||||
* 指定此参数时新增的标签会生成对应的标签id,不指定时则以目前最大的id自增。
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E5.88.9B.E5.BB.BA.E6.A0.87.E7.AD.BE">创建标签说明</a>
|
||||
* @return 标签ID
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public int createTag(String tagName) throws WeixinException {
|
||||
public int createTag(Tag tag) throws WeixinException {
|
||||
String tag_create_uri = getRequestUri("tag_create_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(tag);
|
||||
if (obj.getIntValue("tagid") <= 0) {
|
||||
obj.remove("tagid");
|
||||
}
|
||||
WeixinResponse response = weixinClient.post(
|
||||
String.format(tag_create_uri, token.getAccessToken()),
|
||||
String.format("{\"tagname\":\"%s\"}", tagName));
|
||||
obj.toJSONString());
|
||||
return response.getAsJson().getIntValue("tagid");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新标签(管理组必须是指定标签的创建者)
|
||||
*
|
||||
* @param tag 标签信息
|
||||
* @param tag
|
||||
* 标签信息
|
||||
* @see <a href=
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E6.9B.B4.E6.96.B0.E6.A0.87.E7.AD.BE.E5.90.8D.E5.AD.97"
|
||||
* >更新标签说明</a>
|
||||
@ -81,8 +87,8 @@ public class TagApi extends QyApi {
|
||||
public JsonResult deleteTag(int tagId) throws WeixinException {
|
||||
String tag_delete_uri = getRequestUri("tag_delete_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinClient.post(String.format(tag_delete_uri,
|
||||
token.getAccessToken(), tagId));
|
||||
WeixinResponse response = weixinClient.post(String.format(
|
||||
tag_delete_uri, token.getAccessToken(), tagId));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
@ -118,8 +124,8 @@ public class TagApi extends QyApi {
|
||||
public List<User> getTagUsers(int tagId) throws WeixinException {
|
||||
String tag_get_user_uri = getRequestUri("tag_get_user_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinClient.post(String.format(tag_get_user_uri,
|
||||
token.getAccessToken(), tagId));
|
||||
WeixinResponse response = weixinClient.post(String.format(
|
||||
tag_get_user_uri, token.getAccessToken(), tagId));
|
||||
return JSON.parseArray(response.getAsJson().getString("userlist"),
|
||||
User.class);
|
||||
}
|
||||
|
||||
@ -32,6 +32,10 @@ public class Tag implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
public Tag(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Tag(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
||||
@ -32,7 +32,7 @@ public class TagTest extends TokenTest {
|
||||
|
||||
@Test
|
||||
public void create() throws WeixinException {
|
||||
int tagId = tagApi.createTag("coder");
|
||||
int tagId = tagApi.createTag(new Tag("coder"));
|
||||
Assert.assertTrue(tagId > 0);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user