Skip to content

Commit 16e091a

Browse files
authored
Merge pull request #3 from fuh/main
feat: add sphfeed message
2 parents 13e1ca6 + 727b816 commit 16e091a

File tree

3 files changed

+83
-69
lines changed

3 files changed

+83
-69
lines changed

chat.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ type ChatData struct {
2020
}
2121

2222
type ChatMessage struct {
23-
Id string // 消息id,消息的唯一标识,企业可以使用此字段进行消息去重。
24-
From string // 消息发送方id。同一企业内容为userid,非相同企业为external_userid。消息如果是机器人发出,也为external_userid。
25-
ToList []string // 消息接收方列表,可能是多个,同一个企业内容为userid,非相同企业为external_userid。
26-
Action string // 消息动作,目前有send(发送消息)/recall(撤回消息)/switch(切换企业日志)三种类型。
27-
Type string // 消息类型
28-
originData []byte // 原始消息对象
23+
Id string // 消息id,消息的唯一标识,企业可以使用此字段进行消息去重。
24+
From string // 消息发送方id。同一企业内容为userid,非相同企业为external_userid。消息如果是机器人发出,也为external_userid。
25+
ToList []string // 消息接收方列表,可能是多个,同一个企业内容为userid,非相同企业为external_userid。
26+
Action string // 消息动作,目前有send(发送消息)/recall(撤回消息)/switch(切换企业日志)三种类型。
27+
Type string // 消息类型
28+
originData []byte // 原始消息对象
2929
}
3030

