从堆栈看大概是t.refreshAuth这个函数出问题了 [图片]
errCode: -601022 | errMsg: 找不到对应的FunctionName在react的useEffect里使用官方提供的云登录示例见code在instance.init时出错了:errCode: -601022 | errMsg: 找不到对应的FunctionName[图片] 见代码: useEffect(async () => { // try { require('../utils/cloud'); // 公众号基本信息:请修改下列字段使用本示例 const WX_RESOURCE_APPID = 'wxeb151f49f6b2beea'; /* 资源方 AppID */ const WX_RESOURCE_ENVID = 'youhuima-7g2kzr7h9e6d34f7'; /* 资源方云开发环境 ID */ const WX_OFFICIAL_ACCOUNT_APPID = 'wx3e4700970958fcec'; /* 公众号 AppID */ const WX_AUTH_TYPE = 'snsapi_base'; /* 选择需要的授权方式,snsapi_base 或 snsapi_userinfo */ const WX_REDIRECT_URI = 'http://m.youhuima.life/'; /* 回调 URL */ // 示例配置 const isPersistLoginInfo = false; // 是否需要保留登录态信息到 window 中,只有 snsapi_userinfo 方式需要 if (window.wx) { window.cloud = wx.cloud; } var urlSearch = new URLSearchParams(location.search); var accessToken = urlSearch.get('access_token'); var refreshToken = urlSearch.get('refresh_token'); const checkLoginOptions = { provider: 'OfficialAccount', appid: WX_OFFICIAL_ACCOUNT_APPID, }; if (urlSearch.get('oauthredirect') === '1') { checkLoginOptions.accessToken = accessToken; checkLoginOptions.refreshToken = refreshToken; } console.log(`checkLogin options: `, checkLoginOptions); const result = await cloud.checkLogin(checkLoginOptions); console.log(`checkLogin result: `, result); if (isPersistLoginInfo) window.checkLoginRes = result; if (result.errCode === 0 && result.loggedIn) { console.log(`checkLogin success`); const instance = (window.instance = new cloud.Cloud({ appid: WX_OFFICIAL_ACCOUNT_APPID, resourceAppid: WX_RESOURCE_APPID, resourceEnv: WX_RESOURCE_ENVID, })); console.log('--------initial-----', instance); const initResult = await instance.init(); console.log('--------initial done ----'); // console.log(`instance inited`, initResult); console.log(`can use cloud instance to access resource now !`); // const els = [...document.getElementsByClassName('display-none')]; // els.forEach((el) => el.classList.remove('display-none')); } else { console.log( `checkLogin with sdk errCode ${result.errCode} errMsg ${result.errMsg}, will start oauth in 10s` ); });
2021-03-26