收藏
回答

wx.login调用限频问题?求帮助

// 根据openid查询用户的登陆状态

async initUserInfo({ statecommitdispatch }) {

uni.showLoading({ title: "Loading…"mask: true });

try {

let wxCode = await getWxCode();

// 直接调用登录接口登录

let userInfo = await dispatch("loginHandle", {

gyAppCode: wxCode

});

uni.hideLoading();

return userInfo;

catch (err) {

const pages = getCurrentPages();

const currentPage = pages[pages.length - 1];

// 排除 unbound/expired 页自身,避免登录成功后又跳回这两个页面

const excludePages = ["pageSubPackages/common/unbound/index""pageSubPackages/common/expired/index"];

let params = {};

let time = 0;

if (excludePages.includes(currentPage.route)) {

// 已在 unbound/expired 页,透传原始业务页信息

if (currentPage.options?.loginParams) {

params.loginParams = currentPage.options.loginParams;

}

time = 800;

else {

params.loginParams = JSON.stringify({

type: "reLaunch",

url: "/" + currentPage.route,

params: { ...currentPage.options }

});

}

currentPage.$vm.$addPoint({ oid: 99999deed: 0extendInfo: JSON.stringify(err) });

uni.hideLoading();

// 留够时间看到pageSubPackages/common/unbound/index登录失败的提示

setTimeout(() => {

// 登录接口只要异常 一直跳转到未绑定页增加小程序pv访问次数 防止wx.login接口异常导致用户无法使用小程序的情况(小程序规定wx.login接口调用次数不超过当天pv量的2倍)

uni.$u.route({

type: "reLaunch",

url: "/pageSubPackages/common/unbound/index",

params

});

}, time);

return Promise.reject(err);

}

},

上面是个登录的方法

/pageSubPackages/common/unbound/index“ 这是未登录页。

总体逻辑是用户打开小程序触发这个登录 未登录会reLaunch到那个登录页 这个页面有个登录按钮点击还是调用这个方法 如果用户一直在当前unbound页一直点击登录按钮 那么如果没有绑定关系还是无法登录那就reLaunch还是当前页就相当于点一次异常后就reLaunch,点一次异常后就reLaunch 无限点就无限reLaunch

我这样调用登录方法会触发wx.login一次 我们的系统逻辑没有登录会重定向到unbound页 会增加pc一次吧? 如果是这样 那么wx.login 打开比应该永远不会超过1 只会无限接近于1 我观察了几天微信小程序后台接口调用比 发现有超过1的天数 这是怎么回事呢 pv到底是啥统计维度 当前页reLaunch当前页会增加pv吗?那为啥比例还能超1呢


回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 本次回答由AI生成
    03-19
    有用 1
登录 后发表内容