Skip to content

Commit

Permalink
supported short video message.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Aug 13, 2020
1 parent d49300e commit 0fa5228
Show file tree
Hide file tree
Showing 8 changed files with 859 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ qq-android协议的golang实现 移植于mirai
- [x] 长消息
- [x] 链接分享
- [x] 小程序(暂只支持RAW)
- [ ] 位置
- [x] 短视频(仅接收信息)
- [x] 合并转发
- [x] 群文件(仅接受消息)
- [x] 群文件(仅接收信息)

#### 事件
- [x] 好友消息
Expand Down
25 changes: 25 additions & 0 deletions client/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/client/pb/multimsg"
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
"github.com/Mrs4s/MiraiGo/client/pb/pttcenter"
"github.com/Mrs4s/MiraiGo/client/pb/structmsg"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/protocol/crypto"
Expand Down Expand Up @@ -994,3 +995,27 @@ func (c *QQClient) buildGroupFileDownloadReqPacket(groupCode int64, fileId strin
packet := packets.BuildUniPacket(c.Uin, seq, "OidbSvc.0x6d6_2", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
return seq, packet
}

func (c *QQClient) buildPttShortVideoDownReqPacket(uuid, md5 []byte) (uint16, []byte) {
seq := c.nextSeq()
body := &pttcenter.ShortVideoReqBody{
Cmd: 400,
Seq: int32(seq),
PttShortVideoDownloadReq: &pttcenter.ShortVideoDownloadReq{
FromUin: c.Uin,
ToUin: c.Uin,
ChatType: 1,
ClientType: 7,
FileId: string(uuid),
GroupCode: 1,
FileMd5: md5,
BusinessType: 1,
FileType: 2,
DownType: 2,
SceneType: 2,
},
}
payload, _ := proto.Marshal(body)
packet := packets.BuildUniPacket(c.Uin, seq, "PttCenterSvr.ShortVideoDownReq", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
return seq, packet
}
9 changes: 9 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
"MultiMsg.ApplyUp": decodeMultiApplyUpResponse,
"MultiMsg.ApplyDown": decodeMultiApplyDownResponse,
"OidbSvc.0x6d6_2": decodeOIDB6d6Response,
"PttCenterSvr.ShortVideoDownReq": decodePttShortVideoDownResponse,
},
sigInfo: &loginSigInfo{},
requestPacketRequestId: 1921334513,
Expand Down Expand Up @@ -209,6 +210,14 @@ func (c *QQClient) GetFriendList() (*FriendListResponse, error) {
return r, nil
}

func (c *QQClient) GetShortVideoUrl(uuid, md5 []byte) string {
i, err := c.sendAndWait(c.buildPttShortVideoDownReqPacket(uuid, md5))
if err != nil {
return ""
}
return i.(string)
}

func (c *QQClient) GetGroupFileUrl(groupCode int64, fileId string, busId int32) string {
i, err := c.sendAndWait(c.buildGroupFileDownloadReqPacket(groupCode, fileId, busId))
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions client/decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/Mrs4s/MiraiGo/client/pb/pttcenter"
"log"
"strconv"
"sync"
Expand Down Expand Up @@ -816,3 +817,14 @@ func decodeOIDB6d6Response(c *QQClient, _ uint16, payload []byte) (interface{},
url := hex.EncodeToString(rsp.DownloadFileRsp.DownloadUrl)
return fmt.Sprintf("http://%s/ftn_handler/%s/", ip, url), nil
}

func decodePttShortVideoDownResponse(c *QQClient, _ uint16, payload []byte) (interface{}, error) {
rsp := pttcenter.ShortVideoRspBody{}
if err := proto.Unmarshal(payload, &rsp); err != nil {
return nil, err
}
if rsp.PttShortVideoDownloadRsp == nil || rsp.PttShortVideoDownloadRsp.DownloadAddr == nil {
return nil, errors.New("resp error")
}
return rsp.PttShortVideoDownloadRsp.DownloadAddr.Host[0] + rsp.PttShortVideoDownloadRsp.DownloadAddr.UrlArgs, nil
}
Loading

0 comments on commit 0fa5228

Please sign in to comment.