【最简入门】金蝶 WebAPI 的三种登录方式(金蝶云星空、K3Cloud、login、授权、鉴权、身份验证)
## 1:ValidateUser
- 概要
- 先登录(**`用户名+密码`**),后访问
- 注意事项
- 登录状态通过 `Cookie` 实现,由登录 API 的响应头返回(`kdservice-sessionid`、`ASP.NET_SessionId` 等),后续 API 请求头需要携带
- 有效期为 60 分钟,需要建立过期刷新机制
- 举例
- 步骤一(登录):Kingdee.BOS.WebApi.ServicesStub.AuthService.**`ValidateUser`**.common.kdsvc
- request
```shell
$ curl -i 'https://**********/k3cloud/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc' \
--header 'Content-Type: application/json' \
--data '{
"acctid":"**********",
"username":"**********",
"password":"**********",
"lcid":2052
}'
```
- response
```http
HTTP/1.1 200 OK
...
Set-Cookie: tgw_l7_route=a0677c17e2bc19032412589344174893; Expires=Fri, 23-Feb-2024 04:02:57 GMT; Path=/
Set-Cookie: kdservice-sessionid=e08a5a8d-4b82-4fbe-834c-c39d7c832802; expires=Fri, 23-Feb-2024 04:02:57 GMT; path=/; secure; HttpOnly
Set-Cookie: ASP.NET_SessionId=ncovjqmxsfskmg1xq45o1cec; path=/; secure; HttpOnly; SameSite=Lax
...
{"Message":null,"MessageCode" ...
```
- 步骤二(查询):Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.**`ExecuteBillQuery`**.common.kdsvc
- request
```shell
$ curl -i 'https://**********/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.QueryBusinessInfo.common.kdsvc' \
--header 'Content-Type: application/json' \
--header 'Cookie: ASP.NET_SessionId=ncovjqmxsfskmg1xq45o1cec; kdservice-sessionid=e08a5a8d-4b82-4fbe-834c-c39d7c832802; tgw_l7_route=a0677c17e2bc19032412589344174893' \
--data '{
"data": {
"FormId": "BD_Department"
}
}'
```
- response
```http
HTTP/1.1 200 OK
...
{"Result":{"ResponseStatus":{"IsSuccess":true, ...
```
## 2:LoginByAppSecret
- 概要
- 先登录([**`应用ID+应用密钥`**](https://wenku.my7c.com/article/22914)),后访问
- 注意事项
- 登录状态通过 `Cookie` 实现,由登录 API 的响应头返回(`kdservice-sessionid`、`ASP.NET_SessionId` 等),后续 API 请求头需要携带
- 有效期为 60 分钟,需要建立过期刷新机制
- 举例
- 步骤一(登录):Kingdee.BOS.WebApi.ServicesStub.AuthService.**`LoginByAppSecret`**.common.kdsvc
- request
```shell
$ curl -i 'https://**********/k3cloud/Kingdee.BOS.WebApi.ServicesStub.AuthService.LoginByAppSecret.common.kdsvc' \
--header 'Content-Type: application/json' \
--data '{
"acctid":"**********",
"username":"**********",
"appid":"**********",
"appsecret":"**********",
"lcid":2052
}'
```
- response
```http
HTTP/1.1 200 OK
...
Set-Cookie: tgw_l7_route=cfcff4e304a5cbf7fbf51c6387351967; Expires=Fri, 23-Feb-2024 04:18:44 GMT; Path=/
Set-Cookie: kdservice-sessionid=1bffb30f-7dbb-40f7-bd60-697e39951cd4; expires=Fri, 23-Feb-2024 04:18:44 GMT; path=/; secure; HttpOnly
Set-Cookie: ASP.NET_SessionId=cbrgw0aimcznsxo33wlyptyc; path=/; secure; HttpOnly; SameSite=Lax
...
{"Message":null,"MessageCode" ...
```
- 步骤二(查询):Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.**`ExecuteBillQuery`**.common.kdsvc
- request
```shell
$ curl -i 'https://**********/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.QueryBusinessInfo.common.kdsvc' \
--header 'Content-Type: application/json' \
--header 'Cookie: ASP.NET_SessionId=cbrgw0aimcznsxo33wlyptyc; kdservice-sessionid=1bffb30f-7dbb-40f7-bd60-697e39951cd4; tgw_l7_route=cfcff4e304a5cbf7fbf51c6387351967' \
--data '{
"data": {
"FormId": "BD_Department"
}
}'
```
- response
```http
HTTP/1.1 200 OK
...
{"Result":{"ResponseStatus":{"IsSuccess":true, ...
```
## 3:AuthenBySign(推荐使用)
- 概要
- 直接访问,请求头内携带签名信息,签名信息由[**`应用ID+应用密钥`**](https://wenku.my7c.com/article/22914)计算(`算法一般内置在SDK中`)得出
- 注意事项
- 无状态,每次访问通过请求头信息(`X-Kd-Appkey`、`X-Kd-Appdata`、`X-Kd-Signature` 等)鉴权
- 举例
- 步骤一(查询):Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.**`ExecuteBillQuery`**.common.kdsvc
- request
```shell
$ curl -i 'https://**********/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.QueryBusinessInfo.common.kdsvc' \
--header 'Content-Type: application/json' \
...
--header 'X-Kd-Appkey: **********' \
--header 'X-Kd-Appdata: **********' \
--header 'X-Kd-Signature: **********' \
...
--data '{
"data": {
"FormId": "BD_Department"
}
}'
```
- response
```http
HTTP/1.1 200 OK
...
{"Result":{"ResponseStatus":{"IsSuccess":true, ...
```
第三种方法试了以后结果是:{"Result":{"ResponseStatus":{"ErrorCode":500,"IsSuccess":false,"Errors":[{"FieldName":null,"Message":"会话信息已丢失,请重新登录","DIndex":0}],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":1}}} 请问header里面还需要带什么吗
tgw_l7_route 这个参数是如何获取或生成的?谢谢
【最简入门】金蝶 WebAPI 的三种登录方式(金蝶云星空、K3Cloud、login、授权、鉴权、身份验证)
## 1:ValidateUser- 概要 - 先登录(**`用户名+密码`**),后访问- 注意事项 - 登录状态通过 `Cookie` 实现,由登录 API 的...
点击下载文档
上一篇:制造费用如何按工单消耗材料占比进行分配下一篇:日常处理问题总结
本文2024-09-16 18:11:13发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-20507.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章