java实现钉钉扫码登录

前端

<script type="text/javascript">
	const APP_ID = '${DING_APP_ID}';
	const APP_SECRET = '${DING_APP_SECRET}';
	const REDIRECT_URI = '${DING_REDIRECT_URI}';
	const GOTO_url = "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid="+APP_ID+"&response_type=code&scope=snsapi_login&state=STATE&redirect_uri="+REDIRECT_URI;
	/*
	* 解释一下goto参数,参考以下例子:
	* var url = encodeURIComponent('http://localhost.me/index.php?test=1&aa=2');
	* var goto = encodeURIComponent('https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=appid&response_type=code&scope=snsapi_login&state=STATE&redirect_uri='+url)
	*/
	$(function () {
   
		var obj = DDLogin({
   
			id:"login_container",//这里需要你在自己的页面定义一个HTML标签并设置id,例如<div id="login_container"></div>或<span id="login_container"></span>
			goto: encodeURIComponent(GOTO_url), //请参考注释里的方式
			style: "border:none;background-color:#FFFFFF;",
			width : "365",
			height: "400"
		});
		console.log(APP_ID,APP_SECRET,REDIRECT_URI);
		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后就可以在这里构造跳转链接进行跳转了

				console.log("loginTmpCode", loginTmpCode);
				window.location.href =
						"https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid="+APP_ID+"&response_type=code&scope=snsapi_login&state=STATE&redirect_uri="+REDIRECT_URI+"&loginTmpCode="+loginTmpCode;

			}
		};
		if (typeof window.addEv
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值