apiConfig.js 776 B

1234567891011121314151617181920212223242526272829303132333435
  1. let v = wx.getAccountInfoSync();
  2. let { envVersion } = v.miniProgram;
  3. // envVersion = "release";
  4. let apiUrl = `${
  5. envVersion == "release"
  6. ? "https://interface.huihenduo.cc/hhd-ship"
  7. : "https://interface.huihenduo.cc/hhd-ship-new"
  8. }`;
  9. function api(url, data, method) {
  10. return new Promise((resolve, reject) => {
  11. wx.request({
  12. url: `${apiUrl}${url}`,
  13. method,
  14. data,
  15. dataType: "json",
  16. header: {
  17. "content-type": "application/json",
  18. accessToken: wx.getStorageSync("accessToken"),
  19. },
  20. success: (res) => {
  21. if (res.data.status === "11012") {
  22. wx.removeStorageSync("accessToken");
  23. }
  24. resolve(res);
  25. },
  26. fail: reject,
  27. });
  28. });
  29. }
  30. module.exports = {
  31. apiUrl,
  32. api,
  33. };