钉钉登录

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>

 

posted @ 2020-08-11 09:05  CanyingV  阅读(459)  评论(0编辑  收藏  举报