const util = require('../utils/util.js'); const openidStatus = () => { console.log(wx.getStorageSync('openId'),'缓存里是否有openid') if (wx.getStorageSync('openId')) { return wx.getStorageSync('openId') } else { return new Promise((resolve, reject) => { wx.login({ success: (res) => { if (res.code) { wx.request({ url: util.globalData.publicUrl + '/wx/getAppletOpenId', method: "GET", data: { code: res.code }, success: res => { if (res.data.status == 200) { wx.setStorageSync('openId', res.data.data.openid) return res.data.data.openid; } } }); } else { console.log('获取用户登录态失败!' + res.errMsg); } } }) }) } }; module.exports = { openidStatus }