Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/intchensc/qzone/api/common"
"github.com/intchensc/qzone/api/friend"
"github.com/intchensc/qzone/api/group"
"github.com/intchensc/qzone/api/history"
"github.com/intchensc/qzone/api/message"
"github.com/intchensc/qzone/api/shuoshuo"
"github.com/intchensc/qzone/auth"
)
Expand All @@ -16,7 +16,7 @@ type API struct {
*common.BaseAPI
}

// NewAPI 创建新的API实例
// New 创建新的API实例
func New() *API {
return &API{BaseAPI: &common.BaseAPI{Err: errors.New("未登录无法调用 API")}}
}
Expand All @@ -27,21 +27,21 @@ func (a *API) SetLogin(auth auth.BaseAuth) {
}

// Friend 获取好友API实例
func (a *API) Friend() *friend.FriendAPI {
return &friend.FriendAPI{BaseAPI: a.BaseAPI}
func (a *API) Friend() *friend.API {
return &friend.API{BaseAPI: a.BaseAPI}
}

// Group 获取群组API实例
func (a *API) Group() *group.GroupAPI {
return &group.GroupAPI{BaseAPI: a.BaseAPI}
func (a *API) Group() *group.API {
return &group.API{BaseAPI: a.BaseAPI}
}

// History 获取历史记录API实例
func (a *API) History() *history.HistoryAPI {
return &history.HistoryAPI{BaseAPI: a.BaseAPI}
// Message 获取历史记录API实例
func (a *API) Message() *message.API {
return &message.API{BaseAPI: a.BaseAPI}
}

// ShuoShuo 获取说说API实例
func (a *API) ShuoShuo() *shuoshuo.ShuoShuoAPI {
return &shuoshuo.ShuoShuoAPI{BaseAPI: a.BaseAPI}
func (a *API) ShuoShuo() *shuoshuo.API {
return &shuoshuo.API{BaseAPI: a.BaseAPI}
}
8 changes: 4 additions & 4 deletions api/common/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ var (
)

type BaseAPI struct {
Qq int64 // QQ号
Qq int64 // QQ号
//Gtk string
Gtk string
Gtk2 string
Pskey string
Skey string
Uin string
Cookie string
Err error
}

// unpack 初始化信息,将成功扫码登录获取到的cookie解析
// Unpack 初始化信息,将成功扫码登录获取到的cookie解析
func (b *BaseAPI) Unpack(cookie string) {
for _, v := range strings.Split(cookie, ";") {
name, val, f := strings.Cut(v, "=")
Expand All @@ -41,7 +41,7 @@ func (b *BaseAPI) Unpack(cookie string) {
}
}
b.Gtk = genderGTK(b.Skey, 5381)
b.Gtk2 = genderGTK(b.Pskey, 5381)
b.Gtk = genderGTK(b.Pskey, 5381)
t, err := strconv.ParseInt(strings.TrimPrefix(b.Uin, "o"), 10, 64)
if err != nil {
log.Fatal(err)
Expand Down
31 changes: 7 additions & 24 deletions api/friend/friend.go → api/friend/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ var (
detailFriendURL = "https://h5.qzone.qq.com/proxy/domain/base.qzone.qq.com/cgi-bin/user/cgi_userinfo_get_all?g_tk=%v"
)

type FriendAPI struct {
type API struct {
*common.BaseAPI
}

// FriendList 好友列表获取 TODO:有时候显示亲密度前200好友
func (f *FriendAPI) List() ([]*FriendInfoEasyResp, error) {
// List 好友列表获取 TODO:有时候显示亲密度前200好友
func (f *API) List() ([]*FriendInfoEasyResp, error) {
if f.Err != nil {
return nil, f.Err
}
url := fmt.Sprintf(friendURL, f.Gtk2) + "&uin=" + strconv.FormatInt(f.Qq, 10)
url := fmt.Sprintf(friendURL, f.Gtk) + "&uin=" + strconv.FormatInt(f.Qq, 10)
log.Printf("请求好友列表URL: %s", url)
var data string
err := requests.
Expand All @@ -42,11 +42,6 @@ func (f *FriendAPI) List() ([]*FriendInfoEasyResp, error) {
ToString(&data).Fetch(context.Background())
log.Printf("原始响应数据: %s", data)

// data, err := DialRequest(NewRequest(WithUrl(url), WithHeader(map[string]string{
// "referer": userQzoneURL,
// "origin": userQzoneURL,
// "cookie": f.Cookie,
// })))
if err != nil {

log.Println("好友列表获取失败:", err)
Expand Down Expand Up @@ -76,34 +71,22 @@ func (f *FriendAPI) List() ([]*FriendInfoEasyResp, error) {
results[index] = fie
index++
}

// groupName := gjson.Get(jsonStr, "gpnames.#.gpname").Array()
// log.Printf("分组数量: %d, 分组名称: %v", len(groupName), groupName)
// for i := 0; i < index; i++ {
// log.Printf("处理好友 %d, groupid: %d", i, results[i].Groupid)
// results[i].GroupName = groupName[results[i].Groupid-1].String()
// }
return results, nil
}

// FriendInfoDetail 好友详细信息获取
func (f *FriendAPI) Detail(uin int64) (*FriendInfoDetailResp, error) {
// Detail 好友详细信息获取
func (f *API) Detail(uin int64) (*FriendInfoDetailResp, error) {
if f.Err != nil {
return nil, f.Err
}
url := fmt.Sprintf(detailFriendURL, f.Gtk2) + "&uin=" + strconv.FormatUint(uint64(uin), 10)
url := fmt.Sprintf(detailFriendURL, f.Gtk) + "&uin=" + strconv.FormatUint(uint64(uin), 10)
var data string
err := requests.
URL(url).
Header("referer", userQzoneURL).
Header("origin", userQzoneURL).
Header("cookie", f.Cookie).
ToString(&data).Fetch(context.Background())
// data, err := DialRequest(NewRequest(WithUrl(url), WithHeader(map[string]string{
// "referer": userQzoneURL,
// "origin": userQzoneURL,
// "cookie": f.Cookie,
// })))
if err != nil {
// er := errors.New("好友详细信息请求错误:" + err.Error())
log.Println("好友详细信息获取失败:", err)
Expand Down
18 changes: 6 additions & 12 deletions api/group/group.go → api/group/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ var (
getQZoneHistory = "https://user.qzone.qq.com/proxy/domain/ic2.qzone.qq.com/cgi-bin/feeds/feeds2_html_pav_all?"
)

type GroupAPI struct {
type API struct {
*common.BaseAPI
}

// QQGroupList 群列表获取
func (g *GroupAPI) List() ([]*QQGroupResp, error) {
func (g *API) List() ([]*QQGroupResp, error) {
if g.Err != nil {
return nil, g.Err
}
Expand All @@ -41,19 +41,13 @@ func (g *GroupAPI) List() ([]*QQGroupResp, error) {
Rd: fmt.Sprintf("%010.8f", rand.Float64()),
Fupdate: "1",
Clean: "1",
GTk: g.Gtk2,
GTk: g.Gtk,
}

var data string
url := getQQGroupURL + common.StructToStr(gr)
err := requests.URL(url).
UserAgent(ua).Header("cookie", g.Cookie).ToString(&data).Fetch(context.Background())
// data, err := DialRequest(NewRequest(WithUrl(url), WithHeader(map[string]string{
// url := getQQGroupURL + structToStr(gr)
// data, err := DialRequest(NewRequest(WithUrl(url), WithHeader(map[string]string{
// "user-agent": ua,
// "cookie": g.cookie,
// })))
if err != nil {
// er := errors.New("QQ群请求错误:" + err.Error())
log.Println("QQ群获取失败:", err)
Expand Down Expand Up @@ -83,8 +77,8 @@ func (g *GroupAPI) List() ([]*QQGroupResp, error) {
return results, nil
}

// QQGroupMemberList 群友(非好友)列表获取
func (g *GroupAPI) MemberList(gid int64) ([]*QQGroupMemberResp, error) {
// MemberList 群友(非好友)列表获取
func (g *API) MemberList(gid int64) ([]*QQGroupMemberResp, error) {
if g.Err != nil {
return nil, g.Err
}
Expand All @@ -93,7 +87,7 @@ func (g *GroupAPI) MemberList(gid int64) ([]*QQGroupMemberResp, error) {
Gid: gid,
Fupdate: "1",
Type: "1",
GTk: g.Gtk2,
GTk: g.Gtk,
}
// url := getQQGroupMemberURL + structToStr(gmr)
var data string
Expand Down
Loading