最近有个我的项目用到了专有钉钉,这里记录下应用专有钉钉获取用户信息流程

一:流程

1:获取用户的免登受权码

2:依据免登受权码获取用户信息

二:获取用户信息

1:获取用户免登录受权码

应用js获取用户的免登录受权码

<script src="https://g.alicdn.com/gdt/jsapi/1.3.2/index.js"></script><script>    dd.ready(function () {        dd.getAuthCode({}).then((result) =>{            if (result) {                var code = result.code;//获取受权登录码            }        }).catch(err => {            alert(err);        })    })</script>

如上就能够获取到用户的免登录受权码,上面咱们就能够应用用户的免登录受权码来获取用户的根本信息

2:依据免登录受权码获取用户信息

(1):获取access_token,具体参考:https://blog.csdn.net/huaweichenai/article/details/118325521

(2):获取用户根本信息

try {    $executableClient = new ExecutableClient();    //Saas环境域名为:https://openplatform.dg-work.cn,浙政钉环境域名为:https://openplatform-pro.ding.zj.gov.cn    $executableClient->setDomain('域名');    $executableClient->setAccessKey('利用App Key');    $executableClient->setSecretKey('利用App Secret');    $executableClient->setApiName('/rpc/oauth2/dingtalk_app_user.json');    //print("Get形式执行...\n");    $executableClient->addParameter('access_token', '获取access_token接口获取到的信息');    $executableClient->addParameter('auth_code', '用户的免登录受权码');    //$ret = $executableClient->epaasCurlGet(3);    $ret = $executableClient->epaasCurlGet(3);} catch (\Exception $e) {    $msg = "getFilterWords|err, code: ". $e->getCode() . "|message: ". $e->getMessage();    Yii::error($msg);    throw new ForbiddenHttpException('获取失败,请分割管理员!');}if (isset($ret['success']) && $ret['success'] == true) {    $result = $ret['data'];//用户信息}

具体获取到的信息如下