# 海外 - 统一登录
如果活动页登录无特殊要求(如弹窗登录),统一接入登录页实现登录流程
# 接入方法
正式环境登录页:https://goldenspatula.com/act/authentication/?returnURL=&lang=
测试环境登录页:https://test.goldenspatula.com/act/authentication/?returnURL=&lang=&env=test
参数
returnURL
:登录后的回跳地址,需要经过Base64
编码:btoa(location.href)
不用encodeURIComponent
的原因:登录跳转已经解码 decodeURIComponent 过一次了,如果是 hash 路由会截断 hash 部分,导致读取不全参数
lang
:页面语言,如果为空则优先读取浏览器语言。可设置 中 英 泰:zh、en、th参数
env=test
:测试环境必须携带用于区分,正式环境必须删掉此参数
接入示例
// 页面语言
const currentLang = ...
// 跳转到正式环境登录页、语言为当前页面语言
location.href = `https://goldenspatula.com/act/authentication/?returnURL=${btoa(location.href)}&lang=${currentLang}`
# 获取登录信息
引入 milo
<script src="https://goldenspatula.com/act/milo-next/milo.js"></script>
const getLoginInfo = () => {
const res = Milo.checkLogin();
if (res.iRet === 0) {
// 已登录
// 获取用户名、平台、头像
const { userName, channelid, pictureUrl } = res.userInfo
let plat = "";
if (channelid === 4) {
plat = "Facebook";
} else if (channelid === 15) {
plat = "Apple";
} else if (channelid === 6) {
plat = "Google";
} else {
plat = "Email";
}
} else {
// 未登录
}
}
# 注销登录
const logout = () => {
Milo.logout();
location.reload();
}