|
|
@@ -23,6 +23,7 @@ import java.net.URLEncoder;
|
|
|
import java.net.http.HttpRequest;
|
|
|
import java.net.http.HttpResponse;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/*
|
|
|
*项目名: netflix
|
|
|
@@ -57,7 +58,7 @@ public class WxCorpOpsImpl implements WxCorpOps {
|
|
|
|
|
|
@Override
|
|
|
public String getAccessToken(String corpId) throws Exception {
|
|
|
- String accessToken = redisService.getStr(RedisKey.CORP_ACCESS_TOKEN_KEY + corpId);
|
|
|
+ String accessToken = StrUtil.EMPTY;
|
|
|
if (StringUtils.isNotBlank(accessToken)) {
|
|
|
return accessToken;
|
|
|
}
|
|
|
@@ -185,6 +186,99 @@ public class WxCorpOpsImpl implements WxCorpOps {
|
|
|
return ticket;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getCorpChatGroups(String corpId, String configId) throws Exception {
|
|
|
+ corpId = Optional.ofNullable(corpId).orElse(yhlXWxCorpConfig.getCorpId());
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get_join_way?access_token=" + getAccessToken(corpId);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.putOpt("config_id", configId);
|
|
|
+ HttpResponse<byte[]> res =
|
|
|
+ J11HttpC.custom()
|
|
|
+ .ofPost()
|
|
|
+ .url(url)
|
|
|
+ .cacheURI()
|
|
|
+ .body(HttpRequest.BodyPublishers.ofString(jsonObject.toString(), IoKit.Charsets.UTF_8.getCharset()))
|
|
|
+ .send(HttpResponse.BodyHandlers.ofByteArray());
|
|
|
+ String body = IoKit.toString(res.body());
|
|
|
+ if (200 != res.statusCode()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("获取access_token失败: " + body);
|
|
|
+ }
|
|
|
+ JSONObject re = Jsons.parseObject(body, JSONObject.class);
|
|
|
+ Integer errcode = re.getInt("errcode");
|
|
|
+ if (null != errcode && 0 != errcode) {
|
|
|
+ throw BusinessRuntimeException.getInstance("获取企业微信access_token失败: " + re.getStr("errmsg") + "[" + errcode + "]");
|
|
|
+ }
|
|
|
+ JSONObject codeRe = Jsons.parseObject(re.getStr("join_way"), JSONObject.class);
|
|
|
+ String qr_code = codeRe.getStr("qr_code");
|
|
|
+ return qr_code;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getGroupsList() throws Exception {
|
|
|
+ String corpId = yhlXWxCorpConfig.getCorpId();
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/list?access_token=" + getAccessToken(corpId);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.putOpt("limit", 1000);
|
|
|
+ HttpResponse<byte[]> res =
|
|
|
+ J11HttpC.custom()
|
|
|
+ .ofPost()
|
|
|
+ .url(url)
|
|
|
+ .cacheURI()
|
|
|
+ .body(HttpRequest.BodyPublishers.ofString(jsonObject.toString(), IoKit.Charsets.UTF_8.getCharset()))
|
|
|
+ .send(HttpResponse.BodyHandlers.ofByteArray());
|
|
|
+ String body = IoKit.toString(res.body());
|
|
|
+ if (200 != res.statusCode()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("获取access_token失败: " + IoKit.toString(res.body()));
|
|
|
+ }
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String setGroupsConfig(List<String> chatIds) throws Exception {
|
|
|
+ String corpId = yhlXWxCorpConfig.getCorpId();
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/add_join_way?access_token=" + getAccessToken(corpId);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ //scene 是 场景。
|
|
|
+ //1 - 群的小程序插件
|
|
|
+ //2 - 群的二维码插件
|
|
|
+ jsonObject.putOpt("scene", 2);
|
|
|
+ jsonObject.putOpt("chat_id_list", chatIds);
|
|
|
+ jsonObject.putOpt("room_base_name", "Ai银河课堂 MJ SD教程分享");
|
|
|
+ HttpResponse<byte[]> res =
|
|
|
+ J11HttpC.custom()
|
|
|
+ .ofPost()
|
|
|
+ .url(url)
|
|
|
+ .cacheURI()
|
|
|
+ .body(HttpRequest.BodyPublishers.ofString(jsonObject.toString(), IoKit.Charsets.UTF_8.getCharset()))
|
|
|
+ .send(HttpResponse.BodyHandlers.ofByteArray());
|
|
|
+ String body = IoKit.toString(res.body());
|
|
|
+ if (200 != res.statusCode()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("获取access_token失败: " + body);
|
|
|
+ }
|
|
|
+ log.info("配置企业微信群返回信息body:{}", body);
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getGroupsDetail(String chatId) throws Exception {
|
|
|
+ String corpId = yhlXWxCorpConfig.getCorpId();
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get?access_token=" + getAccessToken(corpId);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.putOpt("chat_id", chatId);
|
|
|
+ HttpResponse<byte[]> res =
|
|
|
+ J11HttpC.custom()
|
|
|
+ .ofPost()
|
|
|
+ .url(url)
|
|
|
+ .cacheURI()
|
|
|
+ .body(HttpRequest.BodyPublishers.ofString(jsonObject.toString(), IoKit.Charsets.UTF_8.getCharset()))
|
|
|
+ .send(HttpResponse.BodyHandlers.ofByteArray());
|
|
|
+ String body = IoKit.toString(res.body());
|
|
|
+ if (200 != res.statusCode()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("获取access_token失败: " + body);
|
|
|
+ }
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+
|
|
|
public String access_token(String corpId) throws Exception {
|
|
|
WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
|
|
|
if (corpId == null) {
|