提交 77fae2c1 authored 作者: 李勤's avatar 李勤

完成代码

上级 3cffdd7a
......@@ -58,8 +58,10 @@ public class KingdeeApiClient {
}
public void execute(String serviceName, Object[] parameters) throws Exception {
String cookie = HttpUtil.login(this._serverUrl);
Map<String, Object> header = new HashMap<>(1);
header.put("cookie", this._cookieStore);
header.put("cookie", cookie);
Map<String, Object> request = new HashMap<>(1);
request.put("parameters", parameters);
......
package org.jeecg.modules.iost.ims.kingdeeapi;
import org.jeecg.modules.iost.ims.Util.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -185,7 +189,52 @@ public class HttpUtil {
//发送请求
return toPost(url, httpHeaders, json);
}
public static String login(String serverUrl) {
try {
Map<String, Object> request = new HashMap<>(1);
request.put("parameters", new Object[]{"6441e19c2fbbe1", "Administrator", "sa123.sa", 2052});
String url = serverUrl + "Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc";
String requestStr = JsonUtil.toString(request);
ResponseEntity<String> responseEntity = HttpUtil.httpPost(url, requestStr);
if (responseEntity.getStatusCode() == HttpStatus.OK) {
Map<String, Object> map = JsonUtil.toMap(responseEntity.getBody(), String.class, Object.class);
if (!CollectionUtils.isEmpty(map) && 1 == Integer.parseInt(String.valueOf(map.get("LoginResultType")))) {
return getCookieStore(responseEntity);
} else {
return "";
}
} else {
return "";
}
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
private static String getCookieStore(ResponseEntity<String> responseEntity) {
String cookieStore = "";
Set<String> keys = responseEntity.getHeaders().keySet();
for (String key : keys) {
if (key.equalsIgnoreCase("Set-Cookie")) {
List<String> cookieList = responseEntity.getHeaders().get(key);
if (!CollectionUtils.isEmpty(cookieList)) {
for (String cookie : cookieList) {
if (cookie.startsWith("Set-Cookie")) {
cookieStore = cookie;
break;
}
}
}
}
}
return cookieStore;
}
/**
* 发送请求
*/
......@@ -194,6 +243,7 @@ public class HttpUtil {
ResponseEntity<String> result = null;
try {
result = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
}
catch(Exception ex)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论