How to use cloud functions to get the openId of the applet user? Proceed as follows:
- If you have not opened cloud development, please read this
- The basic library version needs to be 2.3.3 or higher , and it is recommended to set it to the latest version
- New cloud function:
- Right click
cloudfunctions
and select新建Node.js云函数
- enter
login
- Now the cloud development console looks like:
- This function saves the openID to local storage and calls it when an error occurs
error
:
function saveOpenID(error) {
if (!wx.getStorageSync('openID')) {
wx.cloud.callFunction({
name: 'login',
data: {
},
success: res => {
console.log('Got user openid: ', res.result.openid)
wx.setStorageSync('openID', res.result.openid)
},
fail: err => {
console.error(err)
error()
}
})
}
}