-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
获取自己账号的简单信息。方便使用
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package bilibili | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// AccountInformation 自己账号相关的简单信息 | ||
type AccountInformation struct { | ||
Mid int64 `json:"mid"` //我的mid | ||
Uname string `json:"uname"` //我的昵称 | ||
Userid string `json:"userid"` //我的用户名 | ||
Sign string `json:"sign"` //我的签名 | ||
Birthday string `json:"birthday"` //我的生日 | ||
Sex string `json:"sex"` //我的性别 | ||
NickFree bool `json:"nick_free"` //false:设置过昵称 true:未设置昵称 | ||
Rank string `json:"rank"` //我的会员等级 | ||
} | ||
|
||
func (c *Client) GetAccountInformation() (*AccountInformation, error) { | ||
request := c.resty().R().SetHeader("Content-Type", "application/x-www-form-urlencoded").SetQueryParam("version", "1") | ||
|
||
var accountInfo AccountInformation | ||
|
||
resp, err := request.Get("https://api.bilibili.com/x/member/web/account") | ||
if err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
data, err := getRespData(resp, "获取我的信息") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = json.Unmarshal(data, &accountInfo) | ||
|
||
return &accountInfo, err | ||
} | ||
|
||
// GetAccountInformation 获取我的信息 无参数 | ||
func GetAccountInformation() (*AccountInformation, error) { | ||
return std.GetAccountInformation() | ||
} |