钉钉登录二维码嵌套在vue页面中
转自 https://www.csdn.net/tags/OtDacg3sMjQ2NTgtYmxvZwO0O0OO0O0O.html
<template>
<div id="app">
<div id="login_container"></div>
</div>
</template>
<script>
import axios from "axios"; export default {
name: "App",
components: {},
data() {
return {
appid: "dingb3x07ieb8wrwmw81",
redirectUrl: "https://console.huishouzx.com/login",
apiUrl:
"<用户信息接口,把redirectUrl回调获取的CODE给后端用于获取扫码用户信息>",
dingCodeConfig: {
id: "login_container",
style: "border:none;background-color:#FFFFFF;",
width: "365",
height: "400",
},
};
},
computed: {
getRedirectUrl() {
return encodeURIComponent(this.redirectUrl);
},
getAuthUrl() {
returnhttps://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${this.appid}&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${this.getRedirectUrl};
},
getGoto() {
return encodeURIComponent(this.getAuthUrl);
},
getDingCodeConfig() {
return { ...this.dingCodeConfig, goto: this.getGoto };
},
},
created() {
//调用
this.initDingJs();
},
mounted() {
this.addDingListener();
this.initDingLogin();
this.getUser();
},
methods: {
initDingJs() {
!(function (window, document) {
function d(a) {
var e,
c = document.createElement("iframe"),
d = "https://login.dingtalk.com/login/qrcode.htm?goto=" + a.goto;
(d += a.style ? "&style=" + encodeURIComponent(a.style) : ""),
(d += a.href ? "&href=" + a.href : ""),
(c.src = d),
(c.frameBorder = "0"),
(c.allowTransparency = "true"),
(c.scrolling = "no"),
(c.width = a.width ? a.width + "px" : "365px"),
(c.height = a.height ? a.height + "px" : "400px"),
(e = document.getElementById(a.id)),
(e.innerHTML = ""),
e.appendChild(c);
}window.DDLogin = d;
})(window, document);
},
addDingListener() {
let self = this; let handleLoginTmpCode = function (loginTmpCode) {
window.location.href =
self.getAuthUrl + `&loginTmpCode=${loginTmpCode}`;
}; let handleMessage = function (event) {
if (event.origin == "https://login.dingtalk.com") {
handleLoginTmpCode(event.data);
}
}; if (typeof window.addEventListener != "undefined") {
window.addEventListener("message", handleMessage, false);
} else if (typeof window.attachEvent != "undefined") {
window.attachEvent("onmessage", handleMessage);
}
},
initDingLogin() {
window.DDLogin(this.getDingCodeConfig);
},
getUser() {
let getQueryString = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}; let code = getQueryString("code"); if (code !== null) {
axios
.get(`${this.apiUrl}?code=${code}`)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
}
},
},
};
</script><style>
app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>



