wafer2-node-sdk icon indicating copy to clipboard operation
wafer2-node-sdk copied to clipboard

无法从userInfo中获取openid

Open qz1543706741 opened this issue 3 years ago • 0 comments
trafficstars

建议修改: /lib/auth/index.js

debug('Auth: encryptedData: %s, iv: %s', encryptedData, iv)

// 获取 session key
return getSessionKey(code)
        .then(pkg => {
            const { session_key, openid } = pkg
            // 生成 3rd_session
            const skey = sha1(session_key)

            // 解密数据
            let decryptedData
            try {
                decryptedData = aesDecrypt(session_key, iv, encryptedData)
                decryptedData = JSON.parse(decryptedData)
            } catch (e) {
                debug('Auth: %s: %o', ERRORS.ERR_IN_DECRYPT_DATA, e)
                throw new Error(`${ERRORS.ERR_IN_DECRYPT_DATA}\n${e}`)
            }

            // 存储到数据库中
            return AuthDbService.saveUserInfo(Object.assign(decryptedData, {openId: openid}) , skey, session_key).then(userinfo => ({
                loginState: LOGIN_STATE.SUCCESS,
                userinfo
            }))
        })

qz1543706741 avatar Jun 20 '22 15:06 qz1543706741