request.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import wxRequest from 'wechat-request';
  2. const urls = {
  3. //VR课堂
  4. getVRCourseList: '/api/show/lesson/pageList',
  5. //VR课堂详情
  6. getVRCourseDetail: '/api/show/lesson/detail/',
  7. // 获取微信用户详情
  8. getWxUserInfo: "/api/wxUser/getWxUserInfo/",
  9. //微信用户-我的购买
  10. getMylesson: "/api/show/lesson/getList/",
  11. //主持人-我的课程
  12. getMyHostlesson: "/api/show/compere/getLesson/",
  13. getPhone: "/api/wxUser/getPhone",
  14. updateWxUser: "/api/wxUser/updateWxUser/{sessionKey}",
  15. }
  16. wxRequest.defaults.baseURL = 'https://sit-daikan.4dage.com';
  17. wxRequest.defaults.headers['Token'] = wx.getStorageSync('token') || "";
  18. wxRequest.defaults.headers.post['Content-Type'] = 'application/json';
  19. export async function getVRCourseList(params) {
  20. return await (await wxRequest.post(urls.getVRCourseList, params)).data;
  21. }
  22. export async function getVRCourseDetail(id) {
  23. return await (await wxRequest.get(urls.getVRCourseDetail + id)).data;
  24. }
  25. export async function getWxUserInfo(key) {
  26. return await (await wxRequest.get(urls.getWxUserInfo + key)).data;
  27. }
  28. export async function getMyPaidlesson(wxUserId) {
  29. return await (await wxRequest.get(urls.getMylesson + wxUserId)).data;
  30. }
  31. export async function getMyHostlesson(wxUserId) {
  32. return await (await wxRequest.get(urls.getMyHostlesson + wxUserId)).data;
  33. }
  34. export async function decrptPhone(code, wxUserId) {
  35. console.log('decrptPhone-params', code, wxUserId)
  36. const url = `${urls.getPhone}/${code}/${wxUserId}`
  37. console.log('decrptPhone-url', url)
  38. return await (await wxRequest.get(url)).data;
  39. }
  40. export async function updateUserInfo(info) {
  41. const sessionKey = wx.getStorageSync('sessionKey')
  42. if (sessionKey) {
  43. const url = urls.updateWxUser.replace('{sessionKey}', sessionKey)
  44. return await (await wxRequest.post(url, info)).data;
  45. }
  46. }
  47. export const updateAvatar = async (avatarUrl) => {
  48. const WX_UPLOAD_URL = ''
  49. let url = ''
  50. wx.uploadFile({
  51. filePath: avatarUrl,
  52. name: 'file',
  53. url: WX_UPLOAD_URL,
  54. success: async (res) => {
  55. const data = JSON.parse(res.data)
  56. console.log('data', data)
  57. url = data.data
  58. }
  59. })
  60. await sleep(1200)
  61. return Promise.resolve(url)
  62. }