request.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import wxRequest from 'wechat-request';
  2. const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
  3. const urls = {
  4. //VR课堂
  5. getVRCourseList: '/api/show/lesson/pageList',
  6. //VR课堂详情
  7. getVRCourseDetail: '/api/show/lesson/detail/',
  8. // 获取微信用户详情
  9. getWxUserInfo: "/api/wxUser/getWxUserInfo",
  10. //微信用户-我的购买
  11. getMylesson: "/api/show/lesson/getList/",
  12. //主持人-我的课程
  13. getMyHostlesson: "/api/show/compere/getLesson/",
  14. //主持人-我的课程
  15. getPhone: "/api/wxUser/getPhone",
  16. updateWxUser: '/api/wxUser/updateWxUser',
  17. // 新微信登录
  18. wxLogin: "/api/show/wxLogin/{code}",
  19. //免费限时
  20. freeBuy: "/api/payment/freeBuy",
  21. // 上传
  22. upload: '/api/wxUser/upload'
  23. }
  24. wxRequest.defaults.baseURL = 'https://sit-daikan.4dage.com';
  25. wxRequest.defaults.headers['Token'] = wx.getStorageSync('token') || "";
  26. wxRequest.defaults.headers.post['Content-Type'] = 'application/json';
  27. export async function getVRCourseList(params) {
  28. return await (await wxRequest.post(urls.getVRCourseList, params)).data;
  29. }
  30. export async function getVRCourseDetail(id) {
  31. return await (await wxRequest.get(urls.getVRCourseDetail + id)).data;
  32. }
  33. export async function getWxUserInfo(key) {
  34. // const url = urls.getWxUserInfo.replace('{sessionKey}', encodeURIComponent(key))
  35. console.log('getWxUserInfo-key', key)
  36. return await (await wxRequest.get(urls.getWxUserInfo, {
  37. params: {
  38. sessionKey: key
  39. }
  40. })).data;
  41. }
  42. export async function getMyPaidlesson(wxUserId) {
  43. return await (await wxRequest.get(urls.getMylesson + wxUserId)).data;
  44. }
  45. export async function getMyHostlesson(wxUserId) {
  46. return await (await wxRequest.get(urls.getMyHostlesson + wxUserId)).data;
  47. }
  48. export async function decrptPhone(code) {
  49. console.log('decrptPhone-params', code, )
  50. const url = `${urls.getPhone}/${code}`
  51. console.log('decrptPhone-url', url)
  52. return await (await wxRequest.get(url)).data;
  53. }
  54. export async function updateUserInfo(info) {
  55. return await (await wxRequest.post(urls.updateWxUser, info)).data;
  56. }
  57. export const updateAvatar = async (avatarUrl) => {
  58. // const WX_UPLOAD_URL = wxRequest.defaults.baseURL + urls.upload
  59. const WX_UPLOAD_URL = 'https://v4-test.4dkankan.com/takelook/upload/file'
  60. let url = ''
  61. wx.uploadFile({
  62. filePath: avatarUrl,
  63. name: 'file',
  64. url: WX_UPLOAD_URL,
  65. success: async (res) => {
  66. const data = JSON.parse(res.data)
  67. console.log('data', data)
  68. url = data.data
  69. }
  70. })
  71. await sleep(1200)
  72. return Promise.resolve(url)
  73. }
  74. export async function wxUserLogin(code) {
  75. const url = urls.wxLogin.replace('{code}', code);
  76. return await (await wxRequest.get(url)).data;
  77. }
  78. export async function freeBuy(params) {
  79. // const url = urls.wxLogin.replace('{code}', code);
  80. return await (await wxRequest.post(urls.freeBuy, params)).data;
  81. }