Recently, a project used proprietary Dingding, here is a record of the process of using proprietary Dingding to obtain user information

One: Process

1: Obtain the user's non-logging authorization code

2: Obtain user information according to the non-logging authorization code

Two: Obtain user information

1: Obtain the user's login-free authorization code

Use js to get the user's login-free authorization code

<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>

As above, the user's login-free authorization code can be obtained, and then we can use the user's login-free authorization code to obtain the user's basic information

2: Obtain user information according to the login-free authorization code

(1): Obtain access_token, specific reference: https://blog.csdn.net/huaweichenai/article/details/118325521

(2): Obtain basic user information

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'];//用户信息
}

The specific information obtained is as follows
image.png


huaweichenai
695 声望115 粉丝

引用和评论

0 条评论