api.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // 接口文档:https://hyperion-novel-qa-app.mokamrp.com/swagger-ui/#/
  2. import { requestAll, requestLogin, post, postWithCommonParams, uploadTrackLog } from '../utils/request'
  3. export const userLogin = (data) => requestLogin(data)
  4. // 获取token
  5. const getToken = () => {
  6. return wx.getStorageSync('accessToken') || ''
  7. }
  8. // 添加token到header
  9. const addTokenToHeader = () => {
  10. return {
  11. token: getToken()
  12. }
  13. }
  14. export const getBannerList = (channel) => {
  15. return requestAll('/novel/banner', {channel}, 'GET', addTokenToHeader())
  16. }
  17. export const getChapterList = (channel) => {
  18. return requestAll('/novel/chapter/list', {channel}, 'GET', addTokenToHeader())
  19. }
  20. // /novel/cardNovels
  21. export const getCardNovels = (channel) => {
  22. return requestAll('/novel/cardNovels', {channel}, 'GET', addTokenToHeader())
  23. }
  24. // /novel/cardNovelsMore
  25. export const getCardNovelsMore = (id) => {
  26. if (!id) {
  27. return Promise.reject(new Error('缺少必要参数: id'));
  28. }
  29. return requestAll('/novel/cardNovelsMore', {id}, 'GET', addTokenToHeader())
  30. }
  31. // /category/list
  32. export const getCategoryList = (category) => {
  33. if (!category) {
  34. return Promise.reject(new Error('缺少必要参数: category'));
  35. }
  36. return requestAll('/category/list', {category}, 'GET', addTokenToHeader())
  37. }
  38. // /novel/detail
  39. export const getNovelDetail = (id) => {
  40. if (!id) {
  41. return Promise.reject(new Error('缺少必要参数: id'));
  42. }
  43. return requestAll('/novel/detail', {id}, 'GET', addTokenToHeader())
  44. }
  45. // /novel/search
  46. export const getNovelSearch = ({
  47. keyword,
  48. page = 1,
  49. size = 10,
  50. category
  51. }) => {
  52. // 创建基本参数对象
  53. const params = {keyword, page, size};
  54. // 如果category有值,才添加到参数中
  55. if (category) {
  56. params.category = category;
  57. }
  58. return requestAll('/novel/search', params, 'GET', addTokenToHeader());
  59. }
  60. // /user/bookshelf 获取书架列表
  61. export const getBookshelfList = () => {
  62. return requestAll('/user/bookshelf', {}, 'GET', addTokenToHeader())
  63. }
  64. // /user/bookshelf 添加书架
  65. export const addBookshelf = (data) => {
  66. return requestAll('/user/bookshelf', data, 'POST', addTokenToHeader())
  67. }
  68. // /user/bookshelf 移除用户书架
  69. export const removeBookshelf = (data) => {
  70. return requestAll('/user/bookshelf', data, 'DELETE', addTokenToHeader())
  71. }
  72. // /user/chapter/unlock-status 获取章节解锁状态
  73. export const getChapterUnlockStatus = (data) => {
  74. return requestAll('/user/chapter/unlock-status-val', data, 'GET', addTokenToHeader())
  75. }
  76. // /user/browsing-history 新增用户阅读历史
  77. export const addBrowsingHistory = (data) => {
  78. return requestAll('/user/browsing-history', data, 'POST', addTokenToHeader())
  79. }
  80. // /user/chapter/unlock 解锁章节
  81. export const unlockChapter = (data) => {
  82. return requestAll('/user/chapter/unlock', data, 'POST', addTokenToHeader())
  83. }
  84. // 获取阅读记录
  85. export const getBrowsingHistory = () => {
  86. return requestAll('/user/browsing-history', {}, 'GET', addTokenToHeader())
  87. }
  88. // 获取短剧列表
  89. export function getVideoList(params = {}) {
  90. const {page = 1, size = 10, tag_id = 2245, filter_id = "", next_id = "",gh_id = ""} = params;
  91. const requestData = {
  92. tag_id: tag_id,
  93. filter_id: filter_id,
  94. next_id: next_id,
  95. count: size,
  96. uuid: getApp().globalData.uuid, // 固定值,实际应用中可能需要动态生成
  97. gh_id: gh_id // 固定值
  98. };
  99. return postWithCommonParams("https://applet.xiaoduer.cn/cashvideoapi/cashvideo/getvideolist", requestData)
  100. .then(data => {
  101. return data;
  102. // 处理返回数据的格式转换,确保与页面期望的数据结构一致
  103. if (data) {
  104. return data.map(video => ({
  105. id: video.id,
  106. title: video.title,
  107. cover: video.cover_image,
  108. playCount: video.views || '0'
  109. }));
  110. }
  111. return [];
  112. });
  113. }
  114. // 获取视频详情
  115. export function getVideoDetail(params = {}) {
  116. if (!params.id) {
  117. return Promise.reject(new Error('缺少必要参数: id'));
  118. }
  119. return postWithCommonParams('https://applet.xiaoduer.cn/cashvideoapi/cashvideo/getvideoinfo', params);
  120. }
  121. // 获取真实视频播放地址
  122. export function getRealVideoUrl(id, tagId) {
  123. if (!id || !tagId) {
  124. return Promise.reject(new Error('缺少必要参数: id 或 tagId'));
  125. }
  126. const url = `https://applet.xiaoduer.cn/coral/cashvideo/getOasVideoUrl?id=${id}&tagId=${tagId}`;
  127. return postWithCommonParams(url, {}, 'GET');
  128. }
  129. // 获取相关视频列表
  130. export function getRelatedVideos(params = {}) {
  131. const {tag_id = 2250, count = 10, filter_id = "", gh_id = ""} = params;
  132. const requestData = {
  133. tag_id,
  134. count,
  135. filter_id,
  136. uuid: getApp().globalData.uuid,
  137. gh_id: gh_id
  138. };
  139. return post("https://applet.xiaoduer.cn/cashvideoapi/cashvideo/getrandvideolistpro", requestData);
  140. }
  141. /**
  142. * 获取 uuid
  143. */
  144. export function getUuid(body) {
  145. return postWithCommonParams('https://applet.xiaoduer.cn/api/user/getuuid', body)
  146. }
  147. // https://applet.xiaoduer.cn/coral/template/config
  148. export function getTemplateConfig(body) {
  149. return postWithCommonParams('https://applet.xiaoduer.cn/coral/template/config', body)
  150. }
  151. // 导出postWithCommonParams
  152. export { postWithCommonParams };
  153. /**
  154. * 打点
  155. */
  156. export const recordLog = (body) => uploadTrackLog('/track', body)