api.js 4.9 KB

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