Explorar o código

转发优化提交

yjwang hai 6 días
pai
achega
fe0bff52ce

+ 32 - 10
fs-service/src/main/java/com/fs/qwApi/service/impl/QwApiServiceImpl.java

@@ -1166,7 +1166,7 @@ public class QwApiServiceImpl implements QwApiService {
     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);
+            return JSON.parseObject(sendGet(QwApiConfig.getuserinfo, MapUtil.builder("code",code).build(), corpId,false), QwJsapiTicketResult.class);
         }
 
         QwJsapiTicketResult qwResult=new QwJsapiTicketResult();
@@ -1205,7 +1205,7 @@ public class QwApiServiceImpl implements QwApiService {
         }
         QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(bookCorpId);
         if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
-            qwResult = JSON.parseObject(sendGet(QwApiConfig.getJsapiTicket, new HashMap<>(), bookCorpId), QwJsapiTicketResult.class);
+            qwResult = JSON.parseObject(sendGet(QwApiConfig.getJsapiTicket, new HashMap<>(), bookCorpId,false), QwJsapiTicketResult.class);
             qwResult.setCorpId(bookCorpId);
             redisCache.setCacheObject("ticket:corpId"+":"+bookCorpId,qwResult.getTicket(),1,TimeUnit.HOURS);
             return qwResult;
@@ -1250,7 +1250,7 @@ public class QwApiServiceImpl implements QwApiService {
 
         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 = JSON.parseObject(sendGet(QwApiConfig.jsapiTicket, MapUtil.builder("type", "agent_config").build(), corpId,false), QwJsapiTicketResult.class);
             qwResult.setCorpId(corpId);
             redisCache.setCacheObject("ticketApp:corpId"+":"+corpId,qwResult.getTicket(),1,TimeUnit.HOURS);
             return qwResult;
@@ -1350,7 +1350,7 @@ public class QwApiServiceImpl implements QwApiService {
     public QwGetMomentTaskResult getMomentTaskResult(String jobid, String 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);
+            return JSON.parseObject(sendGet(QwApiConfig.getMomentTaskResult, MapUtil.builder("jobid", jobid).build(), corpId,false), QwGetMomentTaskResult.class);
         }
 //        CompanyConfig companyConfig = companyConfigService.selectCompanyConfigByKey(corpId, "sys:qw:config");
 //        QWCompanyConfig qwCompanyConfig = JSON.parseObject(companyConfig.getConfigValue(), QWCompanyConfig.class);
@@ -1662,7 +1662,7 @@ public class QwApiServiceImpl implements QwApiService {
 //
         QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
         if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
-            return JSON.parseObject(sendGet(QwApiConfig.getDepartmentList, new HashMap<>(), corpId), QwDeptResult.class);
+            return JSON.parseObject(sendGet(QwApiConfig.getDepartmentList, new HashMap<>(), corpId,false), QwDeptResult.class);
         }
 
         String bookSecret = qwCompany.getOpenSecret();
@@ -1694,7 +1694,7 @@ public class QwApiServiceImpl implements QwApiService {
 //        String appSecret = qwCompanyConfig.getOpen_Secret();
         QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(corpId);
         if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
-            return JSON.parseObject(sendGet(QwApiConfig.externalcontactListUrl, MapUtil.builder("userid", userId).build(), corpId), QwExternalContactListResult.class);
+            return JSON.parseObject(sendGet(QwApiConfig.externalcontactListUrl, MapUtil.builder("userid", userId).build(), corpId,false), QwExternalContactListResult.class);
         }
 
         String appSecret = qwCompany.getOpenSecret();
@@ -1720,7 +1720,7 @@ public class QwApiServiceImpl implements QwApiService {
     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);
+            return JSON.parseObject(sendGet(QwApiConfig.externalcontactUrl, MapUtil.builder("external_userid", userId).build(), corpId,false), QwExternalContactResult.class);
         }
         String appSecret = getAppSecret(corpId);
 
@@ -1742,9 +1742,31 @@ 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);
+    public String sendGet(String url, Map<String, String> map,String corpId, boolean bookSecret) {
+        QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
+        if(StringUtils.isNotEmpty(qwCompany.getQwApiUrl())){
+            QwApiParam param = new QwApiParam();
+            param.setUrl(url);
+            param.setCorpId(corpId);
+            param.setParam(map);
+            param.setBookSecret(bookSecret);
+            ResponseEntity<QwApiResult> response = new RestTemplate().postForEntity(qwCompany.getQwApiUrl() + "/get", 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 secret = bookSecret ? qwCompany.getServerBookSecret() : getAppSecret(corpId);
+        String token = getToken(corpId, secret);
         HttpClient httpClient = HttpClients.createDefault();
         try {
             URIBuilder builder = new URIBuilder(url);