wafer2的keng

一、之前用wafer2开发的小程序,今天突然Error: 用户未登录过,请先使用 login() 登录?

答:改用qcloud.login, 替换掉qcloud.loginWithCode (小程序代码)

参考链接:https://blog.csdn.net/kfgauss/article/details/91046421

二、小程序Cannot set property 'userInfo' of undefined

//this.globalData.userInfo = res.userInfo;
var app = getApp();
app.globalData.userInfo = res.userInfo;

Cannot set property 'userInfo' of undefined
不要使用this

参考链接:https://blog.51cto.com/lailai/2068184

三、wafer2二次登录时,报:用户未登录过,请先使用 login() 登录

request fail Error: 用户未登录过,请先使用 login() 登录
at n.success (login.js:141)
at Object.success (WAService.js:4)
at s. (WAService.js:12)
at s.emit (WAService.js:6)
at Function. (WAService.js:12)
at WAService.js:6
at a (appservice?t=1528991705772:1048)
at b. (appservice?t=1528991705772:1048)
at b.emit (appservice?t=1528991705772:1048)
at callback (appservice?t=1528991705772:1048)
index.js:128 request complete

Node.js SDK 更新了吗,需要配合 1.4.x 版本以上的 SDK

参考链接:

1. https://github.com/tencentyun/wafer2-quickstart-nodejs/issues/14

2. https://github.com/tencentyun/wafer2-startup/issues/143

四、Unexpected token o in JSON at position 1 报错原因

解决方案就是去掉JSON.parse()这一层转换,因为你需要转换的数据本来就是一个json对象了,不需要在转换了。

(我不知道,我重启就好了

参考链接:

1. https://blog.csdn.net/wxl1555/article/details/79184076

2. https://blog.csdn.net/qq_41999617/article/details/83511002

五、登陆失败,请允许获取您的公开信息

根据微信公告,wx.getUserInfo 接口将不再弹窗,而改用 <button>。目前 Wafer2 的 Demo 已经切换,以下主要对 Wafer2 SDK 的实现进行说明。

Wafer2 SDK 的授权登录模式改为:前端 <button> 弹出登录框,用户点击授权之后,SDK 调用 wx.login 和 wx.getUserInfo 获取用户信息,并解密,存储数据库。

注意 2.0 版本以上的 Client SDK 需配合 1.4.x 以上版本的 Node.js SDK 或者 2.2.x 以上版本的 PHP SDK。

// wxml
<button open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="doLogin">获取用户信息</button>

// js
doLogin: function () {
    const session = qcloud.Session.get()

    if (session) {
        // 第二次登录
        // 或者本地已经有登录态
        // 可使用本函数更新登录态
        qcloud.loginWithCode({
            success: res => {
                this.setData({ userInfo: res, logged: true })
                util.showSuccess('登录成功')
            },
            fail: err => {
                console.error(err)
                util.showModel('登录错误', err.message)
            }
        })
    } else {
        // 首次登录
        qcloud.login({
            success: res => {
                this.setData({ userInfo: res, logged: true })
                util.showSuccess('登录成功')
            },
            fail: err => {
                console.error(err)
                util.showModel('登录错误', err.message)
            }
        })
    }
}

参考链接:

1. https://github.com/tencentyun/wafer2-client-sdk#%E7%99%BB%E5%BD%95

2. https://github.com/tencentyun/wafer2-client-sdk/issues/28

3. https://github.com/tencentyun/wafer2-quickstart/issues/10

猜你喜欢

转载自www.cnblogs.com/lfri/p/11909683.html
2
>&2
今日推荐