api.js 6.7 KB

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