config.js 1.3 KB

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