小程序判断手机型号小程序判断iphonx

阅读更多
#app.js

checkIsIPhoneX: function () {
    const self = this
    wx.getSystemInfo({
      success: function (res) {
        // 根据 model 进行判断
        if (res.model.search('iPhone X') != -1) {
          self.globalData.isIPX = true
        }
        // 或者根据 screenHeight 进行判断
        // if (res.screenHeight == 812) {
        //   self.globalData.isIPX = true
        // }
      }
    }),
 getSessionKey: function () {
    return new Promise((resolve, reject) => {
      let webSiteId = this.globalData.webSiteId
      // 检查Session是否过期
      wx.checkSession({
        //session_key 未过期,并且在本生命周期一直有效
        success: () => {
          let openid = store.get('openid')
          if (openid) {
            resolve(openid)
          } else {
            // 重新登录
            wx.login({
              success: (res) => {
                if (res.code) {
                  //发起网络请求
                  let options = {
                    path: 'https://www.cloudlakenet.com',
                    method: 'POST',
                    body: {
                      'code': `${res.code}`,
                      'webSiteId': `${webSiteId}`
                    }
                  }
                  oData.submit(options).then(res => {
                    if (res.value) {
                      let openid = res.value
                      store.set('openid', openid)
                      resolve(openid)
                    } else {
                      resolve(false)
                    }
                  })
                } else {
                  resolve(false)
                  console.log('登录失败!' + res.errMsg)
                }
              }
            })
          }
        },
        fail: () => {
          // session_key 已经失效,需要重新执行登录流程
          //重新登录
          wx.login({
            success: (res) => {
              if (res.code) {
                //发起网络请求
                let options = {
                  path: 'getWxMiniprogramUserId',
                  method: 'POST',
                  body: {
                    'code': `${res.code}`,
                    'webSiteId': `${webSiteId}`
                  }
                }
                oData.submit(options).then(res => {
                  if (res.data.value) {
                    let openid = res.data.value
                    store.set('openid', openid)
                    resolve(openid)
                  } else {
                    resolve(false)
                  }
                })
              } else {
                resolve(false)
                console.log('登录失败!' + res.errMsg)
              }
            }
          })
        }
      })
    })

  },

你可能感兴趣的:(小程序判断手机型号小程序判断iphonx)