diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/dgx/u9c/service/IU9CPluginService.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/dgx/u9c/service/IU9CPluginService.java index 818f745e..492dee4d 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/dgx/u9c/service/IU9CPluginService.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/dgx/u9c/service/IU9CPluginService.java @@ -1,6 +1,9 @@ package com.hzya.frame.plugin.dgx.u9c.service; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.sysnew.application.entity.SysApplicationEntity; +import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity; import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity; import com.hzya.frame.web.entity.JsonResultEntity; @@ -32,4 +35,7 @@ public interface IU9CPluginService { * @param taskLivingDetail 日志表对象 */ void saveLog(String integration_task_living_details_id, Boolean flag, IntegrationTaskLivingDetailsEntity taskLivingDetail); + //根据应用key和应用密钥获取应用编码和应用名称 + public SysExtensionApiEntity setQueryUrl(SysExtensionApiEntity sysExtensionApiEntity); + } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/dgx/u9c/service/impl/U9CPluginServiceImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/dgx/u9c/service/impl/U9CPluginServiceImpl.java index 946295f3..3ac1edff 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/dgx/u9c/service/impl/U9CPluginServiceImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/dgx/u9c/service/impl/U9CPluginServiceImpl.java @@ -3,14 +3,18 @@ package com.hzya.frame.plugin.dgx.u9c.service.impl; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.hzya.frame.plugin.dgx.u9c.entity.*; import com.hzya.frame.plugin.dgx.u9c.service.*; +import com.hzya.frame.sysnew.application.entity.SysApplicationEntity; +import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity; import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity; import com.hzya.frame.sysnew.integtationTaskLivingDetails.service.IIntegrationTaskLivingDetailsService; import com.hzya.frame.web.entity.BaseResult; import com.hzya.frame.web.entity.JsonResultEntity; import org.apache.commons.collections.CollectionUtils; +import org.bson.types.Code; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -398,13 +402,26 @@ public class U9CPluginServiceImpl implements IU9CPluginService { String res = null; Boolean flag = false; try { - JSONObject token = getToken("admin", "800045", "8000450000"); - if(token.getBoolean("flag")){ - res = invokeEsb(param, "800045", "8000450002",token.getString("token")); - JSONObject jsonObject = JSONObject.parseObject(res); - flag = jsonObject.getBoolean("flag"); + //1、获取token + JSONObject nouserToken = getToken(null, "800045", "8000450000"); + if(nouserToken.getBoolean("flag")){ + //2、根据电话获取code + JSONObject usercode = getUsercode(nouserToken.getString("token"),"13924608800", "800045", "8000450005"); + if(usercode.getBoolean("flag")){ + //3、根据code,再次获取token + JSONObject token = getToken(usercode.getString("code"), "800045", "8000450000"); + if(token.getBoolean("flag")){ + res = invokeEsb(param, "800045", "8000450002",token.getString("token")); + JSONObject jsonObject = JSONObject.parseObject(res); + flag = jsonObject.getBoolean("flag"); + }else { + res = token.getString("msg"); + } + }else { + res = usercode.getString("msg"); + } }else { - res = token.getString("msg"); + res = nouserToken.getString("msg"); } }catch (Exception e){ logger.error("调用oa接口出错:{}",e); @@ -431,6 +448,40 @@ public class U9CPluginServiceImpl implements IU9CPluginService { return BaseResult.getSuccessMessageEntity("德广信U9C请购单推送OA插件执行成功"); } + private JSONObject getUsercode(String token, String phone, String appId,String apiCode) { + JSONObject param = new JSONObject(); + param.put("phone",phone); + param.put("token",token); + + JSONObject returnData = new JSONObject(); + + String res = null; + String code = null; + Boolean flag = false; + + try { + res = invokeEsb(param, appId, apiCode,null); + JSONObject jsonObject = JSONObject.parseObject(res); + flag = jsonObject.getBoolean("flag"); + if(flag){ + code = jsonObject.getJSONObject("attribute").getString("id"); + } + }catch (Exception e){ + logger.error("调用oa接口出错:{}",e); + res = e.getMessage(); + } + if(flag){ + returnData.put("flag","true"); + //todo + returnData.put("code","admin"); + //returnData.put("code",code); + }else { + returnData.put("flag","false"); + returnData.put("msg",res); + } + return returnData; + } + /** * @Author lvleigang * @Description 获取token @@ -441,11 +492,12 @@ public class U9CPluginServiceImpl implements IU9CPluginService { * @return com.alibaba.fastjson.JSONObject **/ private JSONObject getToken(String code,String appId,String apiCode) { - JSONObject param = new JSONObject(); param.put("userName","hzyaRest"); param.put("password","3ca9a8d7-43df-4101-8de2-8bb113cb9145"); - param.put("loginName",code); + if(code != null){ + param.put("loginName",code); + } JSONObject returnData = new JSONObject(); String res = null; @@ -453,7 +505,7 @@ public class U9CPluginServiceImpl implements IU9CPluginService { Boolean flag = false; try { - res = invokeEsb(param, "800045", "8000450000",null); + res = invokeEsb(param, appId, apiCode,null); JSONObject jsonObject = JSONObject.parseObject(res); flag = jsonObject.getBoolean("flag"); if(flag){ @@ -473,7 +525,6 @@ public class U9CPluginServiceImpl implements IU9CPluginService { return returnData; } - /** * 保存日志 * @@ -537,4 +588,15 @@ public class U9CPluginServiceImpl implements IU9CPluginService { logger.info("调用:{},返回参数:{}",apiCode,result); return result; } + + //根据应用key和应用密钥获取应用编码和应用名称 + @Override + public SysExtensionApiEntity setQueryUrl(SysExtensionApiEntity sysExtensionApiEntity) { + String bodys = sysExtensionApiEntity.getBodys(); + JSONObject jsonObject = JSON.parseObject(bodys); + String url = jsonObject.getString("phone")+"?token="+jsonObject.getString("token"); + sysExtensionApiEntity.setAddQuerys(url); + return sysExtensionApiEntity; + } + } diff --git a/base-service/src/main/java/com/hzya/frame/sysnew/application/entity/SysExtensionApiEntity.java b/base-service/src/main/java/com/hzya/frame/sysnew/application/entity/SysExtensionApiEntity.java index baff9a85..3bbda189 100644 --- a/base-service/src/main/java/com/hzya/frame/sysnew/application/entity/SysExtensionApiEntity.java +++ b/base-service/src/main/java/com/hzya/frame/sysnew/application/entity/SysExtensionApiEntity.java @@ -11,6 +11,8 @@ public class SysExtensionApiEntity { private Map headers; /** query */ private String querys; + /** query */ + private String addQuerys; /** body */ private String bodys; //byteBodys @@ -77,5 +79,13 @@ public class SysExtensionApiEntity { public void setByteBodys(byte[] byteBodys) { this.byteBodys = byteBodys; } + + public String getAddQuerys() { + return addQuerys; + } + + public void setAddQuerys(String addQuerys) { + this.addQuerys = addQuerys; + } } diff --git a/base-service/src/main/java/com/hzya/frame/sysnew/application/service/impl/SysApplicationServiceImpl.java b/base-service/src/main/java/com/hzya/frame/sysnew/application/service/impl/SysApplicationServiceImpl.java index b6ad01cd..935a07e6 100644 --- a/base-service/src/main/java/com/hzya/frame/sysnew/application/service/impl/SysApplicationServiceImpl.java +++ b/base-service/src/main/java/com/hzya/frame/sysnew/application/service/impl/SysApplicationServiceImpl.java @@ -1840,6 +1840,7 @@ public class SysApplicationServiceImpl extends BaseService