api.js 6.5 KB

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