config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. let api = "https://passport.lrlz.com/mobile/index.php";
  2. // let api = "http://a.lrlz.com/mobile/index.php";
  3. // let api = "http://121.43.114.153/mobile/index.php"
  4. // let api = "http://192.168.0.131/mobile/index.php";
  5. // let api = "http://192.168.0.200/mobile/index.php";
  6. function getReq(data, callback, method) {
  7. let options = {
  8. // client_type: 'ios'
  9. client_type: 'mini'
  10. }
  11. data = Object.assign({}, options, data);
  12. let session_id = wx.getStorageSync('session_id');
  13. let header = {
  14. 'content-type': 'application/json', // 默认值
  15. 'Cookie': 'MPHPSESSID=' + session_id
  16. }
  17. if(method == 'POST') {
  18. header = {
  19. 'content-type': 'application/x-www-form-urlencoded', // 数据转换成 query string
  20. 'Cookie': 'MPHPSESSID=' + session_id
  21. }
  22. }
  23. return wx.request({
  24. url: api,
  25. data,
  26. method: method || 'GET',
  27. header,
  28. success(res) {
  29. callback(res.data)
  30. },
  31. fail() {
  32. wx.showModal({
  33. confirmText: '重试',
  34. content: '网络错误',
  35. success: function (res) {
  36. if (res.confirm) {
  37. wx.reLaunch({
  38. url: "/pages/index/index"
  39. })
  40. } else if (res.cancel) {
  41. console.log('用户点击取消')
  42. }
  43. }
  44. })
  45. }
  46. })
  47. }
  48. module.exports = {
  49. getReq,
  50. host: api
  51. }