diff --git a/src/renderer/utils/musicSdk/tx/comment.js b/src/renderer/utils/musicSdk/tx/comment.js index 10adf5c2..af4692c9 100644 --- a/src/renderer/utils/musicSdk/tx/comment.js +++ b/src/renderer/utils/musicSdk/tx/comment.js @@ -128,36 +128,43 @@ export default { if (this._requestObj2) this._requestObj2.cancelHttp() const songId = await this.getSongId(mInfo) - - const _requestObj2 = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', { - method: 'POST', + // const _requestObj2 = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', { + // method: 'POST', + // headers: { + // 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)', + // }, + // form: { + // uin: '0', + // format: 'json', + // cid: '205360772', + // reqtype: '2', + // biztype: '1', + // topid: songId, + // cmd: '9', + // needmusiccrit: '1', + // pagenum: page - 1, + // pagesize: limit, + // }, + // }) + const _requestObj2 = httpFetch(`https://u.y.qq.com/cgi-bin/musicu.fcg?data={"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":0,"g_tk_new_20200303":2101046530,"g_tk":2101046530},"req_1":{"module":"music.globalComment.CommentRead","method":"GetHotCommentList","param":{"BizType":1,"BizId":"${songId}","LastCommentSeqNo":"","PageSize":${limit},"PageNum":${page - 1},"HotType":1,"WithAirborne":0,"PicEnable":1}}}`, { + method: 'GET', headers: { - 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)', - }, - form: { - uin: '0', - format: 'json', - cid: '205360772', - reqtype: '2', - biztype: '1', - topid: songId, - cmd: '9', - needmusiccrit: '1', - pagenum: page - 1, - pagesize: limit, + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.0.0', + origin: 'https://y.qq.com', + referer: 'https://y.qq.com/', }, }) const { body, statusCode } = await _requestObj2.promise - if (statusCode != 200 || body.code !== 0) throw new Error('获取热门评论失败') - // console.log(body, statusCode) - const comment = body.comment + // console.log('body', body) + if (statusCode != 200 || body.code !== 0 || body.req_1.code !== 0) throw new Error('获取热门评论失败') + const comment = body.req_1.data.CommentList return { source: 'tx', - comments: this.filterComment(comment.commentlist), - total: comment.commenttotal, + comments: this.filterHotComment(comment.Comments), + total: comment.Total, page, limit, - maxPage: Math.ceil(comment.commenttotal / limit) || 1, + maxPage: Math.ceil(comment.Total / limit) || 1, } }, replaceEmoji(msg) { @@ -211,4 +218,48 @@ export default { } }) }, + filterHotComment(rawList) { + return rawList.map(item => { + // let time = String(item.PubTime).length < 10 ? null : parseInt(item.PubTime + '000') + // let timeStr = time ? dateFormat2(time) : null + // if (item.SubComments) { + // let firstItem = item.SubComments[0] + // firstItem.avatarurl = item.avatarurl + // firstItem.praisenum = item.praisenum + // item.avatarurl = null + // item.praisenum = null + // item.SubComments.reverse() + // } + return { + id: `${item.SeqNo}_${item.EncryptUin}`, + rootId: item.SeqNo, + text: item.Content ? this.replaceEmoji(item.Content).replace(/\\n/g, '\n').split('\n') : [], + time: this.formatTime(item.PubTime), + timeStr: item.PubTime ? dateFormat2(this.formatTime(item.PubTime)) : null, + userName: item.Nick ? item.Nick.substring(1) : '', + images: item.Pic ? [item.Pic] : [], + avatar: item.Avatar, + userId: item.EncryptUin, + likedCount: item.PraiseNum, + reply: item.SubComments + ? item.SubComments.map(c => { + // let index = c.subcommentid.lastIndexOf('_') + return { + id: `sub_${item.SeqNo}_${c.EncryptUin}`, + text: this.replaceEmoji(c.Content).replace(/\\n/g, '\n').split('\n'), + time: this.formatTime(c.PubTime), + timeStr: item.PubTime ? dateFormat2(this.formatTime(c.PubTime)) : null, + userName: c.Nick.substring(1), + avatar: c.Avatar, + userId: c.EncryptUin, + likedCount: c.PraiseNum, + } + }) + : [], + } + }) + }, + formatTime(time) { + return String(time).length < 10 ? null : parseInt(time + '000') + }, }