/** * 早安电台 — 后端 API 接口封装 * 统一调用 request.js,对外暴露业务方法 */ const { get, post } = require('./request') // ======================== 登录相关 ======================== /** 小程序登录 (wx.login code → token + user) */ function miniLogin(code) { return get('/auth/miniLogin', { code }) } /** 获取位置信息 */ function getLocation(longitude, latitude) { return get('/auth/getLocation', { longitude, latitude }) } /** 获取天气 */ function getWeather(adcode) { return get('/auth/getWeather', { adcode }) } /** 获取手机号 */ function getPhone(code, openId) { return get('/auth/getPhone', { code, openId }) } // ======================== 分类管理 ======================== /** 获取分类列表(全量) */ function getCategoryList() { return get('/radio/category/list') } /** 获取分类树 */ function getCategoryTree() { return get('/radio/category/tree') } // ======================== 频道管理 ======================== /** 获取频道列表(分页) */ function getChannelList(params) { return post('/radio/channel/list', { current: params.current || 1, pageSize: params.pageSize || 50, categoryId: params.categoryId || '', status: 1 // 仅上架 }) } /** 获取免费频道列表 */ function getFreeChannelList(params) { return post('/radio/channel/freeList', { current: (params && params.current) || 1, pageSize: (params && params.pageSize) || 20, keyword: (params && params.keyword) || '' }) } /** 获取频道详情 */ function getChannelDetail(id) { return get('/radio/channel/detail', { id }) } // ======================== 节目管理 ======================== /** 获取节目列表(分页,需传 channelId) */ function getProgramList(params) { return post('/radio/program/list', { channelId: params.channelId, current: params.current || 1, pageSize: params.pageSize || 50, status: 1 }) } /** 获取节目详情 */ function getProgramDetail(id) { return get('/radio/program/detail', { id }) } // ======================== 订阅管理 ======================== /** 获取我的订阅列表 */ function getSubscriptionList(params) { return post('/radio/subscription/list', { current: (params && params.current) || 1, pageSize: (params && params.pageSize) || 50 }) } /** 检查是否可以订阅 */ function canSubscribe(channelId) { return post('/radio/subscription/can-subscribe', { channelId }) } /** 订阅频道 */ function subscribe(channelId) { return post('/radio/subscription/subscribe', { channelId }) } /** 退订频道 */ function unsubscribe(channelId) { return post('/radio/subscription/unsubscribe', { channelId }) } // ======================== 收听历史 ======================== /** 添加收听历史 */ function addHistory(params) { return post('/history/add', { programId: params.programId, progress: params.progress || 0, duration: params.duration || 0 }) } /** 获取收听历史列表 */ function getHistoryList(params) { return post('/history/list', { current: (params && params.current) || 1, pageSize: (params && params.pageSize) || 20 }) } /** 删除单条收听历史 */ function deleteHistory(programId) { return post('/history/delete', { programId }) } /** 清空全部收听历史 */ function deleteAllHistory() { return get('/history/deleteAll') } // ======================== 收藏 ======================== /** 添加收藏 */ function addFavorite(programId) { return post('/favorite/add', { programId }) } /** 取消收藏 */ function removeFavorite(programId) { return post('/favorite/remove', { programId }) } /** 清空全部收藏 */ function removeAllFavorites() { return get('/favorite/removeAll') } /** 获取收藏列表 */ function getFavoriteList(params) { return post('/favorite/list', { current: (params && params.current) || 1, pageSize: (params && params.pageSize) || 20 }) } // ======================== 点赞 / 评论 ======================== /** 切换点赞 */ function toggleLike(programId) { return post('/like/toggle', { programId }) } /** 添加评论 */ function addComment(programId, content) { return post('/comment/add', { programId, content }) } /** 删除评论 */ function deleteComment(id) { return post('/comment/delete', { id }) } /** 获取评论列表 */ function getCommentList(programId, params) { return post('/comment/list', { programId, current: (params && params.current) || 1, pageSize: (params && params.pageSize) || 20 }) } /** 获取当前登录用户 */ /** 获取 VIP 配置(价格等) */ function getVipConfig() { return post('/vip/config/detail', {}) } /** 发起 VIP 开通预支付 */ function initiateVipPayment() { return post('/vip/vip', {}) } function getUserInfo() { return get('/user/info') } /** 付费订阅频道(传入方案 monthly/quarterly/annual 和价格) */ function subscribeChannel(params) { return post('/radio/subscription/pay', params) } /** * 主动查询微信支付状态 * @param {string} outTradeNo 商户订单号(上游返回) * @returns {Promise} true = 支付成功 */ function queryPayStatus(outTradeNo) { return get('/pay/query', { outTradeNo }) .then(function (res) { // 后端返回 bool 或 { data: bool } if (typeof res === 'boolean') return res if (typeof res.data === 'boolean') return res.data return res.code === 200 && !!res.data }) } /** * 频道解锁(唇起微信支付骄支付单) * @param {string} channelId * @param {string} type '1'=包月 '2'=包季 '3'=包年 */ function unlockChannel(channelId, type) { return post('/radio/subscription/unlock', { channelId, type }) } /** 获取点赞列表 */ function getLikeList(params) { return post('/like/list', { current: (params && params.current) || 1, pageSize: (params && params.pageSize) || 30 }) } /** 清空全部点赞 */ function removeAllLikes() { return get('/like/removeAll') } module.exports = { miniLogin, getLocation, getWeather, getPhone, getCategoryList, getCategoryTree, getChannelList, getFreeChannelList, getChannelDetail, getProgramList, getProgramDetail, getSubscriptionList, canSubscribe, subscribe, unsubscribe, addHistory, getHistoryList, deleteHistory, deleteAllHistory, addFavorite, removeFavorite, removeAllFavorites, getFavoriteList, toggleLike, getLikeList, removeAllLikes, addComment, deleteComment, getCommentList, getVipConfig, initiateVipPayment, getUserInfo, subscribeChannel, unlockChannel, queryPayStatus }