1 const domainUrl = getApp().data.domainUrl; 2 Page({ 3 data: {}, 4 onLoad: function (options) { 5 wx.getSystemInfo({ 6 success(res) { 7 if (res.environment == 'wxwork') { 8 //驗證session是否過期 9 wx.qy.checkSession({ 10 success: function () { 11 //session_key 未過期,並且在本生命周期一直有效 12 }, 13 fail: function () { 14 // session_key 已經失效,需要重新執行登錄流程 15 wx.qy.login({ 16 success: function (res) { 17 if (res.code) { 18 //發起網絡請求 19 wx.request({ 20 url: domainUrl + 'weixinapplet/wx_qy_loginxxxxxxx', 21 data: { 22 code: res.code 23 }, 24 success: function (result) {}, 25 fail: function () {} 26 }) 27 } 28 } 29 }); 30 } 31 }) 32 33 //打開用戶個人信息 34 wx.qy.openUserProfile({ 35 type: 2, //1表示該userid是企業成員,2表示該userid是外部聯系人 36 userid: 'wmpBA5BxxxxxxxxxxxxxxxxxxJMA',//可以是企業成員,也可以是外部聯系人 37 success: function (res) {}, 38 fail: function (res) { } 39 }); 40 } else { 41 wx.showLoading({ 42 title: '個人微信端........', 43 mask: true 44 }) 45 // wx.hideLoading() 46 } 47 } 48 }) 49 50 }, 51 52 53 54 })