config.js 1.3 KB

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