|
|
@@ -1,6 +1,7 @@
|
|
|
package com.fs.qwApi.service.impl;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -10,6 +11,7 @@ import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
import com.fs.qw.param.QwUpdateContactWayParam;
|
|
|
import com.fs.qw.service.IQwCompanyService;
|
|
|
+import com.fs.qwApi.Params.QwApiParam;
|
|
|
import com.fs.qwApi.Result.*;
|
|
|
import com.fs.qwApi.config.QwApiConfig;
|
|
|
import com.fs.qwApi.domain.*;
|
|
|
@@ -31,7 +33,14 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.FileSystemResource;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
@@ -48,7 +57,7 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
- IQwCompanyService iQwCompanyService;
|
|
|
+ IQwCompanyService qwCompanyService;
|
|
|
// @Autowired
|
|
|
// ICompanyConfigService companyConfigService;
|
|
|
|
|
|
@@ -549,7 +558,7 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
// HttpClient httpClient = HttpClients.createDefault();
|
|
|
//
|
|
|
// // 获取企业信息
|
|
|
-// QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+// QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
// String openSecret = qwCompany.getOpenSecret();
|
|
|
// String token = getToken(corpId, openSecret);
|
|
|
//
|
|
|
@@ -626,56 +635,51 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
// }
|
|
|
|
|
|
public QwUploadImgResult uploadimgs(String url, String corpId) throws IOException {
|
|
|
-
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ QwApiParam param = new QwApiParam();
|
|
|
+ param.setUrl(url);
|
|
|
+ param.setCorpId(corpId);
|
|
|
+ ResponseEntity<QwApiResult> response = new RestTemplate().postForEntity(qwCompany.getQwApiUrl() + "/uploadImg", param, QwApiResult.class);
|
|
|
+ QwApiResult result = response.getBody();
|
|
|
+ if (result == null) {
|
|
|
+ log.error("返回错误,返回数据为空!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ log.info("请求结果:{}", JSON.toJSONString(result));
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ log.error("接口请求错误:{}", result.getMsg());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result.getData(), QwUploadImgResult.class);
|
|
|
+ }
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
-// CompanyConfig companyConfig = companyConfigService.selectCompanyConfigByKey(corpId, "sys:qw:config");
|
|
|
-// QWCompanyConfig qwCompanyConfig = JSON.parseObject(companyConfig.getConfigValue(), QWCompanyConfig.class);
|
|
|
-// String corpId = qwCompanyConfig.getCorpId();
|
|
|
-// String appSecret = qwCompanyConfig.getAppSecret();
|
|
|
-// String token = getToken(corpId, appSecret);
|
|
|
-// String open_corpid = qwCompanyConfig.getOpen_corpid();
|
|
|
-// String openSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
-
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
-
|
|
|
-
|
|
|
String openSecret = qwCompany.getOpenSecret();
|
|
|
-
|
|
|
String token = getToken(corpId, openSecret);
|
|
|
-
|
|
|
URIBuilder uriBuilder = null;
|
|
|
-
|
|
|
URL urlItem = new URL(url);
|
|
|
InputStream inputStream =urlItem.openStream();
|
|
|
-
|
|
|
try {
|
|
|
uriBuilder = new URIBuilder(QwApiConfig.uploadimg);
|
|
|
uriBuilder.setParameter("access_token", token);
|
|
|
URI uri = uriBuilder.build();
|
|
|
-
|
|
|
HttpPost httpPost = new HttpPost(uri);
|
|
|
-
|
|
|
// 构造表单数据
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
builder.addBinaryBody("image", inputStream, ContentType.create("image/jpeg"), UUID.randomUUID().toString());
|
|
|
-
|
|
|
// 构建表单实体
|
|
|
HttpEntity multipart = builder.build();
|
|
|
httpPost.setEntity(multipart);
|
|
|
-
|
|
|
// 发送请求
|
|
|
HttpResponse response = httpClient.execute(httpPost);
|
|
|
String json = EntityUtils.toString(response.getEntity());
|
|
|
-
|
|
|
QwUploadImgResult qwUploadImgResult = JSON.parseObject(json, QwUploadImgResult.class);
|
|
|
-
|
|
|
return qwUploadImgResult;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
|
inputStream.close();
|
|
|
}
|
|
|
-
|
|
|
return null;
|
|
|
}
|
|
|
/**
|
|
|
@@ -683,47 +687,54 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
*/
|
|
|
@Override
|
|
|
public QwUploadResult upload(File file, String type,String corpId) throws IOException {
|
|
|
-
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ QwApiParam param = new QwApiParam();
|
|
|
+ param.setFile(file);
|
|
|
+ param.setCorpId(corpId);
|
|
|
+ MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
|
|
+ body.add("file", new FileSystemResource(file));
|
|
|
+ body.add("corpId", corpId);
|
|
|
+ body.add("type", type);
|
|
|
+ // 设置请求头
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
+ // 创建请求实体
|
|
|
+ org.springframework.http.HttpEntity<MultiValueMap<String, Object>> requestEntity = new org.springframework.http.HttpEntity<>(body, headers);
|
|
|
+ ResponseEntity<QwApiResult> response = new RestTemplate().postForEntity(qwCompany.getQwApiUrl() + "/uploadFile", requestEntity, QwApiResult.class);
|
|
|
+ QwApiResult result = response.getBody();
|
|
|
+ if (result == null) {
|
|
|
+ log.error("返回错误,返回数据为空!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ log.info("请求结果:{}", JSON.toJSONString(result));
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ log.error("接口请求错误:{}", result.getMsg());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result.getData(), QwUploadResult.class);
|
|
|
+ }
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
-// CompanyConfig companyConfig = companyConfigService.selectCompanyConfigByKey(corpId, "sys:qw:config");
|
|
|
-// QWCompanyConfig qwCompanyConfig = JSON.parseObject(companyConfig.getConfigValue(), QWCompanyConfig.class);
|
|
|
-// String corpId = qwCompanyConfig.getCorpId();
|
|
|
-// String appSecret = qwCompanyConfig.getAppSecret();
|
|
|
-// String token = getToken(corpId, appSecret);
|
|
|
-//
|
|
|
-// String open_corpid = qwCompanyConfig.getOpen_corpid();
|
|
|
-// String openSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
-
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
-
|
|
|
String openSecret = qwCompany.getOpenSecret();
|
|
|
-
|
|
|
String token = getToken(corpId, openSecret);
|
|
|
-
|
|
|
URIBuilder uriBuilder = null;
|
|
|
try {
|
|
|
uriBuilder = new URIBuilder(QwApiConfig.upload);
|
|
|
uriBuilder.setParameter("access_token", token);
|
|
|
uriBuilder.setParameter("type", type);
|
|
|
URI uri = uriBuilder.build();
|
|
|
-
|
|
|
-
|
|
|
HttpPost httpPost = new HttpPost(uri);
|
|
|
// 构造表单数据
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
builder.addBinaryBody("media", file, ContentType.DEFAULT_BINARY, file.getName());
|
|
|
-
|
|
|
// 构建表单实体
|
|
|
HttpEntity multipart = builder.build();
|
|
|
httpPost.setEntity(multipart);
|
|
|
httpPost.setHeader("Content-Type", "multipart/form-data; charset=UTF-8");
|
|
|
-
|
|
|
// 发送请求
|
|
|
HttpResponse response = httpClient.execute(httpPost);
|
|
|
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
|
|
-
|
|
|
QwUploadResult qwUploadResult = JSON.parseObject(json, QwUploadResult.class);
|
|
|
-
|
|
|
return qwUploadResult;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -788,7 +799,7 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
// String open_corpid = qwCompanyConfig.getOpen_corpid();
|
|
|
// String openSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
|
|
|
// String open_corpid = qwCompany.getOpenCorpId();
|
|
|
String openSecret = qwCompany.getOpenSecret();
|
|
|
@@ -922,7 +933,7 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
|
|
|
@Override
|
|
|
public String getToken(String corpId,String corpSecret) {
|
|
|
- String key =(String)redisCache.getCacheObject("qwServer:corpId:" + corpId + ":" + corpSecret);
|
|
|
+ String key = redisCache.getCacheObject("qwServer:corpId:" + corpId + ":" + corpSecret);
|
|
|
if (!StringUtil.strIsNullOrEmpty(key)){
|
|
|
return key;
|
|
|
}
|
|
|
@@ -1084,6 +1095,28 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
*/
|
|
|
@Override
|
|
|
public String getServerQwUserName(String corpId,String Secret, String userid) {
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ QwApiParam param = new QwApiParam();
|
|
|
+ param.setUrl(QwApiConfig.getServerQwUserName);
|
|
|
+ param.setCorpId(corpId);
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("userid", userid);
|
|
|
+ param.setParam(map);
|
|
|
+ ResponseEntity<QwApiResult> response = new RestTemplate().postForEntity(qwCompany.getQwApiUrl() + "/post", param, QwApiResult.class);
|
|
|
+ QwApiResult result = response.getBody();
|
|
|
+ if (result == null) {
|
|
|
+ log.error("返回错误,返回数据为空!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ log.info("请求结果:{}", JSON.toJSONString(result));
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ log.error("接口请求错误:{}", result.getMsg());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result.getData());
|
|
|
+ return jsonObject.getString("name");
|
|
|
+ }
|
|
|
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
String name = "";
|
|
|
@@ -1111,7 +1144,10 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
*/
|
|
|
@Override
|
|
|
public QwJsapiTicketResult getQwUserid(String code,String corpId,String appSecret) {
|
|
|
-
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ return JSON.parseObject(sendGet(QwApiConfig.getuserinfo, MapUtil.builder("code",code).build(), corpId), QwJsapiTicketResult.class);
|
|
|
+ }
|
|
|
QwJsapiTicketResult qwResult=new QwJsapiTicketResult();
|
|
|
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
@@ -1146,7 +1182,13 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
qwResult.setCorpId(bookCorpId);
|
|
|
return qwResult;
|
|
|
}
|
|
|
-
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(bookCorpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ qwResult = JSON.parseObject(sendGet(QwApiConfig.getJsapiTicket, new HashMap<>(), bookCorpId), QwJsapiTicketResult.class);
|
|
|
+ qwResult.setCorpId(bookCorpId);
|
|
|
+ redisCache.setCacheObject("ticket:corpId"+":"+bookCorpId,qwResult.getTicket(),1,TimeUnit.HOURS);
|
|
|
+ return qwResult;
|
|
|
+ }
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
try {
|
|
|
URIBuilder builder = new URIBuilder(QwApiConfig.getJsapiTicket);
|
|
|
@@ -1183,7 +1225,13 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
qwResult.setCorpId(corpId);
|
|
|
return qwResult;
|
|
|
}
|
|
|
-
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ qwResult = JSON.parseObject(sendGet(QwApiConfig.jsapiTicket, MapUtil.builder("type", "agent_config").build(), corpId), QwJsapiTicketResult.class);
|
|
|
+ qwResult.setCorpId(corpId);
|
|
|
+ redisCache.setCacheObject("ticketApp:corpId"+":"+corpId,qwResult.getTicket(),1,TimeUnit.HOURS);
|
|
|
+ return qwResult;
|
|
|
+ }
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
try {
|
|
|
URIBuilder builder = new URIBuilder(QwApiConfig.jsapiTicket);
|
|
|
@@ -1218,7 +1266,7 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
|
|
|
// String open_corpid = qwCompanyConfig.getOpen_corpid();
|
|
|
// String openSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
|
|
|
// String open_corpid = qwCompany.getOpenCorpId();
|
|
|
String openSecret = qwCompany.getOpenSecret();
|
|
|
@@ -1277,14 +1325,10 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
*/
|
|
|
@Override
|
|
|
public QwGetMomentTaskResult getMomentTaskResult(String jobid, String corpId) {
|
|
|
-
|
|
|
-// CompanyConfig companyConfig = companyConfigService.selectCompanyConfigByKey(corpId, "sys:qw:config");
|
|
|
-// QWCompanyConfig qwCompanyConfig = JSON.parseObject(companyConfig.getConfigValue(), QWCompanyConfig.class);
|
|
|
-// String corpId = qwCompanyConfig.getCorpId();
|
|
|
-// String appSecret = qwCompanyConfig.getAppSecret();
|
|
|
-// String corpId = qwCompanyConfig.getOpen_corpid();
|
|
|
-// String appSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ return JSON.parseObject(sendGet(QwApiConfig.getMomentTaskResult, MapUtil.builder("jobid", jobid).build(), corpId), QwGetMomentTaskResult.class);
|
|
|
+ }
|
|
|
|
|
|
String appSecret = qwCompany.getOpenSecret();
|
|
|
|
|
|
@@ -1358,14 +1402,33 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
if (!StringUtil.strIsNullOrEmpty(key)){
|
|
|
return key;
|
|
|
}
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
if (qwCompany!=null&&qwCompany.getOpenSecret()!=null){
|
|
|
redisCache.setCacheObject("appSecret:corpId:" + corpId,qwCompany.getOpenSecret(),1,TimeUnit.HOURS);
|
|
|
return qwCompany.getOpenSecret();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
- public String sendPost(String url, Object param, String corpId) {
|
|
|
+ public String sendPost(String url, Object body, String corpId) {
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ QwApiParam param = new QwApiParam();
|
|
|
+ param.setUrl(url);
|
|
|
+ param.setCorpId(corpId);
|
|
|
+ param.setBody(JSON.parseObject(JSON.toJSONString(body)));
|
|
|
+ ResponseEntity<QwApiResult> response = new RestTemplate().postForEntity(qwCompany.getQwApiUrl() + "/post", param, QwApiResult.class);
|
|
|
+ QwApiResult result = response.getBody();
|
|
|
+ if (result == null) {
|
|
|
+ log.error("返回错误,返回数据为空!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ log.info("请求结果:{}", JSON.toJSONString(result));
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ log.error("接口请求错误:{}", result.getMsg());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return result.getData();
|
|
|
+ }
|
|
|
int maxRetries = 3; // 最大重试次数
|
|
|
int retryCount = 0; // 当前重试次数
|
|
|
// 1. 获取配置信息(可放在循环外,但要确保每次都能获取到最新的token)
|
|
|
@@ -1378,7 +1441,7 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
builder.setParameter("access_token", getToken(corpId, appSecret));
|
|
|
URI uri = builder.build();
|
|
|
HttpPost httpPost = new HttpPost(uri);
|
|
|
- httpPost.setEntity(new StringEntity(JSON.toJSONString(param), StandardCharsets.UTF_8));
|
|
|
+ httpPost.setEntity(new StringEntity(JSON.toJSONString(body), StandardCharsets.UTF_8));
|
|
|
HttpResponse response = httpClient.execute(httpPost);
|
|
|
// 3. 解析结果
|
|
|
String reJson = EntityUtils.toString(response.getEntity());
|
|
|
@@ -1402,7 +1465,7 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
|
|
|
// public String sendPost(String url,Object param,String corpId){
|
|
|
//
|
|
|
-// QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+// QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
//
|
|
|
// String appSecret = qwCompany.getOpenSecret();
|
|
|
//
|
|
|
@@ -1423,20 +1486,30 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
// return null;
|
|
|
// }
|
|
|
|
|
|
- public String sendBookPost(String url,Object param,String corpId){
|
|
|
-
|
|
|
-// CompanyConfig companyConfig = companyConfigService.selectCompanyConfigByKey(corpId, "sys:qw:config");
|
|
|
-// QWCompanyConfig qwCompanyConfig = JSON.parseObject(companyConfig.getConfigValue(), QWCompanyConfig.class);
|
|
|
-//获取通讯录的
|
|
|
-// String corpId = qwCompanyConfig.getCorpId();
|
|
|
-// String bookSecret = qwCompanyConfig.getBookSecret();
|
|
|
-// String corpId = qwCompanyConfig.getOpen_corpid();
|
|
|
-// String bookSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
-
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
-
|
|
|
+ public String sendBookPost(String url,QwOpenidByUserParams body,String corpId){
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ QwApiParam param = new QwApiParam();
|
|
|
+ param.setUrl(url);
|
|
|
+ param.setCorpId(corpId);
|
|
|
+ param.setBookSecret(true);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("userid", body.getUserid());
|
|
|
+ param.setBody(map);
|
|
|
+ ResponseEntity<QwApiResult> response = new RestTemplate().postForEntity(qwCompany.getQwApiUrl() + "/post", param, QwApiResult.class);
|
|
|
+ QwApiResult result = response.getBody();
|
|
|
+ if (result == null) {
|
|
|
+ log.error("返回错误,返回数据为空!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ log.info("请求结果:{}", JSON.toJSONString(result));
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ log.error("接口请求错误:{}", result.getMsg());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return result.getData();
|
|
|
+ }
|
|
|
String bookSecret = qwCompany.getServerBookSecret();
|
|
|
-
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
try {
|
|
|
URIBuilder builder = new URIBuilder(url);
|
|
|
@@ -1444,7 +1517,7 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
builder.setParameter("access_token", getToken(corpId,bookSecret));
|
|
|
URI uri = builder.build();
|
|
|
HttpPost httpPost = new HttpPost(uri);
|
|
|
- httpPost.setEntity( new StringEntity(JSON.toJSONString(param),StandardCharsets.UTF_8));
|
|
|
+ httpPost.setEntity( new StringEntity(JSON.toJSONString(body),StandardCharsets.UTF_8));
|
|
|
HttpResponse response = httpClient.execute(httpPost);
|
|
|
String reJson = EntityUtils.toString(response.getEntity());
|
|
|
return reJson;
|
|
|
@@ -1501,8 +1574,30 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
|
|
|
@Override
|
|
|
public QwUserIdResult getUserList(String corpId) {
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("limit", 10000);
|
|
|
+ String res = sendPost(QwApiConfig.getUserListUrl, map, corpId);
|
|
|
+// QwApiParam param = new QwApiParam();
|
|
|
+// param.setUrl(QwApiConfig.getUserListUrl);
|
|
|
+// param.setCorpId(corpId);
|
|
|
+// param.setBookSecret(true);
|
|
|
+// Map<String, Object> map = new HashMap<>();
|
|
|
+// map.put("limit", 10000);
|
|
|
+// param.setBody(map);
|
|
|
+// ResponseEntity<QwApiResult> response = new RestTemplate().postForEntity(qwCompany.getQwApiUrl() + "/post", param, QwApiResult.class);
|
|
|
+// QwApiResult result = response.getBody();
|
|
|
+// if (result == null) {
|
|
|
+// throw new BaseException("返回错误,返回数据为空!");
|
|
|
+// }
|
|
|
+// log.info("请求结果:{}", JSON.toJSONString(result));
|
|
|
+// if (result.getCode() != 200) {
|
|
|
+// throw new BaseException("接口请求错误:{}", result.getMsg());
|
|
|
+// }
|
|
|
+ return JSON.parseObject(res, QwUserIdResult.class);
|
|
|
+ }
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
String bookSecret = qwCompany.getServerBookSecret();
|
|
|
try {
|
|
|
URIBuilder builder = new URIBuilder(QwApiConfig.getUserListUrl);
|
|
|
@@ -1526,14 +1621,10 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
|
|
|
@Override
|
|
|
public QwDeptResult getDepartmentList(String corpId) {
|
|
|
-//// CompanyConfig companyConfig = companyConfigService.selectCompanyConfigByKey(corpId, "sys:qw:config");
|
|
|
-//// QWCompanyConfig qwCompanyConfig = JSON.parseObject(companyConfig.getConfigValue(), QWCompanyConfig.class);
|
|
|
-//// String corpId = qwCompanyConfig.getCorpId();
|
|
|
-//// String bookSecret = qwCompanyConfig.getBookSecret();
|
|
|
-// String corpId = qwCompanyConfig.getOpen_corpid();
|
|
|
-// String bookSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
-//
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ return JSON.parseObject(sendGet(QwApiConfig.getDepartmentList, new HashMap<>(), corpId), QwDeptResult.class);
|
|
|
+ }
|
|
|
|
|
|
String bookSecret = qwCompany.getOpenSecret();
|
|
|
|
|
|
@@ -1555,14 +1646,10 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
|
|
|
@Override
|
|
|
public QwExternalContactListResult getExternalcontactList(String userId,String corpId) {
|
|
|
-//
|
|
|
-//// CompanyConfig companyConfig = companyConfigService.selectCompanyConfigByKey(corpId, "sys:qw:config");
|
|
|
-//// QWCompanyConfig qwCompanyConfig = JSON.parseObject(companyConfig.getConfigValue(), QWCompanyConfig.class);
|
|
|
-//// String corpId = qwCompanyConfig.getCorpId();
|
|
|
-//// String appSecret = qwCompanyConfig.getAppSecret();
|
|
|
-// String corpId = qwCompanyConfig.getOpen_corpid();
|
|
|
-// String appSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ return JSON.parseObject(sendGet(QwApiConfig.externalcontactListUrl, MapUtil.builder("userid", userId).build(), corpId), QwExternalContactListResult.class);
|
|
|
+ }
|
|
|
|
|
|
String appSecret = qwCompany.getOpenSecret();
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
@@ -1585,6 +1672,10 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
|
|
|
@Override
|
|
|
public QwExternalContactResult getExternalcontact(String userId,String corpId) {
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ return JSON.parseObject(sendGet(QwApiConfig.externalcontactUrl, MapUtil.builder("external_userid", userId).build(), corpId), QwExternalContactResult.class);
|
|
|
+ }
|
|
|
String appSecret = getAppSecret(corpId);
|
|
|
|
|
|
String token = getToken(corpId, appSecret);
|
|
|
@@ -1605,6 +1696,24 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public String sendGet(String url, Map<String, String> map,String corpId) {
|
|
|
+ String appSecret = getAppSecret(corpId);
|
|
|
+ String token = getToken(corpId, appSecret);
|
|
|
+ HttpClient httpClient = HttpClients.createDefault();
|
|
|
+ try {
|
|
|
+ URIBuilder builder = new URIBuilder(url);
|
|
|
+ builder.setParameter("access_token", token);
|
|
|
+ map.forEach(builder::setParameter);
|
|
|
+ URI uri = builder.build();
|
|
|
+ HttpGet httpGet = new HttpGet(uri);
|
|
|
+ HttpResponse response = httpClient.execute(httpGet);
|
|
|
+ return EntityUtils.toString(response.getEntity());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public QwExternalContactAllListResult getAllExternalcontactList(QwExternalListParam param,String corpId) {
|
|
|
String json = sendPost(QwApiConfig.externalcontactAllLlistUrl, param,corpId);
|
|
|
@@ -1845,17 +1954,29 @@ public class QwApiServiceImpl implements QwApiService {
|
|
|
* 封装的post请求
|
|
|
*/
|
|
|
public String templateResultPost(JSONObject object, String url,String corpId){
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
+ if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
|
|
|
+ QwApiParam param = new QwApiParam();
|
|
|
+ param.setUrl(url);
|
|
|
+ param.setCorpId(corpId);
|
|
|
+ param.setBody(JSON.parseObject(JSON.toJSONString(object)));
|
|
|
+ ResponseEntity<QwApiResult> response = new RestTemplate().postForEntity(qwCompany.getQwApiUrl() + "/post", param, QwApiResult.class);
|
|
|
+ QwApiResult result = response.getBody();
|
|
|
+ if (result == null) {
|
|
|
+ log.error("返回错误,返回数据为空!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ log.info("请求结果:{}", JSON.toJSONString(result));
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ log.error("接口请求错误:{}", result.getMsg());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return result.getData();
|
|
|
+ }
|
|
|
HttpClient httpClient = HttpClients.createDefault();
|
|
|
URIBuilder builder = null;
|
|
|
try {
|
|
|
builder = new URIBuilder(url);
|
|
|
-//// CompanyConfig companyConfig = companyConfigService.selectCompanyConfigByKey(corpId, "sys:qw:config");
|
|
|
-//// QWCompanyConfig qwCompanyConfig = JSON.parseObject(companyConfig.getConfigValue(), QWCompanyConfig.class);
|
|
|
-//// String corpId = qwCompanyConfig.getCorpId();
|
|
|
-//// String appSecret = qwCompanyConfig.getAppSecret();
|
|
|
-// String corpId = qwCompanyConfig.getOpen_corpid();
|
|
|
-// String appSecret = qwCompanyConfig.getOpen_Secret();
|
|
|
- QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
|
|
|
String appSecret = qwCompany.getOpenSecret();
|
|
|
|