config.js 1.1 KB

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