Skip to content

Commit cdc3bf5

Browse files
committed
feat: 补全vlw三个api(获取好友列表,获取群组列表,获取订阅公众号列表)
1 parent c70371e commit cdc3bf5

File tree

4 files changed

+252
-65
lines changed

4 files changed

+252
-65
lines changed

engine/robot/model.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type ObjectInfo struct {
2626
MemberNum int `json:"memberNum"` // 群成员数量,仅当对象是群聊时有效
2727
}
2828

29+
// FriendInfo 好友信息
2930
type FriendInfo struct {
3031
WxId string `json:"wxId"` // 微信ID
3132
WxNum string `json:"wxNum"` // 微信号
@@ -49,19 +50,24 @@ type FriendInfo struct {
4950
MemberNum int `json:"memberNum"` // 群成员数量,仅当对象是群聊时有效
5051
}
5152

53+
// GroupInfo 群信息
5254
type GroupInfo struct {
53-
WxId string `json:"wxId"` // 微信ID
54-
WxNum string `json:"wxNum"` // 微信号
55-
Nick string `json:"nick"` // 昵称
56-
Remark string `json:"remark"` // 备注
57-
NickBrief string `json:"nickBrief"` // 昵称简拼
58-
NickWhole string `json:"nickWhole"` // 昵称全拼
59-
RemarkBrief string `json:"remarkBrief"` // 备注简拼
60-
RemarkWhole string `json:"remarkWhole"` // 备注全拼
61-
EnBrief string `json:"enBrief"` // 英文简拼
62-
EnWhole string `json:"enWhole"` // 英文全拼
55+
WxId string `json:"wxId"` // 微信ID
56+
WxNum string `json:"wxNum"` // 微信号
57+
Nick string `json:"nick"` // 昵称
58+
Remark string `json:"remark"` // 备注
59+
NickBrief string `json:"nickBrief"` // 昵称简拼
60+
NickWhole string `json:"nickWhole"` // 昵称全拼
61+
RemarkBrief string `json:"remarkBrief"` // 备注简拼
62+
RemarkWhole string `json:"remarkWhole"` // 备注全拼
63+
EnBrief string `json:"enBrief"` // 英文简拼
64+
EnWhole string `json:"enWhole"` // 英文全拼
65+
MemberNum int `json:"memberNum"` // 群成员数量,仅当对象是群聊时有效
66+
AvatarMinUrl string `json:"avatarMinUrl"` // 头像小图,需要在会话列表中
67+
AvatarMaxUrl string `json:"avatarMaxUrl"` // 头像大图,需要在会话列表中
6368
}
6469

70+
// SubscriptionInfo 订阅公众号信息
6571
type SubscriptionInfo struct {
6672
WxId string `json:"wxId"` // 微信ID
6773
WxNum string `json:"wxNum"` // 微信号

framework/qianxun/httpapi.go

+54-51
Original file line numberDiff line numberDiff line change
@@ -364,28 +364,28 @@ func (f *Framework) GetFriendsList(isRefresh bool) ([]*robot.FriendInfo, error)
364364
return nil, err
365365
}
366366
var friendsInfoList []*robot.FriendInfo
367-
for i := range dataResp.Result {
367+
for _, res := range dataResp.Result {
368368
friendsInfoList = append(friendsInfoList, &robot.FriendInfo{
369-
WxId: dataResp.Result[i].Wxid,
370-
WxNum: dataResp.Result[i].WxNum,
371-
Nick: dataResp.Result[i].Nick,
372-
Remark: dataResp.Result[i].Remark,
373-
NickBrief: dataResp.Result[i].NickBrief,
374-
NickWhole: dataResp.Result[i].NickWhole,
375-
RemarkBrief: dataResp.Result[i].RemarkBrief,
376-
RemarkWhole: dataResp.Result[i].RemarkWhole,
377-
EnBrief: dataResp.Result[i].EnBrief,
378-
EnWhole: dataResp.Result[i].EnWhole,
379-
V3: dataResp.Result[i].V3,
380-
Sign: dataResp.Result[i].Sign,
381-
Country: dataResp.Result[i].Country,
382-
Province: dataResp.Result[i].Province,
383-
City: dataResp.Result[i].City,
384-
MomentsBackgroundImgUrl: dataResp.Result[i].MomentsBackgroudImgUrl,
385-
AvatarMinUrl: dataResp.Result[i].AvatarMinUrl,
386-
AvatarMaxUrl: dataResp.Result[i].AvatarMaxUrl,
387-
Sex: dataResp.Result[i].Sex,
388-
MemberNum: dataResp.Result[i].MemberNum,
369+
WxId: res.Wxid,
370+
WxNum: res.WxNum,
371+
Nick: res.Nick,
372+
Remark: res.Remark,
373+
NickBrief: res.NickBrief,
374+
NickWhole: res.NickWhole,
375+
RemarkBrief: res.RemarkBrief,
376+
RemarkWhole: res.RemarkWhole,
377+
EnBrief: res.EnBrief,
378+
EnWhole: res.EnWhole,
379+
V3: res.V3,
380+
Sign: res.Sign,
381+
Country: res.Country,
382+
Province: res.Province,
383+
City: res.City,
384+
MomentsBackgroundImgUrl: res.MomentsBackgroudImgUrl,
385+
AvatarMinUrl: res.AvatarMinUrl,
386+
AvatarMaxUrl: res.AvatarMaxUrl,
387+
Sex: res.Sex,
388+
MemberNum: res.MemberNum,
389389
})
390390
}
391391

@@ -420,18 +420,21 @@ func (f *Framework) GetGroupList(isRefresh bool) ([]*robot.GroupInfo, error) {
420420
return nil, err
421421
}
422422
var groupInfoList []*robot.GroupInfo
423-
for i := range dataResp.Result {
423+
for _, res := range dataResp.Result {
424424
groupInfoList = append(groupInfoList, &robot.GroupInfo{
425-
WxId: dataResp.Result[i].Wxid,
426-
WxNum: dataResp.Result[i].WxNum,
427-
Nick: dataResp.Result[i].Nick,
428-
Remark: dataResp.Result[i].Remark,
429-
NickBrief: dataResp.Result[i].NickBrief,
430-
NickWhole: dataResp.Result[i].NickWhole,
431-
RemarkBrief: dataResp.Result[i].RemarkBrief,
432-
RemarkWhole: dataResp.Result[i].RemarkWhole,
433-
EnBrief: dataResp.Result[i].EnBrief,
434-
EnWhole: dataResp.Result[i].EnWhole,
425+
WxId: res.Wxid,
426+
WxNum: res.WxNum,
427+
Nick: res.Nick,
428+
Remark: res.Remark,
429+
NickBrief: res.NickBrief,
430+
NickWhole: res.NickWhole,
431+
RemarkBrief: res.RemarkBrief,
432+
RemarkWhole: res.RemarkWhole,
433+
EnBrief: res.EnBrief,
434+
EnWhole: res.EnWhole,
435+
MemberNum: res.MemberNum,
436+
AvatarMinUrl: res.AvatarMinUrl,
437+
AvatarMaxUrl: res.AvatarMaxUrl,
435438
})
436439
}
437440
return groupInfoList, nil
@@ -457,26 +460,26 @@ func (f *Framework) GetSubscriptionList(isRefresh bool) ([]*robot.SubscriptionIn
457460
return nil, err
458461
}
459462
var subscriptionInfoList []*robot.SubscriptionInfo
460-
for i := range dataResp.Result {
463+
for _, res := range dataResp.Result {
461464
subscriptionInfoList = append(subscriptionInfoList, &robot.SubscriptionInfo{
462-
WxId: dataResp.Result[i].Wxid,
463-
WxNum: dataResp.Result[i].WxNum,
464-
Nick: dataResp.Result[i].Nick,
465-
Remark: dataResp.Result[i].Remark,
466-
NickBrief: dataResp.Result[i].NickBrief,
467-
NickWhole: dataResp.Result[i].NickWhole,
468-
RemarkBrief: dataResp.Result[i].RemarkBrief,
469-
RemarkWhole: dataResp.Result[i].RemarkWhole,
470-
EnBrief: dataResp.Result[i].EnBrief,
471-
EnWhole: dataResp.Result[i].EnWhole,
472-
V3: dataResp.Result[i].V3,
473-
Sign: dataResp.Result[i].Sign,
474-
Country: dataResp.Result[i].Country,
475-
Province: dataResp.Result[i].Province,
476-
City: dataResp.Result[i].City,
477-
MomentsBackgroundImgUrl: dataResp.Result[i].MomentsBackgroudImgUrl,
478-
AvatarMinUrl: dataResp.Result[i].AvatarMinUrl,
479-
AvatarMaxUrl: dataResp.Result[i].AvatarMaxUrl,
465+
WxId: res.Wxid,
466+
WxNum: res.WxNum,
467+
Nick: res.Nick,
468+
Remark: res.Remark,
469+
NickBrief: res.NickBrief,
470+
NickWhole: res.NickWhole,
471+
RemarkBrief: res.RemarkBrief,
472+
RemarkWhole: res.RemarkWhole,
473+
EnBrief: res.EnBrief,
474+
EnWhole: res.EnWhole,
475+
V3: res.V3,
476+
Sign: res.Sign,
477+
Country: res.Country,
478+
Province: res.Province,
479+
City: res.City,
480+
MomentsBackgroundImgUrl: res.MomentsBackgroudImgUrl,
481+
AvatarMinUrl: res.AvatarMinUrl,
482+
AvatarMaxUrl: res.AvatarMaxUrl,
480483
})
481484
}
482485
return subscriptionInfoList, nil

framework/vlw/httpapi.go

+112-4
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,125 @@ func (f *Framework) InviteIntoGroup(groupWxId, wxId string, typ int) error {
327327
}
328328

329329
func (f *Framework) GetObjectInfo(wxId string) (*robot.ObjectInfo, error) {
330-
return nil, nil
330+
payload := map[string]interface{}{
331+
"api": "GetFriendlist",
332+
"token": f.ApiToken,
333+
"robot_wxid": f.BotWxId,
334+
"to_wxid": wxId,
335+
}
336+
337+
var dataResp ObjectInfoResp
338+
if err := NewRequest().Post(f.ApiUrl).SetBody(payload).SetSuccessResult(&dataResp).Do().Err; err != nil {
339+
log.Errorf("[VLW] GetObjectInfo error: %v", err.Error())
340+
return nil, err
341+
}
342+
return &robot.ObjectInfo{
343+
WxId: dataResp.ReturnJson.Data.Wxid,
344+
WxNum: dataResp.ReturnJson.Data.Account,
345+
Nick: dataResp.ReturnJson.Data.Nickname,
346+
Remark: dataResp.ReturnJson.Data.Remark,
347+
V3: dataResp.ReturnJson.Data.V1,
348+
V4: dataResp.ReturnJson.Data.V2,
349+
Sign: dataResp.ReturnJson.Data.Signature,
350+
Country: dataResp.ReturnJson.Data.Country,
351+
Province: dataResp.ReturnJson.Data.Province,
352+
City: dataResp.ReturnJson.Data.City,
353+
AvatarMinUrl: dataResp.ReturnJson.Data.SmallAvatar,
354+
AvatarMaxUrl: dataResp.ReturnJson.Data.Avatar,
355+
Sex: strconv.Itoa(dataResp.ReturnJson.Data.Sex),
356+
}, nil
331357
}
332358

333359
func (f *Framework) GetFriendsList(isRefresh bool) ([]*robot.FriendInfo, error) {
334-
return nil, nil
360+
dataType := 0
361+
if isRefresh {
362+
dataType = 1
363+
}
364+
payload := map[string]interface{}{
365+
"api": "GetFriendlist",
366+
"token": f.ApiToken,
367+
"robot_wxid": f.BotWxId,
368+
"is_refresh": dataType,
369+
}
370+
371+
var dataResp FriendsListResp
372+
if err := NewRequest().Post(f.ApiUrl).SetBody(payload).SetSuccessResult(&dataResp).Do().Err; err != nil {
373+
log.Errorf("[VLW] GetFriendsList error: %v", err.Error())
374+
return nil, err
375+
}
376+
var friendsInfoList []*robot.FriendInfo
377+
for _, res := range dataResp.ReturnJson {
378+
friendsInfoList = append(friendsInfoList, &robot.FriendInfo{
379+
WxId: res.Wxid,
380+
WxNum: res.WxNum,
381+
Nick: res.Nickname,
382+
Remark: res.Note,
383+
Country: res.Country,
384+
Province: res.Province,
385+
City: res.City,
386+
AvatarMinUrl: res.Avatar,
387+
AvatarMaxUrl: res.Avatar,
388+
Sex: strconv.Itoa(res.Sex),
389+
})
390+
}
391+
return friendsInfoList, nil
335392
}
336393

337394
func (f *Framework) GetGroupList(isRefresh bool) ([]*robot.GroupInfo, error) {
338-
return nil, nil
395+
dataType := 0
396+
if isRefresh {
397+
dataType = 1
398+
}
399+
payload := map[string]interface{}{
400+
"api": "GetGrouplist",
401+
"token": f.ApiToken,
402+
"robot_wxid": f.BotWxId,
403+
"is_refresh": dataType,
404+
}
405+
406+
var dataResp GroupListResp
407+
if err := NewRequest().Post(f.ApiUrl).SetBody(payload).SetSuccessResult(&dataResp).Do().Err; err != nil {
408+
log.Errorf("[VLW] GetGroupList error: %v", err.Error())
409+
return nil, err
410+
}
411+
var groupInfoList []*robot.GroupInfo
412+
for _, res := range dataResp.ReturnJson {
413+
groupInfoList = append(groupInfoList, &robot.GroupInfo{
414+
WxId: res.Wxid,
415+
Nick: res.Nickname,
416+
MemberNum: res.TotalMember,
417+
AvatarMinUrl: res.Avatar,
418+
AvatarMaxUrl: res.Avatar,
419+
})
420+
}
421+
return groupInfoList, nil
339422
}
340423

341424
func (f *Framework) GetSubscriptionList(isRefresh bool) ([]*robot.SubscriptionInfo, error) {
342-
return nil, nil
425+
dataType := 0
426+
if isRefresh {
427+
dataType = 1
428+
}
429+
payload := map[string]interface{}{
430+
"api": "GetSubscriptionlist",
431+
"token": f.ApiToken,
432+
"robot_wxid": f.BotWxId,
433+
"is_refresh": dataType,
434+
}
435+
436+
var dataResp SubscriptionListResp
437+
if err := NewRequest().Post(f.ApiUrl).SetBody(payload).SetSuccessResult(&dataResp).Do().Err; err != nil {
438+
log.Errorf("[VLW] GetSubscriptionList error: %v", err.Error())
439+
return nil, err
440+
}
441+
var subscriptionInfoList []*robot.SubscriptionInfo
442+
for _, res := range dataResp.ReturnJson {
443+
subscriptionInfoList = append(subscriptionInfoList, &robot.SubscriptionInfo{
444+
WxId: res.Wxid,
445+
Nick: res.Nickname,
446+
AvatarMinUrl: res.Avatar,
447+
AvatarMaxUrl: res.Avatar,
448+
})
449+
}
450+
return subscriptionInfoList, nil
343451
}

framework/vlw/model.go

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package vlw
2+
3+
// ObjectInfoResp 对象可以是好友、群、公众号
4+
type ObjectInfoResp struct {
5+
Code int `json:"Code"`
6+
Result string `json:"Result"`
7+
ReturnJson struct {
8+
Data struct {
9+
Account string `json:"account"`
10+
Avatar string `json:"avatar"`
11+
City string `json:"city"`
12+
Country string `json:"country"`
13+
Nickname string `json:"nickname"`
14+
Province string `json:"province"`
15+
Remark string `json:"remark"`
16+
Sex int `json:"sex"`
17+
Signature string `json:"signature"`
18+
SmallAvatar string `json:"small_avatar"`
19+
SnsPic string `json:"sns_pic"`
20+
SourceType int `json:"source_type"`
21+
Status int `json:"status"`
22+
V1 string `json:"v1"`
23+
V2 string `json:"v2"`
24+
Wxid string `json:"wxid"`
25+
} `json:"data"`
26+
Type int `json:"type"`
27+
} `json:"ReturnJson"`
28+
}
29+
30+
// FriendsListResp 获取好友列表响应
31+
type FriendsListResp struct {
32+
Code int `json:"Code"`
33+
Result string `json:"Result"`
34+
ReturnJson []struct {
35+
WxNum string `json:"wx_num"`
36+
Avatar string `json:"avatar"`
37+
City string `json:"city"`
38+
Country string `json:"country"`
39+
Nickname string `json:"nickname"`
40+
Province string `json:"province"`
41+
Note string `json:"note"`
42+
Sex int `json:"sex"`
43+
Wxid string `json:"wxid"`
44+
} `json:"ReturnJson"`
45+
}
46+
47+
// GroupListResp 获取群组列表响应
48+
type GroupListResp struct {
49+
Code int `json:"Code"`
50+
Result string `json:"Result"`
51+
ReturnJson []struct {
52+
Avatar string `json:"avatar"`
53+
IsManager int `json:"is_manager"`
54+
ManagerWxid string `json:"manager_wxid"`
55+
Nickname string `json:"nickname"`
56+
TotalMember int `json:"total_member"`
57+
Wxid string `json:"wxid"`
58+
} `json:"ReturnJson"`
59+
}
60+
61+
// SubscriptionListResp 获取订阅号列表响应
62+
type SubscriptionListResp struct {
63+
Code int `json:"Code"`
64+
Result string `json:"Result"`
65+
ReturnJson []struct {
66+
Avatar string `json:"avatar"`
67+
Nickname string `json:"nickname"`
68+
Wxid string `json:"wxid"`
69+
} `json:"ReturnJson"`
70+
}

0 commit comments

Comments
 (0)