Files
useds/app/view/index/qrcode.html
T
2026-01-05 14:33:21 +08:00

47 lines
1.9 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>飞书扫码登录示例</title>
<!-- 引入二维码 SDK -->
<script src="https://lf-package-cn.feishucdn.com/obj/feishu-static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.3.js"></script>
</head>
<body>
<!-- 二维码展示容器 -->
<div id="login_container" style="width:500px;height:600px;"></div>
<script>
// 1. 配置你的参数
// const CLIENT_ID = '你的_APP_ID';
// const REDIRECT_URI = encodeURIComponent('https://example.com/api/oauth/callback/feishu');
// const STATE = '随机串_防CSRF';
// // 用于跳转获取 code 的 URL
const GOTO = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=cli_a72f13d6c022500d&redirect_uri=https://web-fdesk.hnxinyouhe.com/auth/feishu-callback&response_type=code&state=MZL`;
// const GOTO = `https://open.feishu.cn/open-apis/authen/v1/authorize?app_id=cli_a73e1e6406fa501c&redirect_uri=https://mzl.dev.hnxinyouhe.com/common/auth/feishu/auth&scope=contact:user.base:readonly contact:contact.base:readonly contact:user.employee_id:readonly im:message:send_as_bot&state=xinyouhe`;
// 2. 创建二维码实例
const QRLoginObj = QRLogin({
id: 'login_container',
goto: GOTO,
width: '500',
height:'500'
});
// 3. 监听扫码并授权后的消息
function handleMessage(event) {
// 校验来源和数据合法性
if (QRLoginObj.matchOrigin(event.origin) && QRLoginObj.matchData(event.data)) {
console.log(event.data);
// return;
const tmpCode = event.data.tmp_code;
// 带上 tmp_code 重定向到后端回调接口
window.location.href = `${GOTO}&tmp_code=${tmpCode}`;
}
}
window.addEventListener
? window.addEventListener('message', handleMessage, false)
: window.attachEvent('onmessage', handleMessage);
</script>
</body>
</html>