Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持私有安装版企业微信. #1065

Merged
merged 4 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* @author <a href="https://github.com/huansinho">huansinho</a>
*/
public interface WxCpAgentService {
String GET_AGENT = "https://qyapi.weixin.qq.com/cgi-bin/agent/get?agentid=%d";
String AGENT_SET = "https://qyapi.weixin.qq.com/cgi-bin/agent/set";
String AGENT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/agent/list";
String GET_AGENT = "/cgi-bin/agent/get?agentid=%d";
String AGENT_SET = "/cgi-bin/agent/set";
String AGENT_LIST = "/cgi-bin/agent/list";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* @author gaigeshen
*/
public interface WxCpChatService {
String APPCHAT_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/appchat/create";
String APPCHAT_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/appchat/update";
String APPCHAT_GET_CHATID = "https://qyapi.weixin.qq.com/cgi-bin/appchat/get?chatid=";
String APPCHAT_SEND = "https://qyapi.weixin.qq.com/cgi-bin/appchat/send";
String APPCHAT_CREATE = "/cgi-bin/appchat/create";
String APPCHAT_UPDATE = "/cgi-bin/appchat/update";
String APPCHAT_GET_CHATID = "/cgi-bin/appchat/get?chatid=";
String APPCHAT_SEND = "/cgi-bin/appchat/send";

@Deprecated
String chatCreate(String name, String owner, List<String> users, String chatId) throws WxErrorException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.chanjar.weixin.cp.api;

import java.util.List;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpDepart;

import java.util.List;

/**
* <pre>
* 部门管理接口
Expand All @@ -14,10 +14,10 @@
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpDepartmentService {
String DEPARTMENT_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
String DEPARTMENT_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
String DEPARTMENT_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=%d";
String DEPARTMENT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
String DEPARTMENT_CREATE = "/cgi-bin/department/create";
String DEPARTMENT_UPDATE = "/cgi-bin/department/update";
String DEPARTMENT_DELETE = "/cgi-bin/department/delete?id=%d";
String DEPARTMENT_LIST = "/cgi-bin/department/list";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;

/**
* <pre>
* 媒体管理接口.
Expand All @@ -16,10 +16,10 @@
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpMediaService {
String MEDIA_GET_URL = "https://qyapi.weixin.qq.com/cgi-bin/media/get";
String MEDIA_UPLOAD_URL = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?type=";
String IMG_UPLOAD_URL = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg";
String JSSDK_MEDIA_GET_URL = "https://qyapi.weixin.qq.com/cgi-bin/media/get/jssdk";
String MEDIA_GET_URL = "/cgi-bin/media/get";
String MEDIA_UPLOAD_URL = "/cgi-bin/media/upload?type=";
String IMG_UPLOAD_URL = "/cgi-bin/media/uploadimg";
String JSSDK_MEDIA_GET_URL = "/cgi-bin/media/get/jssdk";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpMenuService {
String MENU_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=%d";
String MENU_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=%d";
String MENU_GET = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=%d";
String MENU_CREATE = "/cgi-bin/menu/create?agentid=%d";
String MENU_DELETE = "/cgi-bin/menu/delete?agentid=%d";
String MENU_GET = "/cgi-bin/menu/get?agentid=%d";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpOAuth2Service {
String URL_GET_USER_INFO = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
String URL_GET_USER_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail";
String URL_GET_USER_INFO = "/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
String URL_GET_USER_DETAIL = "/cgi-bin/user/getuserdetail";
String URL_OAUTH_2_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize";
binarywang marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* @date 2019-04-06 10:52
*/
public interface WxCpOaService {
String GET_CHECKIN_DATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata";
String GET_CHECKIN_OPTION = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinoption";
String GET_APPROVAL_DATA = "https://qyapi.weixin.qq.com/cgi-bin/corp/getapprovaldata";
String GET_DIAL_RECORD = "https://qyapi.weixin.qq.com/cgi-bin/dial/get_dial_record";
String GET_CHECKIN_DATA = "/cgi-bin/checkin/getcheckindata";
String GET_CHECKIN_OPTION = "/cgi-bin/checkin/getcheckinoption";
String GET_APPROVAL_DATA = "/cgi-bin/corp/getapprovaldata";
String GET_DIAL_RECORD = "/cgi-bin/dial/get_dial_record";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* @author chanjaster
*/
public interface WxCpService {
String GET_JSAPI_TICKET = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
String GET_AGENT_CONFIG_TICKET = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?&type=agent_config";
String MESSAGE_SEND = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
String GET_CALLBACK_IP = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip";
String BATCH_REPLACE_PARTY = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty";
String BATCH_REPLACE_USER = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser";
String BATCH_GET_RESULT = "https://qyapi.weixin.qq.com/cgi-bin/batch/getresult?jobid=";
String JSCODE_TO_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session";
String GET_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?&corpid=%s&corpsecret=%s";
String GET_JSAPI_TICKET = "/cgi-bin/get_jsapi_ticket";
String GET_AGENT_CONFIG_TICKET = "/cgi-bin/ticket/get?&type=agent_config";
String MESSAGE_SEND = "/cgi-bin/message/send";
String GET_CALLBACK_IP = "/cgi-bin/getcallbackip";
String BATCH_REPLACE_PARTY = "/cgi-bin/batch/replaceparty";
String BATCH_REPLACE_USER = "/cgi-bin/batch/replaceuser";
String BATCH_GET_RESULT = "/cgi-bin/batch/getresult?jobid=";
String JSCODE_TO_SESSION_URL = "/cgi-bin/miniprogram/jscode2session";
String GET_TOKEN = "/cgi-bin/gettoken?&corpid=%s&corpsecret=%s";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpTagService {
String TAG_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/tag/create";
String TAG_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/tag/update";
String TAG_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/tag/delete?tagid=%s";
String TAG_LIST = "https://qyapi.weixin.qq.com/cgi-bin/tag/list";
String TAG_GET = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagid=%s";
String TAG_ADDTAGUSERS = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
String TAG_DELTAGUSERS = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
String TAG_CREATE = "/cgi-bin/tag/create";
String TAG_UPDATE = "/cgi-bin/tag/update";
String TAG_DELETE = "/cgi-bin/tag/delete?tagid=%s";
String TAG_LIST = "/cgi-bin/tag/list";
String TAG_GET = "/cgi-bin/tag/get?tagid=%s";
String TAG_ADDTAGUSERS = "/cgi-bin/tag/addtagusers";
String TAG_DELTAGUSERS = "/cgi-bin/tag/deltagusers";

/**
* 创建标签.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @date 2019-05-16
*/
public interface WxCpTaskCardService {
String MESSAGE_UPDATE_TASKCARD = "https://qyapi.weixin.qq.com/cgi-bin/message/update_taskcard";
String MESSAGE_UPDATE_TASKCARD = "/cgi-bin/message/update_taskcard";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* @author zhenjun cai
*/
public interface WxCpTpService {
String JSCODE_TO_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/miniprogram/jscode2session";
String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/service/get_corp_token";
String GET_PERMANENT_CODE = "https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code";
String GET_SUITE_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token";
String JSCODE_TO_SESSION_URL = "/cgi-bin/service/miniprogram/jscode2session";
String GET_CORP_TOKEN = "/cgi-bin/service/get_corp_token";
String GET_PERMANENT_CODE = "`/cgi-bin/service/get_permanent_code";
crazycode marked this conversation as resolved.
Show resolved Hide resolved
String GET_SUITE_TOKEN = "/cgi-bin/service/get_suite_token";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package me.chanjar.weixin.cp.api;

import java.util.List;
import java.util.Map;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;

import java.util.List;
import java.util.Map;

/**
* <pre>
* 用户管理接口
Expand All @@ -17,18 +17,18 @@
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpUserService {
String URL_AUTHENTICATE = "https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?userid=";
String URL_USER_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/user/create";
String URL_USER_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/user/update";
String URL_USER_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?userid=";
String URL_USER_BATCH_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
String URL_USER_GET = "https://qyapi.weixin.qq.com/cgi-bin/user/get?userid=";
String URL_USER_LIST = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=";
String URL_USER_SIMPLE_LIST = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=";
String URL_BATCH_INVITE = "https://qyapi.weixin.qq.com/cgi-bin/batch/invite";
String URL_CONVERT_TO_OPENID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid";
String URL_CONVERT_TO_USERID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid";
String URL_GET_EXTERNAL_CONTACT = "https://qyapi.weixin.qq.com/cgi-bin/crm/get_external_contact?external_userid=";
String URL_AUTHENTICATE = "/cgi-bin/user/authsucc?userid=";
String URL_USER_CREATE = "/cgi-bin/user/create";
String URL_USER_UPDATE = "/cgi-bin/user/update";
String URL_USER_DELETE = "/cgi-bin/user/delete?userid=";
String URL_USER_BATCH_DELETE = "/cgi-bin/user/batchdelete";
String URL_USER_GET = "/cgi-bin/user/get?userid=";
String URL_USER_LIST = "/cgi-bin/user/list?department_id=";
String URL_USER_SIMPLE_LIST = "/cgi-bin/user/simplelist?department_id=";
String URL_BATCH_INVITE = "/cgi-bin/batch/invite";
String URL_CONVERT_TO_OPENID = "/cgi-bin/user/convert_to_openid";
String URL_CONVERT_TO_USERID = "/cgi-bin/user/convert_to_userid";
String URL_GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.cp.api.*;
import me.chanjar.weixin.cp.api.WxCpAgentService;
import me.chanjar.weixin.cp.api.WxCpChatService;
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
import me.chanjar.weixin.cp.api.WxCpMediaService;
import me.chanjar.weixin.cp.api.WxCpMenuService;
import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
import me.chanjar.weixin.cp.api.WxCpOaService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpTagService;
import me.chanjar.weixin.cp.api.WxCpTaskCardService;
import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
Expand All @@ -37,16 +47,16 @@
public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> {
protected final Logger log = LoggerFactory.getLogger(this.getClass());

private WxCpUserService userService = new WxCpUserServiceImpl(this);
private WxCpChatService chatService = new WxCpChatServiceImpl(this);
private WxCpUserService userService = new WxCpUserServiceImpl(this);
private WxCpChatService chatService = new WxCpChatServiceImpl(this);
private WxCpDepartmentService departmentService = new WxCpDepartmentServiceImpl(this);
private WxCpMediaService mediaService = new WxCpMediaServiceImpl(this);
private WxCpMenuService menuService = new WxCpMenuServiceImpl(this);
private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this);
private WxCpTagService tagService = new WxCpTagServiceImpl(this);
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
private WxCpOaService oaService = new WxCpOaServiceImpl(this);
private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);
private WxCpMediaService mediaService = new WxCpMediaServiceImpl(this);
private WxCpMenuService menuService = new WxCpMenuServiceImpl(this);
private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this);
private WxCpTagService tagService = new WxCpTagServiceImpl(this);
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
private WxCpOaService oaService = new WxCpOaServiceImpl(this);
private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);

/**
* 全局的是否正在刷新access token的锁
Expand Down Expand Up @@ -104,7 +114,7 @@ public String getAgentJsapiTicket(boolean forceRefresh) throws WxErrorException
if (this.configStorage.isAgentJsapiTicketExpired()) {
synchronized (this.globalAgentJsapiTicketRefreshLock) {
if (this.configStorage.isAgentJsapiTicketExpired()) {
String responseContent = this.get(WxCpService.GET_AGENT_CONFIG_TICKET, null);
String responseContent = this.get(this.configStorage.getApiUrl(WxCpService.GET_AGENT_CONFIG_TICKET), null);
JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
this.configStorage.updateAgentJsapiTicket(jsonObject.get("ticket").getAsString(),
jsonObject.get("expires_in").getAsInt());
Expand All @@ -129,7 +139,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
if (this.configStorage.isJsapiTicketExpired()) {
synchronized (this.globalJsapiTicketRefreshLock) {
if (this.configStorage.isJsapiTicketExpired()) {
String responseContent = this.get(WxCpService.GET_JSAPI_TICKET, null);
String responseContent = this.get(this.configStorage.getApiUrl(WxCpService.GET_JSAPI_TICKET), null);
JsonObject tmpJsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
this.configStorage.updateJsapiTicket(tmpJsonObject.get("ticket").getAsString(),
tmpJsonObject.get("expires_in").getAsInt());
Expand Down Expand Up @@ -170,7 +180,7 @@ public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorExce
message.setAgentId(this.getWxCpConfigStorage().getAgentId());
}

return WxCpMessageSendResult.fromJson(this.post(WxCpService.MESSAGE_SEND, message.toJson()));
return WxCpMessageSendResult.fromJson(this.post(this.configStorage.getApiUrl(WxCpService.MESSAGE_SEND), message.toJson()));
}

@Override
Expand All @@ -179,13 +189,13 @@ public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorEx
params.put("js_code", jsCode);
params.put("grant_type", "authorization_code");

String result = this.get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
String result = this.get(this.configStorage.getApiUrl(JSCODE_TO_SESSION_URL), Joiner.on("&").withKeyValueSeparator("=").join(params));
return WxCpMaJsCode2SessionResult.fromJson(result);
}

@Override
public String[] getCallbackIp() throws WxErrorException {
String responseContent = get(WxCpService.GET_CALLBACK_IP, null);
String responseContent = get(this.configStorage.getApiUrl(WxCpService.GET_CALLBACK_IP), null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
String[] ips = new String[jsonArray.size()];
Expand Down Expand Up @@ -329,19 +339,19 @@ public WxSessionManager getSessionManager() {
public String replaceParty(String mediaId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("media_id", mediaId);
return post(WxCpService.BATCH_REPLACE_PARTY, jsonObject.toString());
return post(this.configStorage.getApiUrl(WxCpService.BATCH_REPLACE_PARTY), jsonObject.toString());
}

@Override
public String replaceUser(String mediaId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("media_id", mediaId);
return post(WxCpService.BATCH_REPLACE_USER, jsonObject.toString());
return post(this.configStorage.getApiUrl(WxCpService.BATCH_REPLACE_USER), jsonObject.toString());
}

@Override
public String getTaskResult(String joinId) throws WxErrorException {
String url = WxCpService.BATCH_GET_RESULT + joinId;
String url = this.configStorage.getApiUrl(WxCpService.BATCH_GET_RESULT + joinId);
return get(url, null);
}

Expand Down
Loading