APICloud:跨平台开发技术的演进之路
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了APICloud:跨平台开发技术的演进之路相关的知识,希望对你有一定的参考价值。
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>
以上是关于APICloud:跨平台开发技术的演进之路的主要内容,如果未能解决你的问题,请参考以下文章
APICloud开发者进阶之路|[ 模块教程 ] UIAlbumBrowser模块效果展示