request.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/wxUser/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. const sessionKey = wx.getStorageSync('sessionKey')
  53. if (sessionKey) {
  54. // const url = urls.updateWxUser.replace('{sessionKey}', sessionKey)
  55. return await (await wxRequest.post(url + `?sessionKey=${sessionKey}`, info)).data;
  56. }
  57. }
  58. export const updateAvatar = async (avatarUrl) => {
  59. const WX_UPLOAD_URL = ''
  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. }