31-
func (c ChatMessage) GetOriginMessage() (msg map[string]interface{}) {
31+
func (c ChatMessage) GetOriginMessage() (msg map[string]interface{}) {
3232
_ = json.Unmarshal(c.originData, &msg)
3333
return msg
3434
}
@@ -163,6 +163,11 @@ func (c ChatMessage) GetExternalRedPacketMessage() (msg ExternalRedPacketMessage
163163
return msg
164164
}
165165

166+
func (c ChatMessage) GetSphFeedMessage() (msg SphFeedMessage) {
167+
_ = json.Unmarshal(c.originData, &msg)
168+
return msg
169+
}
170+
166171
func (c ChatMessage) GetSwitchMessage() (msg SwitchMessage) {
167172
_ = json.Unmarshal(c.originData, &msg)
168173
return msg

example/example.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package main
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/NICEXAI/WeWorkFinanceSDK"
76
"io/ioutil"
87
"os"
98
"path"
9+
10+
"github.com/NICEXAI/WeWorkFinanceSDK"
1011
)
1112

1213
func main() {
@@ -42,9 +43,10 @@ func main() {
4243

4344
isFinish := false
4445
buffer := bytes.Buffer{}
46+
index_buf := ""
4547
for !isFinish {
4648
//获取媒体数据
47-
mediaData, err := client.GetMediaData("", sdkfileid, "", "", 5)
49+
mediaData, err := client.GetMediaData(index_buf, sdkfileid, "", "", 5)
4850
if err != nil {
4951
fmt.Printf("媒体数据拉取失败:%v \n", err)
5052
return
@@ -53,6 +55,7 @@ func main() {
5355
if mediaData.IsFinish {
5456
isFinish = mediaData.IsFinish
5557
}
58+
index_buf = mediaData.OutIndexBuf
5659
}
5760
filePath, _ := os.Getwd()
5861
filePath = path.Join(filePath, "test.png")
@@ -65,5 +68,3 @@ func main() {
6568
}
6669
}
6770
}
68-
69-

message.go

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package WeWorkFinanceSDK
22

3-
43
type BaseMessage struct {
5-
MsgId string `json:"msgid,omitempty"` // 消息id,消息的唯一标识,企业可以使用此字段进行消息去重。
6-
Action string `json:"action,omitempty"` // 消息动作,目前有send(发送消息)/recall(撤回消息)/switch(切换企业日志)三种类型。
7-
From string `json:"from,omitempty"` // 消息发送方id。同一企业内容为userid,非相同企业为external_userid。消息如果是机器人发出,也为external_userid。
8-
ToList []string `json:"tolist,omitempty"` // 消息接收方列表,可能是多个,同一个企业内容为userid,非相同企业为external_userid。
9-
RoomId string `json:"roomid,omitempty"` // 群聊消息的群id。如果是单聊则为空。
10-
MsgTime int64 `json:"msgtime,omitempty"` // 消息发送时间戳,utc时间,ms单位。
11-
MsgType string `json:"msgtype,omitempty"` // 文本消息为:text。
4+
MsgId string `json:"msgid,omitempty"` // 消息id,消息的唯一标识,企业可以使用此字段进行消息去重。
5+
Action string `json:"action,omitempty"` // 消息动作,目前有send(发送消息)/recall(撤回消息)/switch(切换企业日志)三种类型。
6+
From string `json:"from,omitempty"` // 消息发送方id。同一企业内容为userid,非相同企业为external_userid。消息如果是机器人发出,也为external_userid。
7+
ToList []string `json:"tolist,omitempty"` // 消息接收方列表,可能是多个,同一个企业内容为userid,非相同企业为external_userid。
8+
RoomId string `json:"roomid,omitempty"` // 群聊消息的群id。如果是单聊则为空。
9+
MsgTime int64 `json:"msgtime,omitempty"` // 消息发送时间戳,utc时间,ms单位。
10+
MsgType string `json:"msgtype,omitempty"` // 文本消息为:text。
1211
}
1312

1413
type TextMessage struct {
1514
BaseMessage
16-
Text struct{
15+
Text struct {
1716
Content string `json:"content,omitempty"` // 消息内容。
1817
} `json:"text,omitempty"`
1918
}
2019

2120
type ImageMessage struct {
2221
BaseMessage
23-
Image struct{
22+
Image struct {
2423
SdkFileId string `json:"sdkfileid,omitempty"` // 媒体资源的id信息。
2524
Md5Sum string `json:"md5sum,omitempty"` // 图片资源的md5值,供进行校验。
2625
FileSize uint32 `json:"filesize,omitempty"` // 图片资源的文件大小。
@@ -29,22 +28,22 @@ type ImageMessage struct {
2928

3029
type RevokeMessage struct {
3130
BaseMessage
32-
Revoke struct{
31+
Revoke struct {
3332
PreMsgId string `json:"pre_msgid,omitempty"` // 标识撤回的原消息的msgid
3433
} `json:"revoke,omitempty"`
3534
}
3635

3736
type AgreeMessage struct {
3837
BaseMessage
39-
Agree struct{
38+
Agree struct {
4039
UserId string `json:"userid,omitempty"` // 同意/不同意协议者的userid,外部企业默认为external_userid。
4140
AgreeTime int64 `json:"agree_time,omitempty"` // 同意/不同意协议的时间,utc时间,ms单位。
4241
} `json:"agree,omitempty"`
4342
}
4443

4544
type VoiceMessage struct {
4645
BaseMessage
47-
Voice struct{
46+
Voice struct {
4847
SdkFileId string `json:"sdkfileid,omitempty"` // 媒体资源的id信息。
4948
VoiceSize uint32 `json:"voice_size,omitempty"` // 语音消息大小。
5049
PlayLength uint32 `json:"play_length,omitempty"` // 播放长度。
@@ -54,7 +53,7 @@ type VoiceMessage struct {
5453

5554
type VideoMessage struct {
5655
BaseMessage
57-
Video struct{
56+
Video struct {
5857
SdkFileId string `json:"sdkfileid,omitempty"` // 媒体资源的id信息。
5958
FileSize uint32 `json:"filesize,omitempty"` // 图片资源的文件大小。
6059
PlayLength uint32 `json:"play_length,omitempty"` // 播放长度。
@@ -64,15 +63,15 @@ type VideoMessage struct {
6463

6564
type CardMessage struct {
6665
BaseMessage
67-
Card struct{
66+
Card struct {
6867
CorpName string `json:"corpname,omitempty"` // 名片所有者所在的公司名称。
6968
UserId string `json:"userid,omitempty"` // 名片所有者的id,同一公司是userid,不同公司是external_userid
7069
} `json:"card,omitempty"`
7170
}
7271

7372
type LocationMessage struct {
7473
BaseMessage
75-
Location struct{
74+
Location struct {
7675
Lng float64 `json:"longitude,omitempty"` // 经度,单位double
7776
Lat float64 `json:"latitude,omitempty"` // 纬度,单位double
7877
Address string `json:"address,omitempty"` // 地址信息
@@ -83,19 +82,19 @@ type LocationMessage struct {
8382

8483
type EmotionMessage struct {
8584
BaseMessage
86-
Emotion struct{
85+
Emotion struct {
8786
Type uint32 `json:"type,omitempty"` // 表情类型,png或者gif.1表示gif 2表示png。
88-
Width uint32 `json:"width,omitempty"` // 表情图片宽度。
89-
Height uint32 `json:"height,omitempty"` // 表情图片高度。
90-
ImageSize uint32 `json:"imagesize,omitempty"` // 资源的文件大小。
91-
SdkFileId string `json:"sdkfileid,omitempty"` // 媒体资源的id信息。
92-
Md5Sum string `json:"md5sum,omitempty"` // 图片资源的md5值,供进行校验。
87+
Width uint32 `json:"width,omitempty"` // 表情图片宽度。
88+
Height uint32 `json:"height,omitempty"` // 表情图片高度。
89+
ImageSize uint32 `json:"imagesize,omitempty"` // 资源的文件大小。
90+
SdkFileId string `json:"sdkfileid,omitempty"` // 媒体资源的id信息。
91+
Md5Sum string `json:"md5sum,omitempty"` // 图片资源的md5值,供进行校验。
9392
} `json:"emotion,omitempty"`
9493
}
9594

9695
type FileMessage struct {
9796
BaseMessage
98-
File struct{
97+
File struct {
9998
FileName string `json:"filename,omitempty"` // 文件名称。
10099
FileExt string `json:"fileext,omitempty"` // 文件类型后缀。
101100
SdkFileId string `json:"sdkfileid,omitempty"` // 媒体资源的id信息。
@@ -106,7 +105,7 @@ type FileMessage struct {
106105

107106
type LinkMessage struct {
108107
BaseMessage
109-
Link struct{
108+
Link struct {
110109
Title string `json:"title,omitempty"` // 消息标题。
111110
Desc string `json:"description,omitempty"` // 消息描述。
112111
LinkUrl string `json:"link_url,omitempty"` // 链接url地址
@@ -116,7 +115,7 @@ type LinkMessage struct {
116115

117116
type WeappMessage struct {
118117
BaseMessage
119-
WeApp struct{
118+
WeApp struct {
120119
Title string `json:"title,omitempty"` // 消息标题。
121120
Desc string `json:"description,omitempty"` // 消息描述。
122121
Username string `json:"username,omitempty"` // 用户名称。
@@ -126,31 +125,31 @@ type WeappMessage struct {
126125

127126
type ChatRecordMessage struct {
128127
BaseMessage
129-
ChatRecord struct{
128+
ChatRecord struct {
130129
Title string `json:"title,omitempty"` // 聊天记录标题
131130
Item []ChatRecord `json:"item,omitempty"` // 消息记录内的消息内容,批量数据
132131
} `json:"chatrecord,omitempty"`
133132
}
134133

135134
type TodoMessage struct {
136135
BaseMessage
137-
Todo struct{
138-
Title string `json:"title,omitempty"` // 代办的来源文本
139-
Content string `json:"content,omitempty"` // 代办的具体内容
136+
Todo struct {
137+
Title string `json:"title,omitempty"` // 代办的来源文本
138+
Content string `json:"content,omitempty"` // 代办的具体内容
140139
} `json:"todo,omitempty"`
141140
}
142141

143142
type VoteMessage struct {
144143
BaseMessage
145144
VoteTitle string `json:"votetitle,omitempty"` // 投票主题。
146145
VoteItem []string `json:"voteitem,omitempty"` // 投票选项,可能多个内容。
147-
VoteType uint32 `json:"votetype,omitempty"` // 投票类型.101发起投票、102参与投票。
146+
VoteType uint32 `json:"votetype,omitempty"` // 投票类型.101发起投票、102参与投票。
148147
VoteId string `json:"voteid,omitempty"` // 投票id,方便将参与投票消息与发起投票消息进行前后对照。
149148
}
150149

151150
type CollectMessage struct {
152151
BaseMessage
153-
Collect struct{
152+
Collect struct {
154153
RoomName string `json:"room_name,omitempty"` // 填表消息所在的群名称。
155154
Creator string `json:"creator,omitempty"` // 创建者在群中的名字
156155
CreateTime string `json:"create_time,omitempty"` // 创建的时间
@@ -160,31 +159,31 @@ type CollectMessage struct {
160159

161160
type RedpacketMessage struct {
162161
BaseMessage
163-
RedPacket struct{
162+
RedPacket struct {
164163
Type uint32 `json:"type,omitempty"` // 红包消息类型。1 普通红包、2 拼手气群红包、3 激励群红包。
165-
Wish string `json:"wish,omitempty"` // 红包祝福语
166-
TotalCnt uint32 `json:"totalcnt,omitempty"` // 红包总个数
167-
TotalAmount uint32 `json:"totalamount,omitempty"` // 红包总金额。单位为分。
164+
Wish string `json:"wish,omitempty"` // 红包祝福语
165+
TotalCnt uint32 `json:"totalcnt,omitempty"` // 红包总个数
166+
TotalAmount uint32 `json:"totalamount,omitempty"` // 红包总金额。单位为分。
168167
} `json:"redpacket,omitempty"`
169168
}
170169

171170
type MeetingMessage struct {
172171
BaseMessage
173-
Meeting struct{
174-
Topic string `json:"topic,omitempty"` // 会议主题
175-
StartTime int64 `json:"starttime,omitempty"` // 会议开始时间。Utc时间
176-
EndTime int64 `json:"endtime,omitempty"` // 会议结束时间。Utc时间
177-
Address string `json:"address,omitempty"` // 会议地址
178-
Remarks string `json:"remarks,omitempty"` // 会议备注
179-
MeetingType uint32 `json:"meetingtype,omitempty"` // 会议消息类型。101发起会议邀请消息、102处理会议邀请消息
180-
MeetingId uint64 `json:"meetingid,omitempty"` // 会议id。方便将发起、处理消息进行对照
181-
Status uint32 `json:"status,omitempty"` // 会议邀请处理状态。1 参加会议、2 拒绝会议、3 待定、4 未被邀请、5 会议已取消、6 会议已过期、7 不在房间内。
172+
Meeting struct {
173+
Topic string `json:"topic,omitempty"` // 会议主题
174+
StartTime int64 `json:"starttime,omitempty"` // 会议开始时间。Utc时间
175+
EndTime int64 `json:"endtime,omitempty"` // 会议结束时间。Utc时间
176+
Address string `json:"address,omitempty"` // 会议地址
177+
Remarks string `json:"remarks,omitempty"` // 会议备注
178+
MeetingType uint32 `json:"meetingtype,omitempty"` // 会议消息类型。101发起会议邀请消息、102处理会议邀请消息
179+
MeetingId uint64 `json:"meetingid,omitempty"` // 会议id。方便将发起、处理消息进行对照
180+
Status uint32 `json:"status,omitempty"` // 会议邀请处理状态。1 参加会议、2 拒绝会议、3 待定、4 未被邀请、5 会议已取消、6 会议已过期、7 不在房间内。
182181
} `json:"meeting,omitempty"`
183182
}
184183

185184
type DocMessage struct {
186185
BaseMessage
187-
Doc struct{
186+
Doc struct {
188187
Title string `json:"title,omitempty"` // 在线文档名称
189188
LinkUrl string `json:"link_url,omitempty"` // 在线文档链接
190189
DocCreator string `json:"doc_creator,omitempty"` // 在线文档创建者。本企业成员创建为userid;外部企业成员创建为external_userid
@@ -193,7 +192,7 @@ type DocMessage struct {
193192

194193
type MarkdownMessage struct {
195194
BaseMessage
196-
Info struct{
195+
Info struct {
197196
Content string `json:"content,omitempty"` // markdown消息内容,目前为机器人发出的消息
198197
} `json:"info,omitempty"`
199198
}
@@ -207,7 +206,7 @@ type NewsMessage struct {
207206

208207
type CalendarMessage struct {
209208
BaseMessage
210-
Calendar struct{
209+
Calendar struct {
211210
Title string `json:"title,omitempty"` // 日程主题
212211
CreatorName string `json:"creatorname,omitempty"` // 日程组织者
213212
AttendeeName []string `json:"attendeename,omitempty"` // 日程参与人。数组,内容为String类型
@@ -239,14 +238,23 @@ type VoipDocShareMessage struct {
239238

240239
type ExternalRedPacketMessage struct {
241240
BaseMessage
242-
RedPacket struct{
243-
Type int32 `json:"type,omitempty"` // 红包消息类型。1 普通红包、2 拼手气群红包。Uint32类型
244-
Wish int32 `json:"wish,omitempty"` // 红包祝福语。String类型
245-
TotalCnt int32 `json:"totalcnt,omitempty"` // 红包总个数。Uint32类型
246-
TotalAmount int32 `json:"totalamount,omitempty"` // 红包消息类型。1 普通红包、2 拼手气群红包。Uint32类型
241+
RedPacket struct {
242+
Type int32 `json:"type,omitempty"` // 红包消息类型。1 普通红包、2 拼手气群红包。Uint32类型
243+
Wish int32 `json:"wish,omitempty"` // 红包祝福语。String类型
244+
TotalCnt int32 `json:"totalcnt,omitempty"` // 红包总个数。Uint32类型
245+
TotalAmount int32 `json:"totalamount,omitempty"` // 红包消息类型。1 普通红包、2 拼手气群红包。Uint32类型
247246
} `json:"redpacket,omitempty"`
248247
}
249248

249+
type SphFeedMessage struct {
250+
BaseMessage
251+
SphFeed struct {
252+
FeedType string `json:"feed_type,omitempty"` // 视频号消息类型
253+
SphName string `json:"sph_name,omitempty"` // 视频号账号名称
254+
FeedDesc uint64 `json:"feed_desc,omitempty"` // 视频号账号名称
255+
}
256+
}
257+
250258
type SwitchMessage struct {
251259
MsgId string `json:"msgid,omitempty"` // 消息id,消息的唯一标识,企业可以使用此字段进行消息去重
252260
Action string `json:"action,omitempty"` // 消息动作,切换企业为switch
@@ -256,14 +264,14 @@ type SwitchMessage struct {
256264

257265
type ChatRecord struct {
258266
Type string `json:"type,omitempty"` // 每条聊天记录的具体消息类型:ChatRecordText/ ChatRecordFile/ ChatRecordImage/ ChatRecordVideo/ ChatRecordLink/ ChatRecordLocation/ ChatRecordMixed ….
259-
Content string `json:"content,omitempty"` // 消息内容。Json串,内容为对应类型的json
260-
MsgTime int64 `json:"msgtime,omitempty"` // 消息时间,utc时间,ms单位。
261-
FromChatroom bool `json:"from_chatroom,omitempty"` // 是否来自群会话。
267+
Content string `json:"content,omitempty"` // 消息内容。Json串,内容为对应类型的json
268+
MsgTime int64 `json:"msgtime,omitempty"` // 消息时间,utc时间,ms单位。
269+
FromChatroom bool `json:"from_chatroom,omitempty"` // 是否来自群会话。
262270
}
263271

264272
type CollectDetails struct {
265-
Id uint64 `json:"id,omitempty"` // 表项id
266-
Ques string `json:"ques,omitempty"` // 表项名称
273+
Id uint64 `json:"id,omitempty"` // 表项id
274+
Ques string `json:"ques,omitempty"` // 表项名称
267275
Type string `json:"type,omitempty"` // 表项类型,有Text(文本),Number(数字),Date(日期),Time(时间)
268276
}
269277

@@ -276,7 +284,7 @@ type News struct {
276284

277285
type MixedMsg struct {
278286
Type string `json:"type,omitempty"`
279-
Content string `json:"content,omitempty"`
287+
Content string `json:"content,omitempty"`
280288
}
281289

282290
type MeetingVoiceCall struct {

0 commit comments

Comments
 (0)