暫無描述

util.js 1.3KB

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