浙里办微信小程序单点登录流程
1.获取浙里办跳转地址中ticket或者微信小程序中的ticketId
let ticket = getQueryString("ticket", window.location.href);
let sp = getQueryString("sp", window.location.href);
let ticketId = getQueryString("ticketId", window.location.href);
if (ticket) {
ticket = ticket.replace("#/", "");
}
console.log("拿到用户信息后跳转到测试地址前", sp, ticket, ticketId);
if (sp) {
sp = sp.replace("#/", "");
console.log("拿到用户信息后跳转到测试地址", sp, ticket);
if (sp.indexOf("?") != -1) {
window.location.href = sp + "&ticket=" + ticket;
} else {
window.location.href = sp + "?ticket=" + ticket;
}
console.log("ticket", ticket);
return false;
}
2.判断一下当前环境并且去缓存中拿到用户信息
const sUserAgent = window.navigator.userAgent.toLowerCase();
const bIsAlipayMini =
sUserAgent.indexOf("miniprogram") > -1 &&
sUserAgent.indexOf("alipay") > -1;
const isWx = sUserAgent.indexOf("micromessenger") > -1;
let userInfo = window.sessionStorage.getItem("userInfo");
3.判断一下是否存在用户信息,如果存在按照当前环境去进行跳转
if (!userInfo) {
console.log("进入userInfo-----ticketId", isWx, ticketId);
if (isWx) {
// 微信小程序中的单点登录组件,获取 ticketId
this.wxApply();
console.log("微信小程序--走链接后", window.location.href);
} else if (bIsAlipayMini && !ticket && !ticketId) {
//支付宝app
this.watchApply();
} else if (!ticket && !ticketId) {
//浙里办app
this.watchApp();
}
if (ticket) {
console.log("ticket--存在", ticket);
this.getUserInfo(ticket);
}
}