This commit is contained in:
student_2333
2024-04-30 13:40:15 +08:00
parent 78c6050d61
commit 05091798f4
4 changed files with 64 additions and 65 deletions

View File

@@ -23,14 +23,14 @@ export class MusicSign {
this.url = url
}
async sign(postData: MusicSignPostData): Promise<any> {
async sign(postData: MusicSignPostData): Promise<string> {
const resp = await fetch(this.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(postData),
})
if (!resp.ok) throw new Error(resp.statusText)
const data = await resp.json()
const data = await resp.text()
log('音乐消息生成成功', data)
return data
}

View File

@@ -310,7 +310,7 @@ export class SendMsgElementConstructor {
}
}
static ark(data: any): SendArkElement {
static ark(data: string): SendArkElement {
return {
elementType: ElementType.ARK,
elementId: '',

View File

@@ -15,6 +15,7 @@ import {
OB11MessageCustomMusic,
OB11MessageData,
OB11MessageDataType,
OB11MessageJson,
OB11MessageMixType,
OB11MessageMusic,
OB11MessageNode,
@@ -383,34 +384,32 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
} catch (e) {
throw '发送转发消息失败 ' + e.toString()
}
} else {
if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
const music = messages[0] as OB11MessageMusic
if (music) {
const { musicSignUrl } = getConfigUtil().getConfig()
if (!musicSignUrl) {
throw '音乐签名地址未配置'
}
const { type } = music.data
if (!['qq', '163', 'custom'].includes(type)) {
throw `不支持的音乐类型 ${type}`
}
const postData: MusicSignPostData = { ...music.data }
if (type === 'custom' && music.data.content) {
;(postData as CustomMusicSignPostData).singer = music.data.content
delete (postData as OB11MessageCustomMusic['data']).content
}
let jsonContent: string
try {
jsonContent = await new MusicSign(musicSignUrl).sign(postData)
} catch (e) {
throw `签名音乐消息失败:${e}`
}
messages[0] = {
type: OB11MessageDataType.json,
data: { data: jsonContent },
}
} else if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
const music = messages[0] as OB11MessageMusic
if (music) {
const { musicSignUrl } = getConfigUtil().getConfig()
if (!musicSignUrl) {
throw '音乐签名地址未配置'
}
const { type } = music.data
if (!['qq', '163', 'custom'].includes(type)) {
throw `不支持的音乐类型 ${type}`
}
const postData: MusicSignPostData = { ...music.data }
if (type === 'custom' && music.data.content) {
;(postData as CustomMusicSignPostData).singer = music.data.content
delete (postData as OB11MessageCustomMusic['data']).content
}
let jsonContent: string
try {
jsonContent = await new MusicSign(musicSignUrl).sign(postData)
} catch (e) {
throw `签名音乐消息失败:${e}`
}
messages[0] = {
type: OB11MessageDataType.json,
data: { data: jsonContent },
} as OB11MessageJson
}
}
// log("send msg:", peer, sendElements)
@@ -579,41 +578,41 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
}
}
private genMusicElement(url: string, audio: string, title: string, content: string, image: string): SendArkElement {
const musicJson = {
app: 'com.tencent.structmsg',
config: {
ctime: 1709689928,
forward: 1,
token: '5c1e4905f926dd3a64a4bd3841460351',
type: 'normal',
},
extra: { app_type: 1, appid: 100497308, uin: selfInfo.uin },
meta: {
news: {
action: '',
android_pkg_name: '',
app_type: 1,
appid: 100497308,
ctime: 1709689928,
desc: content || title,
jumpUrl: url,
musicUrl: audio,
preview: image,
source_icon: 'https://p.qpic.cn/qqconnect/0/app_100497308_1626060999/100?max-age=2592000&t=0',
source_url: '',
tag: 'QQ音乐',
title: title,
uin: selfInfo.uin,
},
},
prompt: content || title,
ver: '0.0.0.1',
view: 'news',
}
// private genMusicElement(url: string, audio: string, title: string, content: string, image: string): SendArkElement {
// const musicJson = {
// app: 'com.tencent.structmsg',
// config: {
// ctime: 1709689928,
// forward: 1,
// token: '5c1e4905f926dd3a64a4bd3841460351',
// type: 'normal',
// },
// extra: { app_type: 1, appid: 100497308, uin: selfInfo.uin },
// meta: {
// news: {
// action: '',
// android_pkg_name: '',
// app_type: 1,
// appid: 100497308,
// ctime: 1709689928,
// desc: content || title,
// jumpUrl: url,
// musicUrl: audio,
// preview: image,
// source_icon: 'https://p.qpic.cn/qqconnect/0/app_100497308_1626060999/100?max-age=2592000&t=0',
// source_url: '',
// tag: 'QQ音乐',
// title: title,
// uin: selfInfo.uin,
// },
// },
// prompt: content || title,
// ver: '0.0.0.1',
// view: 'news',
// }
return SendMsgElementConstructor.ark(musicJson)
}
// return SendMsgElementConstructor.ark(musicJson)
// }
}
export default SendMsg

View File

@@ -234,7 +234,7 @@ export type OB11MessageMusic = OB11MessageIdMusic | OB11MessageCustomMusic
export interface OB11MessageJson {
type: OB11MessageDataType.json
data: { config: { token: string } } & any
data: { data: string /* , config: { token: string } */ }
}
export type OB11MessageData =