config.js 1.1 KB

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