api.js 6.7 KB

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