// 跨小程序单点登录(SSO):从 cfc 跳转到训练营(train)小程序。 // 复用方式:页面按钮 @click 调 jumpToTrain() 即可;后端已用一次性票据免二次微信授权。 import { createSsoTicket } from './api.js' // 训练营小程序 AppID const TRAIN_APPID = 'wxcf0ed181fc3bce50' // 训练营落地页(App.onLaunch 会读取 query.ssoTicket 换票登录) const TRAIN_LANDING_PATH = 'pages/index/index' /** 已登录用户跳到训练营:签发一次性票据 → navigateToMiniProgram */ export function jumpToTrain() { if (!uni.getStorageSync('token')) { uni.showToast({ title: '请先登录', icon: 'none' }) return } uni.showLoading({ title: '跳转中...' }) createSsoTicket('train').then(function(res) { uni.hideLoading() var ticket = res && res.data && res.data.ticket if (!ticket) { uni.showToast({ title: '签发失败,请稍后重试', icon: 'none' }) return } uni.navigateToMiniProgram({ appId: TRAIN_APPID, path: TRAIN_LANDING_PATH + '?ssoTicket=' + encodeURIComponent(ticket), fail: function() { uni.showToast({ title: '跳转失败,请确认已关联训练营小程序', icon: 'none' }) } }) }).catch(function() { uni.hideLoading() }) }