java调用金蝶云接口_第三方系统调用金蝶K/3CloudWebAPI实现登录验证的两种方法-南阳金蝶...
时间: 2023-12-10 07:37:43 浏览: 108
这篇文章主要介绍了第三方系统如何调用金蝶K/3CloudWebAPI实现登录验证的两种方法,分别是使用HttpClient和使用RestTemplate,其中包括了具体的代码实现和调用流程。
使用HttpClient调用金蝶K/3CloudWebAPI的登录接口,需要进行如下步骤:
1. 创建HttpClient对象,并设置请求头信息。
2. 创建HttpPost请求对象,并设置请求参数。
3. 执行HttpPost请求,并获取响应结果。
4. 解析响应结果,获取sessionId。
5. 使用sessionId进行后续的操作。
以下是使用HttpClient实现调用金蝶K/3CloudWebAPI登录接口的示例代码:
```
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(params, "UTF-8");
entity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(entity);
CloseableHttpResponse response = httpClient.execute(httpPost);
String result = EntityUtils.toString(response.getEntity(), "UTF-8");
String sessionId = JSONObject.parseObject(result).getString("SessionId");
```
使用RestTemplate调用金蝶K/3CloudWebAPI的登录接口,需要进行如下步骤:
1. 创建RestTemplate对象,并设置请求头信息。
2. 创建请求参数对象,并设置请求参数。
3. 执行POST请求,并获取响应结果。
4. 解析响应结果,获取sessionId。
5. 使用sessionId进行后续的操作。
以下是使用RestTemplate实现调用金蝶K/3CloudWebAPI登录接口的示例代码:
```
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.set("Cookie", "KDS_SessionId=" + sessionId);
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("userID", userId);
map.add("password", password);
map.add("accountID", accountId);
map.add("lcid", lcid);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
String response = restTemplate.postForObject(url, request, String.class);
String sessionId = JSONObject.parseObject(response).getString("SessionId");
```
以上就是调用金蝶K/3CloudWebAPI实现登录验证的两种方法。需要注意的是,在使用RestTemplate时,需要设置请求头中的Cookie信息,以便于后续操作的进行。同时,也需要注意安全性问题,避免敏感信息泄露。
阅读全文
相关推荐














