|
@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.IoKit;
|
|
import com.cyksj.common.util.IoKit;
|
|
|
import com.cyksj.common.util.J11HttpC;
|
|
import com.cyksj.common.util.J11HttpC;
|
|
@@ -84,6 +85,15 @@ public class WxCorpOpsImpl implements WxCorpOps {
|
|
|
}
|
|
}
|
|
|
return access_token(corpId);
|
|
return access_token(corpId);
|
|
|
}
|
|
}
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String getMsgAccessToken(String corpId) throws Exception {
|
|
|
|
|
+ corpId = Optional.ofNullable(corpId).orElse(yhlXWxCorpConfig.getCorpId());
|
|
|
|
|
+ String accessToken = redisService.getStr(RedisKey.CORP_MSG_ACCESS_TOKEN_KEY + corpId);
|
|
|
|
|
+ if (StringUtils.isNotBlank(accessToken)) {
|
|
|
|
|
+ return accessToken;
|
|
|
|
|
+ }
|
|
|
|
|
+ return getKfAccessToken(corpId);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public CorpUserExternalTagGroupList getCorpTagList(String corpId, List<String> tagIds, List<String> groupIds) throws Exception {
|
|
public CorpUserExternalTagGroupList getCorpTagList(String corpId, List<String> tagIds, List<String> groupIds) throws Exception {
|
|
@@ -638,6 +648,38 @@ public class WxCorpOpsImpl implements WxCorpOps {
|
|
|
return accessToken;
|
|
return accessToken;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public String getKfAccessToken(String corpId) throws Exception {
|
|
|
|
|
+ WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
|
|
|
|
|
+ if (StringUtils.isBlank(wxCorpApp.getMsgSecret())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该企业会话存档权限尚未开通.请联系管理员配置api secret");
|
|
|
|
|
+ }
|
|
|
|
|
+ String accessToken = redisService.getStr(RedisKey.CORP_MSG_ACCESS_TOKEN_KEY + corpId);
|
|
|
|
|
+ if(StringUtils.isBlank(accessToken)){
|
|
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" +
|
|
|
|
|
+ "?corpid=" + corpId +"&corpsecret=" + wxCorpApp.getMsgSecret();
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse<String> res =
|
|
|
|
|
+ J11HttpC.custom()
|
|
|
|
|
+ .ofGet()
|
|
|
|
|
+ .url(url)
|
|
|
|
|
+ .send(HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
+
|
|
|
|
|
+ if (200 != res.statusCode()) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("获取企业微信access_token失败: " + res.body());
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject result = new JSONObject(res.body());
|
|
|
|
|
+
|
|
|
|
|
+ final Integer errcode = result.getInt("errcode");
|
|
|
|
|
+ if (null != errcode && 0 != errcode) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("获取企业微信access_token失败: " + result.getStr("errmsg") + "[" + errcode + "]");
|
|
|
|
|
+ }
|
|
|
|
|
+ accessToken = result.getStr("access_token");
|
|
|
|
|
+ redisService.set(RedisKey.CORP_MSG_ACCESS_TOKEN_KEY + corpId, accessToken, result.getInt("expires_in") - 300L);
|
|
|
|
|
+ return accessToken;
|
|
|
|
|
+ }
|
|
|
|
|
+ return accessToken;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public String js_ticket(String corpId) throws Exception {
|
|
public String js_ticket(String corpId) throws Exception {
|
|
|
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=%s", this.getAccessToken(corpId));
|
|
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=%s", this.getAccessToken(corpId));
|
|
|
HttpResponse<byte[]> res =
|
|
HttpResponse<byte[]> res =
|
|
@@ -762,7 +804,7 @@ public class WxCorpOpsImpl implements WxCorpOps {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<String> getPermitUserList(String corpId, String type) throws Exception {
|
|
public List<String> getPermitUserList(String corpId, String type) throws Exception {
|
|
|
- String url = "https://qyapi.weixin.qq.com/cgi-bin/msgaudit/get_permit_user_list?access_token=" + getAccessToken(corpId);
|
|
|
|
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/msgaudit/get_permit_user_list?access_token=" + getMsgAccessToken(corpId);
|
|
|
|
|
|
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
|
if (StringUtils.isNotBlank(type)) {
|
|
if (StringUtils.isNotBlank(type)) {
|