tencentyun / wafer2-node-sdk

Wafer2 SDK for Node.js
Other
268 stars 58 forks source link

无法从userInfo中获取openid #61

Open qz1543706741 opened 2 years ago

qz1543706741 commented 2 years ago

建议修改: /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
            }))
        })