Skip to content

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

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
@@ -1,20 +1,20 @@
package me.chanjar.weixin.cp.api;

import java.util.List;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpAppChatMessage;
import me.chanjar.weixin.cp.bean.WxCpChat;

import java.util.List;

/**
* 群聊服务.
*
* @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_CREATE = "/cgi-bin/appchat/create";
String APPCHAT_UPDATE = "/cgi-bin/appchat/update";
String APPCHAT_GET_CHATID = "/cgi-bin/appchat/get?chatid=";

/**
* 创建群聊会话,注意:刚创建的群,如果没有下发消息,在企业微信不会出现该群.
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 @@ -13,9 +13,9 @@
* @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_OAUTH_2_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize";
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 = "/connect/oauth2/authorize";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
* @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_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";

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@
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.WxCpConsts;
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.WxCpOAService;
import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
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 Down Expand Up @@ -104,7 +115,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 +140,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 +181,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 +190,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 +340,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
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package me.chanjar.weixin.cp.api.impl;

import java.util.List;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;

import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpAgentService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpAgent;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.util.List;


/**
* <pre>
Expand All @@ -37,14 +36,14 @@ public WxCpAgent get(Integer agentId) throws WxErrorException {
throw new IllegalArgumentException("缺少agentid参数");
}

String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/get?agentid=" + agentId;
String url = this.mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/agent/get?agentid=" + agentId);
String responseContent = this.mainService.get(url, null);
return WxCpAgent.fromJson(responseContent);
}

@Override
public void set(WxCpAgent agentInfo) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/set";
String url = this.mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/agent/set");
String responseContent = this.mainService.post(url, agentInfo.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() != 0) {
Expand All @@ -54,7 +53,7 @@ public void set(WxCpAgent agentInfo) throws WxErrorException {

@Override
public List<WxCpAgent> list() throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/list";
String url = this.mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/agent/list");
String responseContent = this.mainService.get(url, null);
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String chatCreate(String name, String owner, List<String> users, String c
if (StringUtils.isNotBlank(chatId)) {
data.put("chatid", chatId);
}
String result = this.cpService.post(APPCHAT_CREATE, WxGsonBuilder.create().toJson(data));
String result = this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_CREATE), WxGsonBuilder.create().toJson(data));
return new JsonParser().parse(result).getAsJsonObject().get("chatid").getAsString();
}

Expand Down Expand Up @@ -76,7 +76,7 @@ public void chatUpdate(String chatId, String name, String owner, List<String> us
data.put("del_user_list", usersToDelete);
}

this.cpService.post(APPCHAT_UPDATE, WxGsonBuilder.create().toJson(data));
this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_UPDATE), WxGsonBuilder.create().toJson(data));
}

@Override
Expand All @@ -86,7 +86,7 @@ public void update(String chatId, String name, String owner, List<String> usersT

@Override
public WxCpChat chatGet(String chatId) throws WxErrorException {
String result = this.cpService.get(APPCHAT_GET_CHATID + chatId, null);
String result = this.cpService.get(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_GET_CHATID + chatId), null);
return WxCpGsonBuilder.create()
.fromJson(JSON_PARSER.parse(result).getAsJsonObject().getAsJsonObject("chat_info").toString(), WxCpChat.class);
}
Expand All @@ -98,7 +98,7 @@ public WxCpChat get(String chatId) throws WxErrorException {

@Override
public void sendMsg(WxCpAppChatMessage message) throws WxErrorException {
this.cpService.post("https://qyapi.weixin.qq.com/cgi-bin/appchat/send", message.toJson());
this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl("/cgi-bin/appchat/send"), message.toJson());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.chanjar.weixin.cp.api.impl;

import java.util.List;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
Expand All @@ -12,6 +10,8 @@
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.util.List;

/**
* <pre>
* 部门管理接口
Expand All @@ -29,27 +29,27 @@ public WxCpDepartmentServiceImpl(WxCpService mainService) {

@Override
public Long create(WxCpDepart depart) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
String url = this.mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/department/create");
String responseContent = this.mainService.post(url, depart.toJson());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("id"));
}

@Override
public void update(WxCpDepart group) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
String url = this.mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/department/update");
this.mainService.post(url, group.toJson());
}

@Override
public void delete(Long departId) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=" + departId;
String url = this.mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/department/delete?id=" + departId);
this.mainService.get(url, null);
}

@Override
public List<WxCpDepart> list(Long id) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
String url = this.mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/department/list");
if (id != null) {
url += "?id=" + id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package me.chanjar.weixin.cp.api.impl;

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

import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.cp.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpMediaService;
import me.chanjar.weixin.cp.api.WxCpService;

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

/**
* <pre>
* 媒体管理接口.
Expand All @@ -37,29 +38,29 @@ public WxMediaUploadResult upload(String mediaType, String fileType, InputStream
@Override
public WxMediaUploadResult upload(String mediaType, File file) throws WxErrorException {
return this.mainService.execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()),
MEDIA_UPLOAD_URL + mediaType, file);
this.mainService.getWxCpConfigStorage().getApiUrl(MEDIA_UPLOAD_URL + mediaType), file);
}

@Override
public File download(String mediaId) throws WxErrorException {
return this.mainService.execute(
BaseMediaDownloadRequestExecutor.create(this.mainService.getRequestHttp(),
this.mainService.getWxCpConfigStorage().getTmpDirFile()),
MEDIA_GET_URL, "media_id=" + mediaId);
this.mainService.getWxCpConfigStorage().getApiUrl(MEDIA_GET_URL), "media_id=" + mediaId);
}

@Override
public File getJssdkFile(String mediaId) throws WxErrorException {
return this.mainService.execute(
BaseMediaDownloadRequestExecutor.create(this.mainService.getRequestHttp(),
this.mainService.getWxCpConfigStorage().getTmpDirFile()),
JSSDK_MEDIA_GET_URL, "media_id=" + mediaId);
this.mainService.getWxCpConfigStorage().getApiUrl(JSSDK_MEDIA_GET_URL), "media_id=" + mediaId);
}

@Override
public String uploadImg(File file) throws WxErrorException {
final WxMediaUploadResult result = this.mainService
.execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), IMG_UPLOAD_URL, file);
.execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), this.mainService.getWxCpConfigStorage().getApiUrl(IMG_UPLOAD_URL), file);
return result.getUrl();
}
}
Loading