修改对照

This commit is contained in:
lvleigang 2024-10-30 14:05:58 +08:00
parent db93567ca4
commit a1eafd905f
4 changed files with 92 additions and 10 deletions

View File

@ -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);
}

View File

@ -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,7 +402,14 @@ public class U9CPluginServiceImpl implements IU9CPluginService {
String res = null;
Boolean flag = false;
try {
JSONObject token = getToken("admin", "800045", "8000450000");
//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);
@ -406,6 +417,12 @@ public class U9CPluginServiceImpl implements IU9CPluginService {
}else {
res = token.getString("msg");
}
}else {
res = usercode.getString("msg");
}
}else {
res = nouserToken.getString("msg");
}
}catch (Exception e){
logger.error("调用oa接口出错:{}",e);
res = e.getMessage();
@ -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");
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;
}
}

View File

@ -11,6 +11,8 @@ public class SysExtensionApiEntity {
private Map<String, String> 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;
}
}

View File

@ -1840,6 +1840,7 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
}
headers = sysExtensionApiEntity.getHeaders();
String querys = sysExtensionApiEntity.getQuerys();
String addquerys = sysExtensionApiEntity.getAddQuerys();
String bodys = sysExtensionApiEntity.getBodys();
//设置参数获取参数
StringBuffer url = new StringBuffer();
@ -1851,6 +1852,9 @@ public class SysApplicationServiceImpl extends BaseService<SysApplicationEntity,
url.append("?");
url.append(querys);
}
if (addquerys != null) {
url.append(querys);
}
Integer outTime = 6000;
if (receiveApi.getTimeoutPeriod() != null && !"".equals(receiveApi.getTimeoutPeriod())) {
outTime = Integer.valueOf(receiveApi.getTimeoutPeriod());