-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
d35e93c
commit 56f9090
Showing
2 changed files
with
107 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,78 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/XiaoMengXinX/Music163Api-Go/types" | ||
"github.com/XiaoMengXinX/Music163Api-Go/utils" | ||
) | ||
|
||
// UserStatusDetailAPI 获取用户状态详情 | ||
const UserStatusDetailAPI = "/api/social/user/status/detail" | ||
|
||
// UserStatusEditAPI 编辑用户状态 | ||
const UserStatusEditAPI = "/api/social/user/status/edit" | ||
|
||
// UserStatusDetailReqJson 获取用户状态详情参数 | ||
type UserStatusDetailReqJson struct { | ||
VisitorId int `json:"visitorId"` | ||
} | ||
|
||
// UserStatusEditReqJson 编辑用户状态参数 | ||
type UserStatusEditReqJson struct { | ||
Content string `json:"content"` | ||
} | ||
|
||
type userStatusContent struct { | ||
Type string `json:"type"` | ||
Content string `json:"content"` | ||
} | ||
|
||
// CreateUserStatusDetailReqJson 创建请求 json | ||
func CreateUserStatusDetailReqJson(visitorId int) string { | ||
reqBodyJson, _ := json.Marshal(UserStatusDetailReqJson{ | ||
VisitorId: visitorId, | ||
}) | ||
return string(reqBodyJson) | ||
} | ||
|
||
// CreateUserStatusEditReqJson 创建请求 json | ||
func CreateUserStatusEditReqJson(context string) string { | ||
s, _ := json.Marshal(userStatusContent{ | ||
Type: "TEXT", | ||
Content: context, | ||
}) | ||
reqBodyJson, _ := json.Marshal(UserStatusEditReqJson{ | ||
Content: string(s), | ||
}) | ||
return string(reqBodyJson) | ||
} | ||
|
||
// GetUserStatus 获取用户状态 | ||
func GetUserStatus(data utils.RequestData, userID int) (result types.UserStatusDetailData, err error) { | ||
var options utils.EapiOption | ||
options.Path = UserStatusDetailAPI | ||
options.Url = "https://music.163.com/eapi/social/user/status/detail" | ||
options.Json = CreateUserStatusDetailReqJson(userID) | ||
resBody, _, err := utils.ApiRequest(options, data) | ||
if err != nil { | ||
return result, err | ||
} | ||
err = json.Unmarshal([]byte(resBody), &result) | ||
result.RawJson = resBody | ||
return result, err | ||
} | ||
|
||
// SetUserStatus 设置用户状态 | ||
func SetUserStatus(data utils.RequestData, ctx string) (result types.UserStatusDetailData, err error) { | ||
var options utils.EapiOption | ||
options.Path = UserStatusEditAPI | ||
options.Url = "https://music.163.com/eapi/social/user/status/edit" | ||
options.Json = CreateUserStatusEditReqJson(ctx) | ||
resBody, _, err := utils.ApiRequest(options, data) | ||
if err != nil { | ||
return result, err | ||
} | ||
err = json.Unmarshal([]byte(resBody), &result) | ||
result.RawJson = resBody | ||
return result, err | ||
} |
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,29 @@ | ||
package types | ||
|
||
// UserStatusDetailData 用户状态详情数据 | ||
type UserStatusDetailData struct { | ||
RawJson string | ||
Code int `json:"code"` | ||
Data struct { | ||
Id int `json:"id"` | ||
UserId int `json:"userId"` | ||
Avatar string `json:"avatar"` | ||
UserName string `json:"userName"` | ||
Song interface{} `json:"song"` | ||
Content struct { | ||
Type string `json:"type"` | ||
IconUrl string `json:"iconUrl"` | ||
Content string `json:"content"` | ||
ActionUrl interface{} `json:"actionUrl"` | ||
} `json:"content"` | ||
ExtInfo interface{} `json:"extInfo"` | ||
} `json:"data"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// UserStatusSetData 用户状态设置数据 | ||
type UserStatusSetData struct { | ||
Code int `json:"code"` | ||
Data string `json:"data"` | ||
Message string `json:"message"` | ||
} |