request.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //设置域名
  2. // const dev_baseUrl_wxrlxf = 'https://hanghuikeji.mynatapp.cc/yx-fyzd';//测试
  3. const dev_baseUrl_wxrlxf = 'http://192.168.77.158:9100/yx-fyzd';//测试
  4. // const dev_baseUrl_wxrlxf = 'https://test.hz-hanghui.com:18890/yx-fyzd';//本地
  5. const pro_baseUrl_wxrlxf = 'https://tx.hz-hanghui.com:8088/yx-fyzd';//正式
  6. //是否是正式环境
  7. const wx_rlxf = true
  8. const baseUrl = wx_rlxf ? pro_baseUrl_wxrlxf : dev_baseUrl_wxrlxf;
  9. //https请求
  10. const request_wxrlxf = e => {
  11. return new Promise(function(resolve,reject){
  12. wx.request({
  13. url: wx_rlxf?(pro_baseUrl_wxrlxf + e.url):(dev_baseUrl_wxrlxf + e.url),
  14. data: e.data,
  15. method: e.method,
  16. header: {'content-type': e.type},
  17. success: res => {
  18. if(res.statusCode == 200 || res.code == 200){
  19. resolve(res.data)
  20. }else{
  21. reject(res.data)
  22. };
  23. },
  24. fail: error => {
  25. reject(error.errMsg)
  26. }
  27. })
  28. })
  29. }
  30. //是否是正式环境
  31. const env = true
  32. //设置域名
  33. const dev_baseUrl = 'http://192.168.18.117:8088';//测试
  34. const pro_baseUrl = 'https://renhe.hz-hanghui.com';//正式
  35. //https请求
  36. const request = e => {
  37. return new Promise(function(resolve,reject){
  38. wx.request({
  39. url: env?(pro_baseUrl + e.url):(dev_baseUrl + e.url),
  40. data: e.data,
  41. method: e.method,
  42. header: {'content-type': e.type},
  43. success: res => {
  44. if(res.statusCode == 200){
  45. resolve(res.data)
  46. }else{
  47. reject(res.data)
  48. };
  49. },
  50. fail: error => {
  51. reject(error.errMsg)
  52. }
  53. })
  54. })
  55. }
  56. module.exports = {
  57. wx_rlxf: wx_rlxf,
  58. baseUrl,
  59. dev_baseUrl_wxrlxf: dev_baseUrl_wxrlxf,
  60. pro_baseUrl_wxrlxf: pro_baseUrl_wxrlxf,
  61. request_wxrlxf: request_wxrlxf,
  62. env: env,
  63. dev_baseUrl: dev_baseUrl,
  64. pro_baseUrl: pro_baseUrl,
  65. request: request,
  66. }