企业号变成了企业微信

This commit is contained in:
jinyu 2017-08-24 22:36:46 +08:00
parent e197e3cd73
commit 01fa30f0da
29 changed files with 1771 additions and 1843 deletions

View File

@ -33,9 +33,7 @@ import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
* @date 2015年6月22日
* @since JDK 1.6
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%88%E6%9D%83">
* 企业号第三方应用</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10968"> 企业号第三方应用</a>
*/
public class WeixinSuiteProxy {
@ -169,8 +167,7 @@ public class WeixinSuiteProxy {
* 套件ID
* @param suiteTicket
* 套件ticket内容
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%9B%9E%E8%B0%83%E5%8D%8F%E8%AE%AE#.E6.8E.A8.E9.80.81suite_ticket.E5.8D.8F.E8.AE.AE">
* @see <a href= "http://work.weixin.qq.com/api/doc#10982/推送suite_ticket">
* 推送suite_ticket协议</a>
* @throws WeixinException
*/
@ -213,9 +210,7 @@ public class WeixinSuiteProxy {
* @see com.foxinmy.weixin4j.qy.api.SuiteApi#getTicketManager()
* @see com.foxinmy.weixin4j.qy.api.SuiteApi#getPreCodeManager()
* @see com.foxinmy.weixin4j.qy.api.SuiteApi#exchangeAuthInfo(String)
* @see <a href="http://qydev.weixin.qq.com/wiki/index.php?title
* =%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%AE%A1%E7%90%86%E5%91%98%E6%
* 8E%88%E6%9D%83%E5%BA%94%E7%94%A8">企业号第三方应用套件授权</a>
* @see <a href="http://work.weixin.qq.com/api/doc#10974">企业号第三方应用套件授权</a>
* @return 请求授权的URL
* @throws WeixinException
*/

View File

@ -22,8 +22,7 @@ import com.foxinmy.weixin4j.token.TokenManager;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年3月16日
* @since JDK 1.6
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8">管理应用接口说明</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10025">管理应用接口说明</a>
*/
public class AgentApi extends QyApi {
private final TokenManager tokenManager;
@ -39,15 +38,14 @@ public class AgentApi extends QyApi {
* 授权方应用id
* @return 应用信息
* @see com.foxinmy.weixin4j.qy.model.AgentInfo
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8">企业号应用的信息</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10087">企业号应用的信息</a>
* @throws WeixinException
*/
public AgentInfo getAgent(int agentid) throws WeixinException {
String agent_get_uri = getRequestUri("agent_get_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(agent_get_uri,
token.getAccessToken(), agentid));
WeixinResponse response = weixinExecutor.get(String.format(
agent_get_uri, token.getAccessToken(), agentid));
JSONObject jsonObj = response.getAsJson();
AgentInfo agent = JSON.toJavaObject(jsonObj, AgentInfo.class);
agent.setAllowUsers(JSON.parseArray(
@ -67,8 +65,7 @@ public class AgentApi extends QyApi {
* @param agentSet
* 设置信息
* @see com.foxinmy.weixin4j.qy.model.AgentSetter
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%AE%BE%E7%BD%AE%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8">设置企业号信息</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10088">设置企业号信息</a>
* @return 处理结果
* @throws WeixinException
*/
@ -101,16 +98,15 @@ public class AgentApi extends QyApi {
* 获取应用概况列表
*
* @see com.foxinmy.weixin4j.qy.model.AgentOverview
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E6%A6%82%E5%86%B5%E5%88%97%E8%A1%A8">获取应用概况</a>
* @see <a href="https://work.weixin.qq.com/api/doc#11214">获取应用概况</a>
* @return 应用概况列表
* @throws WeixinException
*/
public List<AgentOverview> listAgentOverview() throws WeixinException {
String agent_list_uri = getRequestUri("agent_list_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(agent_list_uri,
token.getAccessToken()));
WeixinResponse response = weixinExecutor.get(String.format(
agent_list_uri, token.getAccessToken()));
return JSON.parseArray(response.getAsJson().getString("agentlist"),
AgentOverview.class);

View File

@ -20,8 +20,7 @@ import com.foxinmy.weixin4j.token.TokenManager;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年3月30日
* @since JDK 1.6
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3">批量任务</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10138">批量任务</a>
*/
public class BatchApi extends QyApi {
@ -77,8 +76,7 @@ public class BatchApi extends QyApi {
* @return 异步任务id最大长度为64字符
* @see {@link MediaApi#batchUploadUsers(java.util.List)}
* @see com.foxinmy.weixin4j.qy.model.Callback
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E5.A2.9E.E9.87.8F.E6.9B.B4.E6.96.B0.E6.88.90.E5.91.98">批量更新成员</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10138/增量更新成员">批量更新成员</a>
* @throws WeixinException
*/
public String syncUser(String mediaId, Callback callback)
@ -115,8 +113,7 @@ public class BatchApi extends QyApi {
* @return 异步任务id最大长度为64字符
* @see {@link MediaApi#batchUploadUsers(java.util.List)}
* @see com.foxinmy.weixin4j.qy.model.Callback
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E5.85.A8.E9.87.8F.E8.A6.86.E7.9B.96.E6.88.90.E5.91.98">批量覆盖成员</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10138/全量覆盖成员">批量覆盖成员</a>
* @throws WeixinException
*/
public String replaceUser(String mediaId, Callback callback)
@ -140,8 +137,7 @@ public class BatchApi extends QyApi {
* @return 异步任务id最大长度为64字符
* @see {@link MediaApi#batchUploadParties(java.util.List)}
* @see com.foxinmy.weixin4j.qy.model.Callback
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E5.85.A8.E9.87.8F.E8.A6.86.E7.9B.96.E9.83.A8.E9.97.A8">批量覆盖部门</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10138/全量覆盖部门">批量覆盖部门</a>
* @throws WeixinException
*/
public String replaceParty(String mediaId, Callback callback)

View File

@ -54,8 +54,6 @@ import com.foxinmy.weixin4j.util.StringUtil;
* @author jinyu(foxinmy@gmail.com)
* @date 2014年9月25日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">管理素材文件</a>
* @see com.foxinmy.weixin4j.type.MediaType
*/
public class MediaApi extends QyApi {
@ -113,8 +111,7 @@ public class MediaApi extends QyApi {
* 文件名
* @return 上传到微信服务器返回的媒体标识
* @see com.foxinmy.weixin4j.model.media.MediaUploadResult
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%B4%E6%97%B6%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">上传临时素材文件说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10112">上传临时素材文件说明</a>
* @see <a href=
* "http://http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">上传永久素材文件说明</a>
* @throws WeixinException
@ -192,8 +189,7 @@ public class MediaApi extends QyApi {
* 媒体ID
* @return 媒体下载结果
* @see com.foxinmy.weixin4j.model.media.MediaDownloadResult
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E4%B8%B4%E6%97%B6%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">获取临时媒体说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10115">获取临时媒体说明</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">获取永久媒体说明</a>
* @throws WeixinException
@ -436,8 +432,7 @@ public class MediaApi extends QyApi {
* 成员列表
* @see {@link BatchApi#syncUser(String,Callback)}
* @see {@link BatchApi#replaceUser(String,Callback)}
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E9.80.9A.E8.AE.AF.E5.BD.95.E6.9B.B4.E6.96.B0">批量任务</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10138">批量任务</a>
* @return 上传后的mediaId
* @throws WeixinException
*/
@ -451,8 +446,7 @@ public class MediaApi extends QyApi {
* @param parties
* 部门列表
* @see {@link BatchApi#replaceParty(String,Callback)}
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E9.80.9A.E8.AE.AF.E5.BD.95.E6.9B.B4.E6.96.B0">批量任务</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10138">批量任务</a>
* @return 上传后的mediaId
* @throws WeixinException
*/

View File

@ -29,99 +29,103 @@ import com.foxinmy.weixin4j.util.StringUtil;
*/
public class MenuApi extends QyApi {
private final TokenManager tokenManager;
private final TokenManager tokenManager;
public MenuApi(TokenManager tokenManager) {
this.tokenManager = tokenManager;
}
public MenuApi(TokenManager tokenManager) {
this.tokenManager = tokenManager;
}
/**
* 自定义菜单(管理员须拥有应用的管理权限 并且应用必须设置在回调模式)
*
* @param agentid
* 应用ID
*
* @param buttons
* 菜单列表
* @throws WeixinException
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%9B%E5%BB%BA%E5%BA%94%E7%94%A8%E8%8F%9C%E5%8D%95">
* 创建自定义菜单</a>
* @see com.foxinmy.weixin4j.model.Button
*/
public ApiResult createMenu(int agentid, List<Button> buttons) throws WeixinException {
String menu_create_uri = getRequestUri("menu_create_uri");
Token token = tokenManager.getCache();
JSONObject obj = new JSONObject();
obj.put("button", buttons);
WeixinResponse response = weixinExecutor.post(String.format(menu_create_uri, token.getAccessToken(), agentid),
JSON.toJSONString(obj, new NameFilter() {
@Override
public String process(Object object, String name, Object value) {
if (object instanceof Button && name.equals("content")
&& StringUtil.isNotBlank(((Button) object).getType())) {
ButtonType buttonType = ButtonType.valueOf(((Button) object).getType());
if (ButtonType.view == buttonType) {
return "url";
} else if (ButtonType.media_id == buttonType || ButtonType.view_limited == buttonType) {
return "media_id";
} else {
return "key";
}
}
return name;
}
}));
/**
* 自定义菜单(管理员须拥有应用的管理权限 并且应用必须设置在回调模式)
*
* @param agentid
* 应用ID
*
* @param buttons
* 菜单列表
* @throws WeixinException
* @see <a href= "https://work.weixin.qq.com/api/doc#10786"> 创建自定义菜单</a>
* @see com.foxinmy.weixin4j.model.Button
*/
public ApiResult createMenu(int agentid, List<Button> buttons)
throws WeixinException {
String menu_create_uri = getRequestUri("menu_create_uri");
Token token = tokenManager.getCache();
JSONObject obj = new JSONObject();
obj.put("button", buttons);
WeixinResponse response = weixinExecutor
.post(String.format(menu_create_uri, token.getAccessToken(),
agentid), JSON.toJSONString(obj, new NameFilter() {
@Override
public String process(Object object, String name,
Object value) {
if (object instanceof Button
&& name.equals("content")
&& StringUtil.isNotBlank(((Button) object)
.getType())) {
ButtonType buttonType = ButtonType
.valueOf(((Button) object).getType());
if (ButtonType.view == buttonType) {
return "url";
} else if (ButtonType.media_id == buttonType
|| ButtonType.view_limited == buttonType) {
return "media_id";
} else {
return "key";
}
}
return name;
}
}));
return response.getAsResult();
}
return response.getAsResult();
}
/**
* 查询菜单(管理员须拥有应用的管理权限 并且应用必须设置在回调模式)
*
* @param agentid
* 应用ID
* @return 菜单集合
* @throws WeixinException
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E8%8F%9C%E5%8D%95%E5%88%97%E8%A1%A8">
* 查询菜单</a>
* @see com.foxinmy.weixin4j.model.Button
*/
public List<Button> getMenu(int agentid) throws WeixinException {
String menu_get_uri = getRequestUri("menu_get_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(menu_get_uri, token.getAccessToken(), agentid));
JSONArray buttons = response.getAsJson().getJSONArray("button");
List<Button> buttonList = new ArrayList<Button>(buttons.size());
ParseProcess processor = new ExtraProcessor() {
@Override
public void processExtra(Object object, String key, Object value) {
((Button) object).setContent(String.valueOf(value));
}
};
for (int i = 0; i < buttons.size(); i++) {
buttonList.add(JSON.parseObject(buttons.getString(i), Button.class, processor));
}
return buttonList;
}
/**
* 查询菜单(管理员须拥有应用的管理权限 并且应用必须设置在回调模式)
*
* @param agentid
* 应用ID
* @return 菜单集合
* @throws WeixinException
* @see <a href= "https://work.weixin.qq.com/api/doc#10787"> 查询菜单</a>
* @see com.foxinmy.weixin4j.model.Button
*/
public List<Button> getMenu(int agentid) throws WeixinException {
String menu_get_uri = getRequestUri("menu_get_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
menu_get_uri, token.getAccessToken(), agentid));
JSONArray buttons = response.getAsJson().getJSONArray("button");
List<Button> buttonList = new ArrayList<Button>(buttons.size());
ParseProcess processor = new ExtraProcessor() {
@Override
public void processExtra(Object object, String key, Object value) {
((Button) object).setContent(String.valueOf(value));
}
};
for (int i = 0; i < buttons.size(); i++) {
buttonList.add(JSON.parseObject(buttons.getString(i), Button.class,
processor));
}
return buttonList;
}
/**
* 删除菜单(管理员须拥有应用的管理权限 并且应用必须设置在回调模式)
*
* @param agentid
* 应用ID
* @throws WeixinException
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%A0%E9%99%A4%E8%8F%9C%E5%8D%95">
* 删除菜单</a>
* @return 处理结果
*/
public ApiResult deleteMenu(int agentid) throws WeixinException {
String menu_delete_uri = getRequestUri("menu_delete_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(menu_delete_uri, token.getAccessToken(), agentid));
/**
* 删除菜单(管理员须拥有应用的管理权限 并且应用必须设置在回调模式)
*
* @param agentid
* 应用ID
* @throws WeixinException
* @see <a href= "https://work.weixin.qq.com/api/doc#10788"> 删除菜单</a>
* @return 处理结果
*/
public ApiResult deleteMenu(int agentid) throws WeixinException {
String menu_delete_uri = getRequestUri("menu_delete_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
menu_delete_uri, token.getAccessToken(), agentid));
return response.getAsResult();
}
return response.getAsResult();
}
}

View File

@ -26,10 +26,7 @@ import com.foxinmy.weixin4j.tuple.NotifyTuple;
* @author jinyu(foxinmy@gmail.com)
* @date 2014年11月21日
* @since JDK 1.6
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E">发送接口说明</a>
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%E5%8F%8A%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F">发送格式说明</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10167">发送接口说明</a>
* @see com.foxinmy.weixin4j.tuple.Text
* @see com.foxinmy.weixin4j.tuple.Image
* @see com.foxinmy.weixin4j.tuple.Voice
@ -56,14 +53,11 @@ public class NotifyApi extends QyApi {
*
* @param message
* 消息对象
* @return 如果无权限或收件人不存在则本次发送失败如果未关注发送仍然执行两种情况下均返回无效的部分由于userid不区分大小写返回的列表都统一转为小写</br> { "errcode":
* 0, "errmsg": "ok", "invaliduser": "UserID1",
* "invalidparty":"PartyID1", "invalidtag":"TagID1" }
* @return 如果无权限或收件人不存在则本次发送失败如果未关注发送仍然执行两种情况下均返回无效的部分由于userid不区分大小写
* 返回的列表都统一转为小写</br> { "errcode": 0, "errmsg": "ok", "invaliduser":
* "UserID1", "invalidparty":"PartyID1", "invalidtag":"TagID1" }
* @throws WeixinException
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E">发送接口说明</a>
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%E5%8F%8A%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F">发送格式说明</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10167">发送接口说明</a>
* @see com.foxinmy.weixin4j.tuple.Text
* @see com.foxinmy.weixin4j.tuple.Image
* @see com.foxinmy.weixin4j.tuple.Voice

View File

@ -14,15 +14,10 @@ import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年6月11日
* @since JDK 1.6
* @see <a href= "http://work.weixin.qq.com/api/doc#10028"> 企业号用户身份授权说明</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=OAuth%E9%AA%8C%E8%AF%81%E6%8E%A5%E5%8F%A3">
* 企业号用户身份授权说明</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%99%BB%E5%BD%95%E6%8E%88%E6%9D%83">
* 企业号第三方提供商授权说明</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%88%E6%9D%83">
* 企业号第三方套件应用授权说明</a>
* "http://work.weixin.qq.com/api/doc#11791/服务商的凭证">企业号第三方提供商授权说明</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10974"> 企业号第三方套件应用授权说明</a>
*/
public class OauthApi extends QyApi {
private final WeixinAccount account;
@ -55,7 +50,8 @@ public class OauthApi extends QyApi {
public String getUserAuthorizationURL() {
String redirectUri = Weixin4jConfigUtil
.getValue("user.oauth.redirect.uri");
return getUserAuthorizationURL(redirectUri, "state");
return getUserAuthorizationURL(redirectUri, "snsapi_base", "state",
null);
}
/**
@ -63,19 +59,26 @@ public class OauthApi extends QyApi {
*
* @param redirectUri
* 重定向地址
* @param scope
* 应用授权作用域 snsapi_base静默授权可获取成员的基础信息</br>
* snsapi_userinfo静默授权可获取成员的详细信息但不包含手机邮箱</br>
* snsapi_privateinfo手动授权可获取成员的详细信息包含手机邮箱</br>
* @param state
* 用于保持请求和回调的状态
* @param agentId
* 企业应用的id 当scope是snsapi_userinfo或snsapi_privateinfo时该参数必填
* 注意redirect_uri的域名必须与该应用的可信域名一致
* @return 请求授权的URL
* @see UserApi#getOUserInfoByCode(String, String)
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81">
* 企业号用户身份授权</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10028">企业号用户身份授权</a>
*/
public String getUserAuthorizationURL(String redirectUri, String state) {
public String getUserAuthorizationURL(String redirectUri, String scope,
String state, Integer agentId) {
String oauth_uri = getRequestUri("user_oauth_uri");
try {
return String.format(oauth_uri, account.getId(),
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), scope,
state, agentId != null ? agentId.intValue() : "");
} catch (UnsupportedEncodingException e) {
;
}

View File

@ -19,8 +19,7 @@ import com.foxinmy.weixin4j.token.TokenManager;
* @date 2014年11月18日
* @since JDK 1.6
* @see com.foxinmy.weixin4j.qy.model.Party
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8">管理部门说明</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10076">管理部门说明</a>
*/
public class PartyApi extends QyApi {
private final TokenManager tokenManager;
@ -35,8 +34,7 @@ public class PartyApi extends QyApi {
* @param party
* 部门对象
* @see com.foxinmy.weixin4j.qy.model.Party
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8#.E5.88.9B.E5.BB.BA.E9.83.A8.E9.97.A8">创建部门说明</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10076">创建部门说明</a>
* @return 部门ID
* @throws WeixinException
*/
@ -62,8 +60,7 @@ public class PartyApi extends QyApi {
* @param party
* 部门对象
* @see com.foxinmy.weixin4j.qy.model.Party
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8#.E6.9B.B4.E6.96.B0.E9.83.A8.E9.97.A8">更新部门说明</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10077">更新部门说明</a>
* @return 处理结果
* @throws WeixinException
*/
@ -92,8 +89,7 @@ public class PartyApi extends QyApi {
* @param partId
* 部门ID获取指定部门ID下的子部门 传入0表示获取全部子部门
* @see com.foxinmy.weixin4j.qy.model.Party
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E5.88.97.E8.A1.A8">获取部门列表</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10093">获取部门列表</a>
* @return 部门列表
* @throws WeixinException
*/
@ -114,8 +110,7 @@ public class PartyApi extends QyApi {
*
* @param partId
* 部门ID
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8#.E5.88.A0.E9.99.A4.E9.83.A8.E9.97.A8">删除部门说明</a>
* @see <a href="https://work.weixin.qq.com/api/doc#10079">删除部门说明</a>
* @return 处理结果
* @throws WeixinException
*/

View File

@ -12,7 +12,7 @@ import com.foxinmy.weixin4j.api.BaseApi;
* @date 2014年11月18日
* @since JDK 1.6
* @see com.foxinmy.weixin4j.api.BaseApi
* @see <a href="http://qydev.weixin.qq.com/wiki/index.php">api文档</a>
* @see <a href="http://work.weixin.qq.com/api/doc#10012">api文档</a>
*/
public class QyApi extends BaseApi {

View File

@ -25,8 +25,7 @@ import com.foxinmy.weixin4j.token.TokenManager;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年6月17日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%88%E6%9D%83">第三方应用授权</a>
* @see <a href="http://work.weixin.qq.com/api/doc#10968">第三方应用授权</a>
*/
public class SuiteApi extends QyApi {
/**
@ -49,9 +48,10 @@ public class SuiteApi extends QyApi {
*/
public SuiteApi(TicketManager ticketManager) {
this.ticketManager = ticketManager;
this.tokenManager = new TokenManager(new WeixinSuiteTokenCreator(ticketManager),
ticketManager.getCacheStorager());
this.preCodeManager = new TokenManager(new WeixinSuitePreCodeCreator(tokenManager, ticketManager.getThirdId()),
this.tokenManager = new TokenManager(new WeixinSuiteTokenCreator(
ticketManager), ticketManager.getCacheStorager());
this.preCodeManager = new TokenManager(new WeixinSuitePreCodeCreator(
tokenManager, ticketManager.getThirdId()),
ticketManager.getCacheStorager());
}
@ -90,7 +90,8 @@ public class SuiteApi extends QyApi {
* @return 应用套件的preticket管理
*/
public PerTicketManager getPerTicketManager(String authCorpId) {
return new PerTicketManager(authCorpId, ticketManager.getThirdId(), ticketManager.getThirdSecret(),
return new PerTicketManager(authCorpId, ticketManager.getThirdId(),
ticketManager.getThirdSecret(),
ticketManager.getCacheStorager());
}
@ -102,7 +103,8 @@ public class SuiteApi extends QyApi {
* @return 企业号token
*/
public TokenManager getPerTokenManager(String authCorpId) {
return new TokenManager(new WeixinTokenSuiteCreator(getPerTicketManager(authCorpId), tokenManager),
return new TokenManager(new WeixinTokenSuiteCreator(
getPerTicketManager(authCorpId), tokenManager),
ticketManager.getCacheStorager());
}
@ -124,8 +126,9 @@ public class SuiteApi extends QyApi {
JSONObject appid = new JSONObject();
appid.put("appid", appids);
para.put("session_info", appid);
WeixinResponse response = weixinExecutor
.post(String.format(suite_set_session_uri, tokenManager.getAccessToken()), para.toJSONString());
WeixinResponse response = weixinExecutor.post(
String.format(suite_set_session_uri,
tokenManager.getAccessToken()), para.toJSONString());
return response.getAsResult();
}
@ -138,25 +141,28 @@ public class SuiteApi extends QyApi {
* @throws WeixinException
* @see com.foxinmy.weixin4j.qy.model.OUserInfo
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7.E7.9A.84.E6.B0.B8.E4.B9.85.E6.8E.88.E6.9D.83.E7.A0.81"
* >获取企业号的永久授权码</a>
* "https://work.weixin.qq.com/api/doc#10975/获取企业永久授权码">获取企业号的永久授权码</a>
*/
public OUserInfo exchangeAuthInfo(String authCode) throws WeixinException {
String suite_get_permanent_uri = getRequestUri("suite_get_permanent_uri");
JSONObject obj = new JSONObject();
obj.put("suite_id", ticketManager.getThirdId());
obj.put("auth_code", authCode);
WeixinResponse response = weixinExecutor
.post(String.format(suite_get_permanent_uri, tokenManager.getAccessToken()), obj.toJSONString());
WeixinResponse response = weixinExecutor.post(
String.format(suite_get_permanent_uri,
tokenManager.getAccessToken()), obj.toJSONString());
obj = response.getAsJson();
obj.put("corp_info", obj.remove("auth_corp_info"));
obj.put("user_info", obj.remove("auth_user_info"));
OUserInfo oInfo = JSON.toJavaObject(obj, OUserInfo.class);
// 微信授权企业号的永久授权码
PerTicketManager perTicketManager = getPerTicketManager(oInfo.getCorpInfo().getCorpId());
PerTicketManager perTicketManager = getPerTicketManager(oInfo
.getCorpInfo().getCorpId());
// 缓存微信企业号的access_token
TokenCreator tokenCreator = new WeixinTokenSuiteCreator(perTicketManager, tokenManager);
Token token = new Token(obj.getString("access_token"), obj.getLongValue("expires_in") * 1000l);
TokenCreator tokenCreator = new WeixinTokenSuiteCreator(
perTicketManager, tokenManager);
Token token = new Token(obj.getString("access_token"),
obj.getLongValue("expires_in") * 1000l);
ticketManager.getCacheStorager().caching(tokenCreator.key(), token);
// 缓存微信企业号的永久授权码
perTicketManager.cachingTicket(obj.getString("permanent_code"));
@ -172,16 +178,18 @@ public class SuiteApi extends QyApi {
* @throws WeixinException
* @see com.foxinmy.weixin4j.qy.model.OUserInfo
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7.E7.9A.84.E6.8E.88.E6.9D.83.E4.BF.A1.E6.81.AF">获取企业号的授权信息</a>
* "https://work.weixin.qq.com/api/doc#10975/获取企业授权信息">获取企业号的授权信息</a>
*/
public OUserInfo getAuthInfo(String authCorpId) throws WeixinException {
String suite_get_authinfo_uri = getRequestUri("suite_get_authinfo_uri");
JSONObject obj = new JSONObject();
obj.put("suite_id", ticketManager.getThirdId());
obj.put("auth_corpid", authCorpId);
obj.put("permanent_code", getPerTicketManager(authCorpId).getAccessTicket());
WeixinResponse response = weixinExecutor
.post(String.format(suite_get_authinfo_uri, tokenManager.getAccessToken()), obj.toJSONString());
obj.put("permanent_code", getPerTicketManager(authCorpId)
.getAccessTicket());
WeixinResponse response = weixinExecutor.post(
String.format(suite_get_authinfo_uri,
tokenManager.getAccessToken()), obj.toJSONString());
obj = response.getAsJson();
obj.put("corp_info", obj.remove("auth_corp_info"));
obj.put("user_info", obj.remove("auth_user_info"));
@ -198,24 +206,31 @@ public class SuiteApi extends QyApi {
* @return 应用信息
* @see com.foxinmy.weixin4j.qy.model.AgentInfo
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7.E5.BA.94.E7.94.A8">获取企业号应用</a>
* "https://work.weixin.qq.com/api/doc#10975/获取企业授权信息">获取企业号应用</a>
* @throws WeixinException
*/
public AgentInfo getAgent(String authCorpId, int agentid) throws WeixinException {
public AgentInfo getAgent(String authCorpId, int agentid)
throws WeixinException {
String suite_get_agent_uri = getRequestUri("suite_get_agent_uri");
JSONObject obj = new JSONObject();
obj.put("suite_id", ticketManager.getThirdId());
obj.put("auth_corpid", authCorpId);
obj.put("permanent_code", getPerTicketManager(authCorpId).getAccessTicket());
obj.put("permanent_code", getPerTicketManager(authCorpId)
.getAccessTicket());
obj.put("agentid", agentid);
WeixinResponse response = weixinExecutor.post(String.format(suite_get_agent_uri, tokenManager.getAccessToken()),
obj.toJSONString());
WeixinResponse response = weixinExecutor.post(
String.format(suite_get_agent_uri,
tokenManager.getAccessToken()), obj.toJSONString());
JSONObject jsonObj = response.getAsJson();
AgentInfo agent = JSON.toJavaObject(jsonObj, AgentInfo.class);
agent.setAllowUsers(JSON.parseArray(jsonObj.getJSONObject("allow_userinfos").getString("user"), User.class));
agent.setAllowPartys(
JSON.parseArray(jsonObj.getJSONObject("allow_partys").getString("partyid"), Integer.class));
agent.setAllowTags(JSON.parseArray(jsonObj.getJSONObject("allow_tags").getString("tagid"), Integer.class));
agent.setAllowUsers(JSON.parseArray(
jsonObj.getJSONObject("allow_userinfos").getString("user"),
User.class));
agent.setAllowPartys(JSON.parseArray(
jsonObj.getJSONObject("allow_partys").getString("partyid"),
Integer.class));
agent.setAllowTags(JSON.parseArray(jsonObj.getJSONObject("allow_tags")
.getString("tagid"), Integer.class));
return agent;
}
@ -232,14 +247,18 @@ public class SuiteApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public ApiResult setAgent(String authCorpId, AgentSetter agentSet) throws WeixinException {
public ApiResult setAgent(String authCorpId, AgentSetter agentSet)
throws WeixinException {
String suite_set_agent_uri = getRequestUri("suite_set_agent_uri");
JSONObject obj = new JSONObject();
obj.put("suite_id", ticketManager.getThirdId());
obj.put("auth_corpid", authCorpId);
obj.put("permanent_code", getPerTicketManager(authCorpId).getAccessTicket());
obj.put("permanent_code", getPerTicketManager(authCorpId)
.getAccessTicket());
obj.put("agent", agentSet);
WeixinResponse response = weixinExecutor.post(String.format(suite_set_agent_uri, tokenManager.getAccessToken()),
WeixinResponse response = weixinExecutor.post(
String.format(suite_set_agent_uri,
tokenManager.getAccessToken()),
JSON.toJSONString(obj, AgentApi.typeFilter));
return response.getAsResult();
}

View File

@ -22,9 +22,7 @@ import com.foxinmy.weixin4j.token.TokenManager;
* @author jinyu(foxinmy@gmail.com)
* @date 2014年11月19日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE">
* 管理标签</a>
* @see <a href="http://work.weixin.qq.com/api/doc#10915">管理标签</a>
*/
public class TagApi extends QyApi {
private final TokenManager tokenManager;
@ -39,9 +37,7 @@ public class TagApi extends QyApi {
* @param tag
* 标签对象</br> 标签名称长度限制为32个字汉字或英文字母标签名不可与其他标签重名</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 <a href= "https://work.weixin.qq.com/api/doc#10915"> 创建标签说明</a>
* @return 标签ID
* @throws WeixinException
*/
@ -63,9 +59,7 @@ public class TagApi extends QyApi {
*
* @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>
* @see <a href= "https://work.weixin.qq.com/api/doc#10919" >更新标签说明</a>
* @return 处理结果
* @see com.foxinmy.weixin4j.qy.model.Tag
* @throws WeixinException
@ -85,9 +79,7 @@ public class TagApi extends QyApi {
* @param tagId
* 标签ID
* @return 处理结果
* @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.A0.E9.99.A4.E6.A0.87.E7.AD.BE">
* 删除标签说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10920"> 删除标签说明</a>
* @throws WeixinException
*/
public ApiResult deleteTag(int tagId) throws WeixinException {
@ -101,9 +93,7 @@ public class TagApi extends QyApi {
/**
* 获取标签列表
*
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E8.8E.B7.E5.8F.96.E6.A0.87.E7.AD.BE.E5.88.97.E8.A1.A8">
* 获取标签列表说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10926"> 获取标签列表说明</a>
* @return 标签列表
* @see com.foxinmy.weixin4j.qy.model.Tag
* @throws WeixinException
@ -124,9 +114,7 @@ public class TagApi extends QyApi {
* 标签ID
* @see com.foxinmy.weixin4j.qy.model.Contacts
* @see com.foxinmy.weixin4j.qy.model.User
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E8.8E.B7.E5.8F.96.E6.A0.87.E7.AD.BE.E6.88.90.E5.91.98">
* 获取标签成员说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10921"> 获取标签成员说明</a>
* @return 成员列表<font color="red">Contacts#getUsers</font>和部门列表<font
* color="red">Contacts#getPartyIds</font>
* @throws WeixinException
@ -154,9 +142,7 @@ public class TagApi extends QyApi {
* 企业成员ID列表注意userlistpartylist不能同时为空单次请求长度不超过1000
* @param partyIds
* 企业部门ID列表注意userlistpartylist不能同时为空单次请求长度不超过100
* @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.A2.9E.E5.8A.A0.E6.A0.87.E7.AD.BE.E6.88.90.E5.91.98">
* 新增标签成员说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10923"> 新增标签成员说明</a>
* @see com.foxinmy.weixin4j.qy.model.IdParameter
* @return 非法的userIds和partyIds
* @throws WeixinException
@ -176,9 +162,7 @@ public class TagApi extends QyApi {
* 企业成员ID列表注意userlistpartylist不能同时为空
* @param partyIds
* 企业部门ID列表注意userlistpartylist不能同时为空
* @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.A0.E9.99.A4.E6.A0.87.E7.AD.BE.E6.88.90.E5.91.98">
* 删除标签成员说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10925"> 删除标签成员说明</a>
* @see com.foxinmy.weixin4j.qy.model.IdParameter
* @return 非法的userIds和partyIds
* @throws WeixinException

View File

@ -28,9 +28,7 @@ import com.foxinmy.weixin4j.util.StringUtil;
* @date 2014年11月19日
* @since JDK 1.6
* @see com.foxinmy.weixin4j.qy.model.User
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98">
* 管理成员说明</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10018">管理成员说明</a>
*/
public class UserApi extends QyApi {
private final MediaApi mediaApi;
@ -49,9 +47,7 @@ public class UserApi extends QyApi {
* @param user
* 成员对象
* @see com.foxinmy.weixin4j.qy.model.User
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E5.88.9B.E5.BB.BA.E6.88.90.E5.91.98">
* 创建成员说明</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10018"> 创建成员说明</a>
* @return 处理结果
* @throws WeixinException
*/
@ -68,9 +64,7 @@ public class UserApi extends QyApi {
* @param avatar
* 头像文件 可为空
* @see com.foxinmy.weixin4j.qy.model.User
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E5.88.9B.E5.BB.BA.E6.88.90.E5.91.98">
* 创建成员说明</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10018"> 创建成员说明</a>
* @return 处理结果
* @throws WeixinException
*/
@ -86,9 +80,7 @@ public class UserApi extends QyApi {
* @param user
* 成员对象
* @see com.foxinmy.weixin4j.qy.model.User
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E6.9B.B4.E6.96.B0.E6.88.90.E5.91.98">
* 更新成员说明</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10020"> 更新成员说明</a>
* @return 处理结果
* @throws WeixinException
*/
@ -105,9 +97,7 @@ public class UserApi extends QyApi {
* @param avatar
* 头像文件
* @see com.foxinmy.weixin4j.qy.model.User
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E6.9B.B4.E6.96.B0.E6.88.90.E5.91.98">
* 更新成员说明</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10020"> 更新成员说明</a>
* @return 处理结果
* @throws WeixinException
*/
@ -147,9 +137,7 @@ public class UserApi extends QyApi {
* @param userid
* 成员唯一ID
* @see com.foxinmy.weixin4j.qy.model.User
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E8.8E.B7.E5.8F.96.E6.88.90.E5.91.98">
* 获取成员说明</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10019">获取成员说明</a>
* @return 成员对象
* @throws WeixinException
*/
@ -177,17 +165,35 @@ public class UserApi extends QyApi {
* @return 成员对象
* @see {@link #getUser(String)}
* @see {@link #getUserIdByCode(String)}
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=OAuth%E9%AA%8C%E8%AF%81%E6%8E%A5%E5%8F%A3">
* @see <a href= "http://work.weixin.qq.com/api/doc#10028/根据code获取成员信息">
* oauth授权获取用户信息</a>
* @throws WeixinException
*/
public User getUserByCode(String code) throws WeixinException {
String[] userIds = getUserIdByCode(code);
if (Boolean.parseBoolean(userIds[2])) {
return getUser(openid2userid(userIds[0]));
JSONObject result = getUserIdByCode(code);
if (result.containsKey("user_ticket")) {
String user_ticket_detail_uri = getRequestUri("user_ticket_detail_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(
String.format(user_ticket_detail_uri,
token.getAccessToken()),
String.format("{\"user_ticket\":\"%s\"}",
result.getString("user_ticket")));
JSONObject obj = response.getAsJson();
Object attrs = obj.remove("extattr");
User user = JSON.toJavaObject(obj, User.class);
if (attrs != null) {
user.setExtattr(JSON.parseArray(
((JSONObject) attrs).getString("attrs"),
NameValue.class));
}
return user;
} else {
return getUser(userIds[0]);
String userId = result.getString("UserId");
if (StringUtil.isBlank(userId)) {
userId = openid2userid(result.getString("OpenId"));
}
return getUser(userId);
}
}
@ -196,27 +202,17 @@ public class UserApi extends QyApi {
*
* @param code
* 通过员工授权获取到的code每次员工授权带上的code将不一样code只能使用一次5分钟未被使用自动过期
* @return 两个元素的数组 <font color="red">第一个元素为userId或者openId
* 第二个元素为deviceId</font>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=OAuth%E9%AA%8C%E8%AF%81%E6%8E%A5%E5%8F%A3">
* @return 换取结果
* @see <a href= "https://work.weixin.qq.com/api/doc#10028">
* oauth授权获取用户信息</a>
* @throws WeixinException
*/
public String[] getUserIdByCode(String code) throws WeixinException {
public JSONObject getUserIdByCode(String code) throws WeixinException {
String user_getid_uri = getRequestUri("user_getid_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
user_getid_uri, token.getAccessToken(), code));
JSONObject result = response.getAsJson();
String userId = result.getString("UserId");
boolean need2 = false;
if (StringUtil.isBlank(userId)) {
userId = result.getString("OpenId");
need2 = true;
}
return new String[] { userId, result.getString("DeviceId"),
Boolean.toString(need2) };
return response.getAsJson();
}
/**
@ -252,9 +248,7 @@ public class UserApi extends QyApi {
* @param findDetail
* 是否获取详细信息
* @see com.foxinmy.weixin4j.qy.model.User
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98">
* 获取部门成员说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10061"> 获取部门成员说明</a>
* @return 成员列表
* @throws WeixinException
*/
@ -334,9 +328,7 @@ public class UserApi extends QyApi {
*
* @param userid
* 成员ID
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98">
* 删除成员说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10030"> 删除成员说明</a>
* @return 处理结果
* @throws WeixinException
*/
@ -353,9 +345,7 @@ public class UserApi extends QyApi {
*
* @param userIds
* 成员列表
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98"
* >批量删除成员说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10060" >批量删除成员说明</a>
* @return 处理结果
* @throws WeixinException
*/
@ -377,9 +367,7 @@ public class UserApi extends QyApi {
* @param userid
* 成员ID
* @return 调用结果
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%85%B3%E6%B3%A8%E4%B8%8E%E5%8F%96%E6%B6%88%E5%85%B3%E6%B3%A8">
* 二次验证说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#11378"> 二次验证说明</a>
* @throws WeixinException
*/
public ApiResult authsucc(String userId) throws WeixinException {
@ -433,9 +421,8 @@ public class UserApi extends QyApi {
* 需要发送红包的应用ID若只是使用微信支付和企业转账则无需该参数 传入0或负数则忽略
* @return 结果数组 第一个元素为对应的openid 第二个元素则为应用的appid(如果有)
* @throws WeixinException
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=Userid%E4%B8%8Eopenid%E4%BA%92%E6%8D%A2%E6%8E%A5%E5%8F%A3">
* userid转换成openid</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#11279">
* userid与openid互换</a>
*/
public String[] userid2openid(String userid, int agentid)
throws WeixinException {
@ -460,9 +447,8 @@ public class UserApi extends QyApi {
* 在使用微信支付微信红包和企业转账之后返回结果的openid
* @return 该openid在企业号中对应的成员userid
* @throws WeixinException
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=Userid%E4%B8%8Eopenid%E4%BA%92%E6%8D%A2%E6%8E%A5%E5%8F%A3">
* openid转换成userid</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#11279">
* userid与openid互换</a>
*/
public String openid2userid(String openid) throws WeixinException {
String openid2userid_uri = getRequestUri("openid2userid_uri");

View File

@ -1,6 +1,6 @@
# ----------------------------------------------------------------------------
# api\u9996\u9875
# http://qydev.weixin.qq.com/wiki/index.php
# https://work.weixin.qq.com/api/doc
# ----------------------------------------------------------------------------
api_base_url=https://qyapi.weixin.qq.com/cgi-bin
@ -21,6 +21,8 @@ user_update_uri={api_base_url}/user/update?access_token=%s
user_get_uri={api_base_url}/user/get?access_token=%s&userid=%s
# code\u83b7\u53d6\u6210\u5458\u4fe1\u606f
user_getid_uri={api_base_url}/user/getuserinfo?access_token=%s&code=%s
# code->ticket\u83b7\u53d6\u6210\u5458\u4fe1\u606f
user_ticket_detail_uri={api_base_url}/user/getuserdetail?access_token=%s
# \u83b7\u53d6\u90e8\u95e8\u6210\u5458
user_slist_uri={api_base_url}/user/simplelist?access_token=%s&department_id=%d&fetch_child=%d&status=%d
# \u83b7\u53d6\u90e8\u95e8\u6210\u5458(\u8be6\u60c5)
@ -87,7 +89,9 @@ batch_replaceparty.cvs={"header":"\u90e8\u95e8\u540d\u79f0,\u90e8\u95e8ID,\u7236
batch_getresult_uri={api_base_url}/batch/getresult?access_token=%s&jobid=%s
# \u7528\u6237\u8eab\u4efdoauth\u6388\u6743
user_oauth_uri=https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect
user_oauth_uri=https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&agentid=%s#wechat_redirect
# \u4f7f\u7528user_ticket\u83b7\u53d6\u6210\u5458\u8be6\u60c5
user_oauth_userdetail_uri={api_base_url}/user/getuserdetail?access_token=%s
# \u6210\u5458\u767b\u5f55\u7b2c\u4e09\u65b9oauth\u6388\u6743
user_thirdoauth_uri=https://qy.weixin.qq.com/cgi-bin/loginpage?corp_id=%s&redirect_uri=%s&state=%s&usertype=%s
# \u4f01\u4e1a\u53f7\u6210\u5458\u767b\u5f55\u7b2c\u4e09\u65b9\u4fe1\u606f

View File

@ -17,8 +17,6 @@ import com.foxinmy.weixin4j.tuple.NotifyTuple;
* @see com.foxinmy.weixin4j.tuple.Voice
* @see com.foxinmy.weixin4j.tuple.Video
* @see com.foxinmy.weixin4j.tuple.File
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%AE%A2%E6%9C%8D%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E">客服消息</a>
*/
public class CustomeMessage implements Serializable {

View File

@ -20,8 +20,6 @@ import com.foxinmy.weixin4j.tuple.NotifyTuple;
* @see com.foxinmy.weixin4j.tuple.File
* @see com.foxinmy.weixin4j.tuple.News
* @see com.foxinmy.weixin4j.tuple.MpNews
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%E5%8F%8A%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F">消息说明</a>
*/
public class NotifyMessage implements Serializable {
@ -51,7 +49,8 @@ public class NotifyMessage implements Serializable {
this(agentid, tuple, IdParameter.get(), false);
}
public NotifyMessage(int agentId, NotifyTuple tuple, IdParameter target, boolean isSafe) {
public NotifyMessage(int agentId, NotifyTuple tuple, IdParameter target,
boolean isSafe) {
this.agentId = agentId;
this.safe = isSafe ? 1 : 0;
this.tuple = tuple;
@ -84,6 +83,7 @@ public class NotifyMessage implements Serializable {
@Override
public String toString() {
return "NotifyMessage [agentId=" + agentId + ", safe=" + safe + ", tuple=" + tuple + ", target=" + target + "]";
return "NotifyMessage [agentId=" + agentId + ", safe=" + safe
+ ", tuple=" + tuple + ", target=" + target + "]";
}
}

View File

@ -12,8 +12,6 @@ import com.foxinmy.weixin4j.qy.type.ReportLocationType;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年3月16日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%AE%BE%E7%BD%AE%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8">设置企业号应用</a>
*/
public class AgentSetter implements Serializable {
private static final long serialVersionUID = 5420335232308079801L;

View File

@ -11,8 +11,6 @@ import com.alibaba.fastjson.annotation.JSONField;
* @author jinyu(foxinmy@gmail.com)
* @date 2014年11月18日
* @since JDK 1.6
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8">管理部门说明</a>
*/
public class Party implements Serializable {
@ -31,7 +29,7 @@ public class Party implements Serializable {
@JSONField(name = "parentid")
private int parentId;
/**
* 在父部门中的次序值order值大的排序靠前有效的值范围是[0, 2^32)
* 在父部门中的次序值order值大的排序靠前有效的值范围是[0, 2^32)
*/
private int order;

View File

@ -8,7 +8,7 @@ import com.alibaba.fastjson.annotation.JSONField;
/**
* 权限信息
*
* @className Privilege
* @className PrivilegeInfo
* @author jinyu(foxinmy@gmail.com)
* @date 2016年3月28日
* @since JDK 1.6

View File

@ -3,7 +3,7 @@ package com.foxinmy.weixin4j.qy.model;
/**
* 权限级别
*
* @className Privilege
* @className PrivilegeLevel
* @author jinyu(foxinmy@gmail.com)
* @date 2016年3月28日
* @since JDK 1.6

View File

@ -16,8 +16,6 @@ import com.foxinmy.weixin4j.util.NameValue;
* @author jinyu(foxinmy@gmail.com)
* @date 2014年11月19日
* @since JDK 1.6
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98">管理成员说明</a>
*/
public class User implements Serializable {

View File

@ -13,9 +13,6 @@ import com.foxinmy.weixin4j.model.WeixinAccount;
* @author jinyu(foxinmy@gmail.com)
* @date 2014年11月18日
* @since JDK 1.6
* @see <a href=
* "https://qy.weixin.qq.com/cgi-bin/home?lang=zh_CN&token=685923034#setting"
* >企业号设置</a>
*/
public class WeixinQyAccount extends WeixinAccount {
@ -72,8 +69,8 @@ public class WeixinQyAccount extends WeixinAccount {
@Override
public String toString() {
return "WeixinQyAccount [" + super.toString() + ", suites="
+ suites + ", providerSecret=" + providerSecret
+ ", chatSecret=" + chatSecret + "]";
return "WeixinQyAccount [" + super.toString() + ", suites=" + suites
+ ", providerSecret=" + providerSecret + ", chatSecret="
+ chatSecret + "]";
}
}

View File

@ -15,44 +15,46 @@ import com.foxinmy.weixin4j.token.TokenManager;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年6月17日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E9.A2.84.E6.8E.88.E6.9D.83.E7.A0.81">
* @see <a href= "http://work.weixin.qq.com/api/doc#10975/获取预授权码">
* 获取应用套件预授权码</a>
* @see com.foxinmy.weixin4j.model.Token
*/
public class WeixinSuitePreCodeCreator extends TokenCreator {
private final TokenManager suiteTokenManager;
private final String suiteId;
private final TokenManager suiteTokenManager;
private final String suiteId;
/**
*
* @param suiteTokenManager
* 应用套件的token
* @param suiteId
* 应用套件ID
*/
public WeixinSuitePreCodeCreator(TokenManager suiteTokenManager, String suiteId) {
this.suiteTokenManager = suiteTokenManager;
this.suiteId = suiteId;
}
/**
*
* @param suiteTokenManager
* 应用套件的token
* @param suiteId
* 应用套件ID
*/
public WeixinSuitePreCodeCreator(TokenManager suiteTokenManager,
String suiteId) {
this.suiteTokenManager = suiteTokenManager;
this.suiteId = suiteId;
}
@Override
public String name() {
return "qy_suite_precode";
}
@Override
public String name() {
return "qy_suite_precode";
}
@Override
public String uniqueid() {
return suiteId;
}
@Override
public String uniqueid() {
return suiteId;
}
@Override
public Token create() throws WeixinException {
WeixinResponse response = weixinExecutor.post(
String.format(URLConsts.SUITE_PRE_CODE_URL, suiteTokenManager.getAccessToken()),
String.format("{\"suite_id\":\"%s\"}", suiteId));
JSONObject result = response.getAsJson();
return new Token(result.getString("pre_auth_code"), result.getLongValue("expires_in") * 1000l);
}
@Override
public Token create() throws WeixinException {
WeixinResponse response = weixinExecutor.post(
String.format(URLConsts.SUITE_PRE_CODE_URL,
suiteTokenManager.getAccessToken()),
String.format("{\"suite_id\":\"%s\"}", suiteId));
JSONObject result = response.getAsJson();
return new Token(result.getString("pre_auth_code"),
result.getLongValue("expires_in") * 1000l);
}
}

View File

@ -15,41 +15,42 @@ import com.foxinmy.weixin4j.token.TokenCreator;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年6月17日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E5.BA.94.E7.94.A8.E5.A5.97.E4.BB.B6.E4.BB.A4.E7.89.8C">获取应用套件凭证</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#10975/获取应用套件凭证">获取应用套件凭证</a>
* @see com.foxinmy.weixin4j.model.Token
*/
public class WeixinSuiteTokenCreator extends TokenCreator {
private final TicketManager ticketManager;
private final TicketManager ticketManager;
/**
*
* @param ticketManager
* 套件ticket存取
*/
public WeixinSuiteTokenCreator(TicketManager ticketManager) {
this.ticketManager = ticketManager;
}
/**
*
* @param ticketManager
* 套件ticket存取
*/
public WeixinSuiteTokenCreator(TicketManager ticketManager) {
this.ticketManager = ticketManager;
}
@Override
public String name() {
return "qy_suite_token";
}
@Override
public String name() {
return "qy_suite_token";
}
@Override
public String uniqueid() {
return ticketManager.getThirdId();
}
@Override
public String uniqueid() {
return ticketManager.getThirdId();
}
@Override
public Token create() throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("suite_id", ticketManager.getThirdId());
obj.put("suite_secret", ticketManager.getThirdSecret());
obj.put("suite_ticket", ticketManager.getAccessTicket());
WeixinResponse response = weixinExecutor.post(URLConsts.SUITE_TOKEN_URL, obj.toJSONString());
obj = response.getAsJson();
return new Token(obj.getString("suite_access_token"), obj.getLongValue("expires_in") * 1000l);
}
@Override
public Token create() throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("suite_id", ticketManager.getThirdId());
obj.put("suite_secret", ticketManager.getThirdSecret());
obj.put("suite_ticket", ticketManager.getAccessTicket());
WeixinResponse response = weixinExecutor.post(
URLConsts.SUITE_TOKEN_URL, obj.toJSONString());
obj = response.getAsJson();
return new Token(obj.getString("suite_access_token"),
obj.getLongValue("expires_in") * 1000l);
}
}

View File

@ -16,47 +16,50 @@ import com.foxinmy.weixin4j.token.TokenManager;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年6月17日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7access_token">
* @see <a href= "http://work.weixin.qq.com/api/doc#10975/获取企业永久授权码">
* 获取企业号access_token</a>
* @see com.foxinmy.weixin4j.model.Token
*/
public class WeixinTokenSuiteCreator extends TokenCreator {
private final PerTicketManager perTicketManager;
private final TokenManager suiteTokenManager;
private final PerTicketManager perTicketManager;
private final TokenManager suiteTokenManager;
/**
*
* @param perTicketManager
* 第三方套件永久授权码
* @param suiteTokenManager
* 第三方套件凭证token
*/
public WeixinTokenSuiteCreator(PerTicketManager perTicketManager, TokenManager suiteTokenManager) {
this.perTicketManager = perTicketManager;
this.suiteTokenManager = suiteTokenManager;
}
/**
*
* @param perTicketManager
* 第三方套件永久授权码
* @param suiteTokenManager
* 第三方套件凭证token
*/
public WeixinTokenSuiteCreator(PerTicketManager perTicketManager,
TokenManager suiteTokenManager) {
this.perTicketManager = perTicketManager;
this.suiteTokenManager = suiteTokenManager;
}
@Override
public String name() {
return String.format("qy_token_suite_%s_%s", perTicketManager.getThirdId(), perTicketManager.getAuthAppId());
}
@Override
public String name() {
return String.format("qy_token_suite_%s_%s",
perTicketManager.getThirdId(), perTicketManager.getAuthAppId());
}
@Override
public String uniqueid() {
throw new UnsupportedOperationException();
}
@Override
public String uniqueid() {
throw new UnsupportedOperationException();
}
@Override
public Token create() throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("suite_id", perTicketManager.getThirdId());
obj.put("auth_corpid", perTicketManager.getAuthAppId());
obj.put("permanent_code", perTicketManager.getAccessTicket());
WeixinResponse response = weixinExecutor
.post(String.format(URLConsts.TOKEN_SUITE_URL, suiteTokenManager.getAccessToken()), obj.toJSONString());
obj = response.getAsJson();
return new Token(obj.getString("access_token"), obj.getLongValue("expires_in") * 1000l);
}
@Override
public Token create() throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("suite_id", perTicketManager.getThirdId());
obj.put("auth_corpid", perTicketManager.getAuthAppId());
obj.put("permanent_code", perTicketManager.getAccessTicket());
WeixinResponse response = weixinExecutor
.post(String.format(URLConsts.TOKEN_SUITE_URL,
suiteTokenManager.getAccessToken()), obj.toJSONString());
obj = response.getAsJson();
return new Token(obj.getString("access_token"),
obj.getLongValue("expires_in") * 1000l);
}
}

View File

@ -14,45 +14,45 @@ import com.foxinmy.weixin4j.token.TokenCreator;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年1月10日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E6%8F%90%E4%BE%9B%E5%95%86%E5%87%AD%E8%AF%81">
* 获取应用提供商凭证</a>
* @see <a href= "http://work.weixin.qq.com/api/doc#11791/服务商的凭证">服务商的凭证</a>
* @see com.foxinmy.weixin4j.model.Token
*/
public class WeixinProviderTokenCreator extends TokenCreator {
private final String corpid;
private final String providersecret;
private final String corpid;
private final String providersecret;
/**
*
* @param corpid
* 企业号ID
* @param providersecret
* 企业号提供商的secret
*/
public WeixinProviderTokenCreator(String corpid, String providersecret) {
this.corpid = corpid;
this.providersecret = providersecret;
}
/**
*
* @param corpid
* 企业号ID
* @param providersecret
* 企业号提供商的secret
*/
public WeixinProviderTokenCreator(String corpid, String providersecret) {
this.corpid = corpid;
this.providersecret = providersecret;
}
@Override
public String name() {
return "qy_provider_token";
}
@Override
public String name() {
return "qy_provider_token";
}
@Override
public String uniqueid() {
return corpid;
}
@Override
public String uniqueid() {
return corpid;
}
@Override
public Token create() throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("corpid", corpid);
obj.put("provider_secret", providersecret);
WeixinResponse response = weixinExecutor.post(URLConsts.PROVIDER_TOKEN_URL, obj.toJSONString());
obj = response.getAsJson();
return new Token(obj.getString("provider_access_token"), obj.getLongValue("expires_in") * 1000l);
}
@Override
public Token create() throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("corpid", corpid);
obj.put("provider_secret", providersecret);
WeixinResponse response = weixinExecutor.post(
URLConsts.PROVIDER_TOKEN_URL, obj.toJSONString());
obj = response.getAsJson();
return new Token(obj.getString("provider_access_token"),
obj.getLongValue("expires_in") * 1000l);
}
}

View File

@ -16,48 +16,50 @@ import com.foxinmy.weixin4j.type.TicketType;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年12月25日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1JS-SDK%E6%8E%A5%E5%8F%A3#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95"
* >JSTICKET</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10029/附录1-JS-SDK使用权限签名算法">JSTICKET</a>
*/
public class WeixinTicketCreator extends TokenCreator {
private final TicketType ticketType;
private final TokenManager weixinTokenManager;
private final TicketType ticketType;
private final TokenManager weixinTokenManager;
/**
* @param ticketType
* 票据类型
* @param weixinTokenManager
* <font color="red">企业号的access_token</font>
*/
public WeixinTicketCreator(TicketType ticketType, TokenManager weixinTokenManager) {
this.ticketType = ticketType;
this.weixinTokenManager = weixinTokenManager;
}
/**
* @param ticketType
* 票据类型
* @param weixinTokenManager
* <font color="red">企业号的access_token</font>
*/
public WeixinTicketCreator(TicketType ticketType,
TokenManager weixinTokenManager) {
this.ticketType = ticketType;
this.weixinTokenManager = weixinTokenManager;
}
@Override
public String name() {
return String.format("qy_ticket_%s", ticketType.name());
}
@Override
public String name() {
return String.format("qy_ticket_%s", ticketType.name());
}
@Override
public String uniqueid() {
return weixinTokenManager.getWeixinId();
}
@Override
public String uniqueid() {
return weixinTokenManager.getWeixinId();
}
@Override
public Token create() throws WeixinException {
WeixinResponse response = null;
if (ticketType == TicketType.jsapi) {
response = weixinExecutor
.get(String.format(URLConsts.JS_TICKET_URL, weixinTokenManager.getCache().getAccessToken()));
} else {
response = weixinExecutor.get(String.format(URLConsts.SUITE_TICKET_URL,
weixinTokenManager.getCache().getAccessToken(), ticketType.name()));
}
JSONObject result = response.getAsJson();
return new Token(result.getString("ticket"), result.getLong("expires_in") * 1000l).pushExtra("group_id",
result.getString("group_id"));
}
@Override
public Token create() throws WeixinException {
WeixinResponse response = null;
if (ticketType == TicketType.jsapi) {
response = weixinExecutor.get(String.format(
URLConsts.JS_TICKET_URL, weixinTokenManager.getCache()
.getAccessToken()));
} else {
response = weixinExecutor.get(String.format(
URLConsts.SUITE_TICKET_URL, weixinTokenManager.getCache()
.getAccessToken(), ticketType.name()));
}
JSONObject result = response.getAsJson();
return new Token(result.getString("ticket"),
result.getLong("expires_in") * 1000l).pushExtra("group_id",
result.getString("group_id"));
}
}

View File

@ -14,43 +14,43 @@ import com.foxinmy.weixin4j.token.TokenCreator;
* @author jinyu(foxinmy@gmail.com)
* @date 2015年1月10日
* @since JDK 1.6
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%BB%E5%8A%A8%E8%B0%83%E7%94%A8">
* 微信企业号获取token说明</a>
* @see <a href= "https://work.weixin.qq.com/api/doc#10013"> 微信企业号获取token说明</a>
* @see com.foxinmy.weixin4j.model.Token
*/
public class WeixinTokenCreator extends TokenCreator {
private final String corpid;
private final String corpsecret;
private final String corpid;
private final String corpsecret;
/**
*
* @param corpid
* 企业号ID
* @param corpsecret
* 企业号secret
*/
public WeixinTokenCreator(String corpid, String corpsecret) {
this.corpid = corpid;
this.corpsecret = corpsecret;
}
/**
*
* @param corpid
* 企业号ID
* @param corpsecret
* 企业号secret
*/
public WeixinTokenCreator(String corpid, String corpsecret) {
this.corpid = corpid;
this.corpsecret = corpsecret;
}
@Override
public String name() {
return "qy_token";
}
@Override
public String name() {
return "qy_token";
}
@Override
public String uniqueid() {
return corpid;
}
@Override
public String uniqueid() {
return corpid;
}
@Override
public Token create() throws WeixinException {
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, corpid, corpsecret);
WeixinResponse response = weixinExecutor.get(tokenUrl);
JSONObject result = response.getAsJson();
return new Token(result.getString("access_token"), result.getLongValue("expires_in") * 1000l);
}
@Override
public Token create() throws WeixinException {
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, corpid,
corpsecret);
WeixinResponse response = weixinExecutor.get(tokenUrl);
JSONObject result = response.getAsJson();
return new Token(result.getString("access_token"),
result.getLongValue("expires_in") * 1000l);
}
}

View File

@ -29,7 +29,7 @@ public final class URLConsts {
/**
* 应用套件oauth授权
*/
public static final String SUITE_OAUTH_URL = "https://qy.weixin.qq.com/cgi-bin/loginpage?suite_id=%s&pre_auth_code=%s&redirect_uri=%s&state=%s";
public static final String SUITE_OAUTH_URL = "https://open.work.weixin.qq.com/3rdapp/install?suite_id=%s&pre_auth_code=%s&redirect_uri=%s&state=%s";
/**
* 企业号获取ticket的url
*/