以为谷小程序为例
一、获取client_id及client_secret
(1)登录:https://open.jdy.com/#/home 获取clientID及client_secret
注:若没有应用则需要先创建应用,创建流程:https://open.jdy.com/#/files/api/detail?index=3&categrayId=316e1f5bd9d711ed8e36c17691e84ff5&id=a540e3dcd9d811ed8e3677dc79b66e86

(2)进入登录页面:

二、点击“点击登录”按钮跳转至金蝶授权页面
金蝶auth2授权流程
点击跳转授权页面(获取code 需要通过金蝶授权页面授权后获得)
https://passport.kingdee.com/passport/#/auth/oauth2/third_login?pck=ok&&client_id=${client_id}&&response_type=code&&redirect_uri=${encodeURIComponent(`https://xc-7gd05hys8cce9f91-1252872213.tcloudbaseapp.com/wgyH5/xch5/index.html#/pages/login/loginH5?client_id=${client_id}&client_secret=${client_secret}`)}
注:需要参数:client_id ,client_secret,
redirect_uri 为授权登录成功后跳转的H5 页面,为了接收从金蝶授权页面返回的code,例:
https://xc-7gd05hys8cce9f91-1252872213.tcloudbaseapp.com/wgyH5/xch5/index.html#/pages/login/loginH5
配置H5白名单地址,登录云平台:https://cloud.kingdee.com/console/#/service/kae?path=%2F%23%2Fapp%2Fmine%2Fservice%2Fauth%3Fapp_id%3D261445%26sid%3D1%26menuType%3D2
注:不配置白名单会提示redirect_uri 未注册

示例:

参数:
| 参数名 | 必选 | 类型 | 说明 |
| client_id | 是 | string | 应用id |
| response_type | 是 | string | 固定填写 code |
| redirect_uri | 是 | string | 接收code的页面地址 |
金蝶授权页面 loginH5 页面:该页面接收code
三、通过金蝶授权登录页面返回的code获取access_token
获取access_token接口:
`https://api.kingdee.com/auth/oauth2/access_token?client_id=${client_id}&client_secret=${client_secret}&grant_type=authorization_code&code=${code}&redirect_uri=${encodeURIComponent('https://xc-7gd05hys8cce9f91-1252872213.tcloudbaseapp.com/wgyH5/xch5/index.html#/pages/login/loginH5')}`
需要参数:client_id、client_secret、code、redirect_uri为跳转H5地址
----------------------------------------------------------------------------------------------------------------------------------
curl --location 'https://api.kingdee.com/auth/oauth2/access_token?client_id=261433&client_secret=&grant_type=authorization_code&redirect_uri=http%3A%2F%2F192.168.4.50%3A5173%2F&code=1711075344dabb1af20bc2dd543ceffb' \
--header 'authority: api.kingdee.com' \
--header 'accept: */*' \
--header 'accept-language: zh-CN,zh;q=0.9' \
--header 'content-type: application/json;charset=UTF-8' \
--header 'origin: http://192.168.224.1:5173' \
--header 'referer: http://192.168.224.1:5173/' \
--header 'sec-fetch-dest: empty' \
--header 'sec-fetch-mode: cors' \
--header 'sec-fetch-site: cross-site' \
--header 'user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1' \
--header 'Cookie: AC_NG_SESN=fjQCYoxhq0lJRtcLTNGxNg|1711079041|y_FfFBppKDF6-m2ILtlC6A|lSmmNUtJGe-C5zPGpTGB7F_DTHY; PHPSESSID=26469146-25f7-4b38-8a8e-6666d62c7a03; PHPSESSID2=26469146-25f7-4b38-8a8e-6666d62c7a03; PPSESSION=26469146-25f7-4b38-8a8e-6666d62c7a03' \
--data '{}'
示例:

参数:
| 参数名 | 必选 | 类型 | 说明 |
| client_id | 是 | string | 应用id |
| client_secret | 是 | string | 应用密匙 |
| redirect_uri | 是 | String | 编码后的跳转url |
| grant_type | 是 | string | 固定填写authorization_code |
| code | 是 | String | 获取到code |
四、获取账套信息
接口:https://api.kingdee.com/jdyaccount/sys/accountGroup?access_token=
请求方式:POST
获取接口返回的serviceAddr、groupName、accountId

五、获取当前登录用户信息
接口:https://api.kingdee.com/weigusoft/basedata/get_current_user_info?access_token=
请求方式:POST
参数header= { 'X-GW-Router-Addr': serviceAddr,
'Content-Type': 'application/json;charset=utf-8',
access_token,
groupName,
accountId
};
获取用户信息后缓存用户信息及header信息
跳转至首页即可