request.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. //主持人-我的课程
  14. getPhone: "/api/wxUser/getPhone",
  15. updateWxUser: '/api/wxUser/updateWxUser',
  16. // 新微信登录
  17. wxLogin: "/api/show/wxLogin/{code}",
  18. //免费限时
  19. freeBuy: "/api/payment/freeBuy",
  20. }
  21. wxRequest.defaults.baseURL = 'https://sit-daikan.4dage.com';
  22. wxRequest.defaults.headers['Token'] = wx.getStorageSync('token') || "";
  23. wxRequest.defaults.headers.post['Content-Type'] = 'application/json';
  24. export async function getVRCourseList(params) {
  25. return await (await wxRequest.post(urls.getVRCourseList, params)).data;
  26. }
  27. export async function getVRCourseDetail(id) {
  28. return await (await wxRequest.get(urls.getVRCourseDetail + id)).data;
  29. }
  30. export async function getWxUserInfo(key) {
  31. // const url = urls.getWxUserInfo.replace('{sessionKey}', encodeURIComponent(key))
  32. console.log('getWxUserInfo-key', key)
  33. return await (await wxRequest.get(urls.getWxUserInfo, {
  34. params: {
  35. sessionKey: key
  36. }
  37. })).data;
  38. }
  39. export async function getMyPaidlesson(wxUserId) {
  40. return await (await wxRequest.get(urls.getMylesson + wxUserId)).data;
  41. }
  42. export async function getMyHostlesson(wxUserId) {
  43. return await (await wxRequest.get(urls.getMyHostlesson + wxUserId)).data;
  44. }
  45. export async function decrptPhone(code) {
  46. console.log('decrptPhone-params', code, )
  47. const url = `${urls.getPhone}/${code}`
  48. console.log('decrptPhone-url', url)
  49. return await (await wxRequest.get(url)).data;
  50. }
  51. export async function updateUserInfo(info) {
  52. return await (await wxRequest.post(urls.updateWxUser, info)).data;
  53. }
  54. export const updateAvatar = async (avatarUrl) => {
  55. const WX_UPLOAD_URL = ''
  56. let url = ''
  57. wx.uploadFile({
  58. filePath: avatarUrl,
  59. name: 'file',
  60. url: WX_UPLOAD_URL,
  61. success: async (res) => {
  62. const data = JSON.parse(res.data)
  63. console.log('data', data)
  64. url = data.data
  65. }
  66. })
  67. await sleep(1200)
  68. return Promise.resolve(url)
  69. }
  70. export async function wxUserLogin(code) {
  71. const url = urls.wxLogin.replace('{code}', code);
  72. return await (await wxRequest.get(url)).data;
  73. }
  74. export async function freeBuy(params) {
  75. // const url = urls.wxLogin.replace('{code}', code);
  76. return await (await wxRequest.post(urls.freeBuy, params)).data;
  77. }