微信小程序怎么把用户登录数据储存在云数据库user表

// js页面
const db = wx.cloud.database();
const user = db.collection('user')
Page({
  data: {
    userInfo: {},
    hasUserInfofalse,
    canIUseGetUserProfilefalse,
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfiletrue
      })
    }
  },
  getUserProfile(e) {
    wx.getUserProfile({
      desc'用于记录用户数据',
      success(res) => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfotrue
        })
      }
    })
  }
})
<!--wxml页面-->
<view class="container">
  <view class="userinfo">
    <block wx:if="{{!hasUserInfo}}">
      <button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
    </block>
    <block wx:else>
      <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
      <text class="userinfo-nickname">{{userInfo.nickName}}</text>
    </block>
  </view>
</view>

需要用到云函数获取用户openid或者服务器端语言通过iv数据解密encryptedData得到openid实现用户信息和openid的绑定,客户端wx.getUserProfile不包含openid的
云函数获取openid参考
https://ask.csdn.net/questions/7612082
https://developers.weixin.qq.com/community/business/doc/000e26815e8de0db1ecae5a035b00d

服务器端获取openid

云数据库插入记录

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632