大数据平台的小程序版本

util.js 1.0KB

123456789101112131415161718192021222324252627282930313233
  1. var rootDocment = 'https://ad.wenxingshuju.com';//域名
  2. function req(url, method, data, cb, fail_cb, selfHeader) {
  3. var dataes = {'admin_id':wx.getStorageSync('admin_id'),
  4. 'ttl':wx.getStorageSync('ttl'),
  5. 'sign':wx.getStorageSync('sign')
  6. }
  7. var header = {
  8. 'sessionKey':wx.getStorageSync('session_key')?wx.getStorageSync('session_key'):false
  9. }
  10. const app = getApp()
  11. wx.request({
  12. url: rootDocment + url,
  13. data: data ? Object.assign(data, dataes) : dataes,
  14. method: method,
  15. header: selfHeader ? Object.assign(selfHeader,header) : header,
  16. success: function (res) {
  17. if((res.data.errno == '4002' || res.data.errno == '4001')&&url.indexOf('verified')==-1&&url.indexOf('loginByUnionId')==-1){
  18. if(wx.getStorageSync('isLogin')){
  19. wx.clearStorage()
  20. app.login({})
  21. }
  22. }else{
  23. return typeof cb == "function" && cb(res.data)
  24. }
  25. },
  26. fail: function (err) {
  27. return typeof fail_cb == "function" && fail_cb(err)
  28. }
  29. })
  30. }
  31. module.exports = {
  32. req: req
  33. }