api.js 6.3 KB

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