钉钉登录二维码嵌套在vue页面中的更多相关文章
- 微信长按识别二维码,在 vue 项目中的实现
微信长按识别二维码是 QQ 浏览器的内置功能,该功能的基础一定要使用 img 标签引入图片,其他方式的二维码无法识别. 在 vue 中使用 QrcodeVue 插件 demo1 在 template ...
- C#生成二维码,把二维码图片放入Excel中
/// <summary> /// 把图片保存到excel中 /// </summary> /// <param name="excelFilePath&quo ...
- 基于SignalR的消息推送与二维码描登录实现
1 概要说明 使用微信扫描登录相信大家都不会陌生吧,二维码与手机结合产生了不同应用场景,基于二维码的应用更是比较广泛.为了满足ios.android客户端与web短信平台的结合,特开发了基于Singl ...
- 网站实现微信登录之嵌入二维码——基于yii2开发的描述
之前写了一篇yii2获取登录前的页面url地址的文章,然后发现自己对于网站实现微信扫码登录功能的实现不是很熟悉,所以,我会写2-3篇的文章来描述下一个站点如何实现微信扫码登录的功能,来复习下微信扫码登 ...
- spring boot高性能实现二维码扫码登录(上)——单服务器版
前言 目前网页的主流登录方式是通过手机扫码二维码登录.我看了网上很多关于扫码登录博客后,发现基本思路大致是:打开网页,生成uuid,然后长连接请求后端并等待登录认证相应结果,而后端每个几百毫秒会循环查 ...
- spring boot高性能实现二维码扫码登录(中)——Redis版
前言 本打算用CountDownLatch来实现,但有个问题我没有考虑,就是当用户APP没有扫二维码的时候,线程会阻塞5分钟,这反而造成性能的下降.好吧,现在回归传统方式:前端ajax每隔1秒或2秒发 ...
- spring boot高性能实现二维码扫码登录(下)——订阅与发布机制版
前言 基于之前两篇(<spring boot高性能实现二维码扫码登录(上)——单服务器版>和<spring boot高性能实现二维码扫码登录(中)——Redis版>)的基础, ...
- .net实现扫描二维码登录webqq群抓取qq群信息
一.流程 1. //获得二维码的qrsig,cookie标志 2. //登录二维码获得二维码的状态,及最新的url 3. //登录此网址,获得Cookies 4.//cookies,筛选出skey信息 ...
- PC 商城扫描二维码登录
需求分析: 扫码入口,在pc登录首页新增二维码登录入口 点击扫码入口显示二维码 二维码有效时间为一分钟 超时后显示二维码失效,点击刷新后生成新的二维码 在app端用户登录并扫码后,点击确认登录,进行跳 ...
随机推荐
- C#编写程序,计算数组中奇数之和和偶数之和
编写程序,计算数组中奇数之和和偶数之和. 代码: using System; using System.Collections.Generic; using System.Linq; using Sy ...
- nodejs教程---基于expressJs框架,实现文件上传(upload)?
文件上传功能在nodejs初期是一件很难实现的功能,之后出现了formidable勉强能解决这个问题,但是express框架出现之后基于这个框架开发的中间件有更好的方法来处理文件上传,这个中间件就是m ...
- 网络编程学习——Linux epoll多路复用模型
前言 后端开发的应该都知道Nginx服务器,Nginx是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器.后端部署中一般使用的就是Nginx反向代理技术. ...
- Elasticsearch 使用-安装
Elasticsearch 使用-安装 官方网站 https://www.elastic.co/cn/elasticsearch/ 什么是 Elasticsearch? Elasticsearch 是 ...
- 学习打卡day12&构建之法阅读笔记第一篇
今天浅读了<构建之法>的前四章,稍微有一些个人的见解与感受 第一点即是开篇提及到的算法与数据结构这门学科开设的必要,大二上学期学习了这门课程,就我个人目前接触到的层面来看,几乎可以说用不太 ...
- HbuilderX失焦时自动保存编辑器内容
hbuilderX 有一个非常好用的功能:就是自动保存. 而且不需要安装什么插件,只需要在编辑器设置就可以了.接下来我们一起来设置吧: 1.打开我们的hbuilderX编辑器.在最上排选项栏里打开 & ...
- python爬虫---字体反爬
目标地址:http://glidedsky.com/level/web/crawler-font-puzzle-1 打开google调试工具检查发现网页上和源码之中的数字不一样, 已经确认该题目为 字 ...
- 最大数maxnumber - 题解【树状数组】
原题: 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. 插入操作.语法 ...
- 打基础丨Python图像处理入门知识详解
摘要:本文讲解图像处理基础知识和OpenCV入门函数. 本文分享自华为云社区<[Python图像处理] 一.图像处理基础知识及OpenCV入门函数>,作者: eastmount. 一.图像 ...
- 【虚拟机】VMware-open-vm-tools安装
open-vm-tools(VMware-tools的进化版) VMware Tool 和 open-vm-tools任选一样安装即可 在终端进入超级用户 换源下载,依次输入下面命令 sudo cp ...
