新增media_id和view_limited两种菜单类型
This commit is contained in:
@@ -402,9 +402,11 @@ public class WeixinProxy {
|
||||
* 通过员工授权获取到的code,每次员工授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期
|
||||
* @param agentid
|
||||
* 跳转链接时所在的企业应用ID
|
||||
* @see com.foxinmy.weixin4j.qy.model.User
|
||||
* @see com.foxinmy.weixin4j.qy.api.UserApi
|
||||
* @return 成员对象
|
||||
* @see {@link com.foxinmy.weixin4j.qy.WeixinProxy#getUser(String)}
|
||||
* @see {@link com.foxinmy.weixin4j.qy.WeixinProxy#getUserIdByCode(String,int)}
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E8%8E%B7%E5%8F%96code">企业获取code</a>
|
||||
* @see <a
|
||||
@@ -415,6 +417,26 @@ public class WeixinProxy {
|
||||
return userApi.getUserByCode(code, agentid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取成员信息
|
||||
*
|
||||
* @param code
|
||||
* 通过员工授权获取到的code,每次员工授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期
|
||||
* @param agentid
|
||||
* 跳转链接时所在的企业应用ID
|
||||
* @return { "UserId":"USERID", "DeviceId":"DEVICEID" }
|
||||
* @see com.foxinmy.weixin4j.qy.api.UserApi
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E8%8E%B7%E5%8F%96code">企业获取code</a>
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E6%A0%B9%E6%8D%AEcode%E8%8E%B7%E5%8F%96%E6%88%90%E5%91%98%E4%BF%A1%E6%81%AF">根据code获取成员信息</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JSONObject getUserIdByCode(String code, int agentid)
|
||||
throws WeixinException {
|
||||
return userApi.getUserIdByCode(code, agentid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门成员
|
||||
*
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.foxinmy.weixin4j.qy.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.JSONPath;
|
||||
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
||||
import com.alibaba.fastjson.parser.deserializer.ParseProcess;
|
||||
import com.alibaba.fastjson.serializer.NameFilter;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.JsonResult;
|
||||
@@ -55,8 +60,13 @@ public class MenuApi extends QyApi {
|
||||
public String process(Object object, String name,
|
||||
Object value) {
|
||||
if (object instanceof Button && name.equals("content")) {
|
||||
if (((Button) object).getFormatType() == ButtonType.view) {
|
||||
ButtonType buttonType = ((Button) object)
|
||||
.getFormatType();
|
||||
if (buttonType == ButtonType.view) {
|
||||
return "url";
|
||||
} else if (buttonType == ButtonType.media_id
|
||||
|| buttonType == ButtonType.view_limited) {
|
||||
return "media_id";
|
||||
} else {
|
||||
return "key";
|
||||
}
|
||||
@@ -85,19 +95,20 @@ public class MenuApi extends QyApi {
|
||||
Response response = request.get(String.format(menu_get_uri,
|
||||
token.getAccessToken(), agentid));
|
||||
|
||||
String text = JSON.toJSONString(
|
||||
response.getAsJson().getJSONObject("menu")
|
||||
.getJSONArray("button"), new NameFilter() {
|
||||
@Override
|
||||
public String process(Object object, String name,
|
||||
Object value) {
|
||||
if (name.equals("url") || name.equals("key")) {
|
||||
return "content";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
});
|
||||
return JSON.parseArray(text, Button.class);
|
||||
JSONArray buttons = response.getAsJson().getJSONObject("menu")
|
||||
.getJSONArray("button");
|
||||
List<Button> buttonList = new ArrayList<Button>(buttons.size());
|
||||
ParseProcess processor = new ExtraProcessor() {
|
||||
@Override
|
||||
public void processExtra(Object object, String key, Object value) {
|
||||
JSONPath.set(object, "$.content", value);
|
||||
}
|
||||
};
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
buttonList.add(JSON.parseObject(buttons.getString(i), Button.class,
|
||||
processor));
|
||||
}
|
||||
return buttonList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,9 +112,11 @@ public class UserApi extends QyApi {
|
||||
* 通过员工授权获取到的code,每次员工授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期
|
||||
* @param agentid
|
||||
* 跳转链接时所在的企业应用ID
|
||||
* @see com.foxinmy.weixin4j.qy.model.User
|
||||
* @see com.foxinmy.weixin4j.qy.api.UserApi
|
||||
* @return 成员对象
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.UserApi#getUser(String)}
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.UserApi#getUserIdByCode(String,int)}
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E8%8E%B7%E5%8F%96code">企业获取code</a>
|
||||
* @see <a
|
||||
@@ -122,11 +124,30 @@ public class UserApi extends QyApi {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public User getUserByCode(String code, int agentid) throws WeixinException {
|
||||
return getUser(getUserIdByCode(code, agentid).getString("UserId"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取成员信息
|
||||
*
|
||||
* @param code
|
||||
* 通过员工授权获取到的code,每次员工授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期
|
||||
* @param agentid
|
||||
* 跳转链接时所在的企业应用ID
|
||||
* @return { "UserId":"USERID", "DeviceId":"DEVICEID" }
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E8%8E%B7%E5%8F%96code">企业获取code</a>
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E6%A0%B9%E6%8D%AEcode%E8%8E%B7%E5%8F%96%E6%88%90%E5%91%98%E4%BF%A1%E6%81%AF">根据code获取成员信息</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JSONObject getUserIdByCode(String code, int agentid)
|
||||
throws WeixinException {
|
||||
String user_getid_uri = getRequestUri("user_getid_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Response response = request.post(String.format(user_getid_uri,
|
||||
token.getAccessToken(), code, agentid));
|
||||
return getUser(response.getAsJson().getString("UserId"));
|
||||
return response.getAsJson();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user