钉钉扫码登录

Posted canyingv

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了钉钉扫码登录相关的知识,希望对你有一定的参考价值。

1.方式一

//登录
    public function login(){
        $config=config(‘ding‘);
        $app = new Application($config);
        $response = $app->oauth->use(‘app-01‘)->withQrConnect()->redirect();
        return $response;
    }
 //登录回调
    public function loginCallback(){
        $state=Request::param(‘state‘);
        $config=config(‘ding‘);
        $app = new Application($config);
        $user = $app->oauth->use(‘app-01‘)->stateless()->user();
        dump($user);die;
    }

2.方式二

放到需要展示二维码的地方,回调同上
<div id="login_container"></div> <script> var obj = DDLogin({ id:"login_container", goto: encodeURIComponent("https://oapi.dingtalk.com/connect/oauth2/sns_authorize" + "?appid=dingoayms9jntgrrcofsre&response_type=code&scope=snsapi_login&state=STATE&redirect_uri="+"http://datav.site888.cn/dingd/Index/loginCallback"), //请参考注释里的方式 style: "border:none;background-color:#FFFFFF;", width : "365", height: "400" }); var handleMessage = function (event) { var origin = event.origin; console.log("origin", event.origin); if( origin == "https://login.dingtalk.com" ) { //判断是否来自ddLogin扫码事件。 var loginTmpCode = event.data; //获取到loginTmpCode后就可以在这里构造跳转链接进行跳转了 var url2="https://oapi.dingtalk.com/connect/oauth2/sns_authorize" + "?appid=dingoayms9jntgrrcofsre&response_type=code&scope=snsapi_login" + "&state=STATE&redirect_uri="+encodeURIComponent("https://oapi.dingtalk.com/connect/oauth2/sns_authorize" + "?appid=dingoayms9jntgrrcofsre&response_type=code&scope=snsapi_login&state=STATE&redirect_uri="+"http://datav.site888.cn/dingd/Index/loginCallback")+"&loginTmpCode="+loginTmpCode; window.location.href=url2; console.log("loginTmpCode", loginTmpCode); } }; if (typeof window.addEventListener != "undefined") { window.addEventListener("message", handleMessage, false); } else if (typeof window.attachEvent != "undefined") { window.attachEvent("onmessage", handleMessage); } </script>

 

以上是关于钉钉扫码登录的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot实现专有钉钉扫码登录

钉钉扫码登录

JavaWeb开发初步实现网站应用钉钉扫码登录

钉钉扫码登录 java

钉钉扫码登录web网站

django 钉钉扫码登录