Skip to content

Commit

Permalink
新增分享歌曲API、分享资源API
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoMengXinX committed Jul 17, 2022
1 parent 5a6579d commit 8901f2f
Show file tree
Hide file tree
Showing 40 changed files with 265 additions and 71 deletions.
52 changes: 52 additions & 0 deletions api/resourceShare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package api

import (
"encoding/json"

"github.com/XiaoMengXinX/Music163Api-Go/types"
"github.com/XiaoMengXinX/Music163Api-Go/utils"
)

// ResourceShareAPI 分享资源 API
const ResourceShareAPI = "/api/share/friends/resource"

// resourceShareReq resourceShare API 的 body json
type resourceShareReq struct {
ResourceID int `json:"id"`
ResourceType string `json:"type"`
Msg string `json:"msg"`
}

// CreateResourceShareReqJson 创建 分享资源 请求json
func CreateResourceShareReqJson(resourceID int, resourceType string, msg string) string {
if resourceType == "" {
resourceType = "song"
}
reqBody := resourceShareReq{
ResourceID: resourceID,
ResourceType: resourceType,
Msg: msg,
}
reqBodyJson, _ := json.Marshal(reqBody)
return string(reqBodyJson)
}

// ShareResource 分享资源
// 参数说明:
// ResourceID: 资源ID(歌曲,歌单,mv,电台,电台节目对应 id)
// ResourceType: 资源类型,默认歌曲 song,可传 song,playlist,mv,djradio,djprogram
// Msg: 内容,140 字限制,支持 emoji,@用户名
func ShareResource(data utils.RequestData, resourceID int, resourceType string, msg string) (result types.SendEventData, err error) {
var options utils.EapiOption
options.Path = ResourceShareAPI
options.Url = "https://music.163.com/eapi/share/friends/resource"
reqBodyJson := CreateResourceShareReqJson(resourceID, resourceType, msg)
options.Json = reqBodyJson
resBody, _, err := utils.ApiRequest(options, data)
if err != nil {
return result, err
}
err = json.Unmarshal([]byte(resBody), &result)
result.RawJson = resBody
return result, err
}
41 changes: 41 additions & 0 deletions api/songShare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package api

import (
"encoding/json"

"github.com/XiaoMengXinX/Music163Api-Go/types"
"github.com/XiaoMengXinX/Music163Api-Go/utils"
)

// SongShareAPI 分享歌曲 API
const SongShareAPI = "/api/music/songshare/share/property"

// songShareReq SongShare API 的 body json
type songShareReq struct {
SongId int `json:"songId"`
}

// CreateSongShareReqJson 创建 分享歌曲 请求json
func CreateSongShareReqJson(musicID int) string {
reqBody := songShareReq{
SongId: musicID,
}
reqBodyJson, _ := json.Marshal(reqBody)
return string(reqBodyJson)
}

// SongShare 分享歌曲,用于音乐人任务
func SongShare(data utils.RequestData, musicID int) (result types.SongShareData, err error) {
var options utils.EapiOption
options.Path = SongShareAPI
options.Url = "https://music.163.com/eapi/song/share"
reqBodyJson := CreateSongShareReqJson(musicID)
options.Json = reqBodyJson
resBody, _, err := utils.ApiRequest(options, data)
if err != nil {
return result, err
}
err = json.Unmarshal([]byte(resBody), &result)
result.RawJson = resBody
return result, err
}
4 changes: 2 additions & 2 deletions types/Comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package types

// AddCommentData 新增评论返回数据
type AddCommentData struct {
RawJson string
Code int `json:"code"`
RawJson string `json:"-"`
Code int `json:"code"`
MusicianSaidTips struct {
Toast string `json:"toast"`
InviteTitle string `json:"inviteTitle"`
Expand Down
4 changes: 2 additions & 2 deletions types/Search.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

// SearchSuggestData 搜索建议数据
type SearchSuggestData struct {
RawJson string
RawJson string `json:"-"`
Result struct {
AllMatch []struct {
Keyword string `json:"keyword"`
Expand All @@ -17,7 +17,7 @@ type SearchSuggestData struct {

// SearchMultiMatchData 搜索多重匹配返回数据
type SearchMultiMatchData struct {
RawJson string
RawJson string `json:"-"`
Result struct {
Artist []struct {
Name string `json:"name"`
Expand Down
6 changes: 3 additions & 3 deletions types/Upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

// UploadFileData 上传文件返回数据
type UploadFileData struct {
RawJson string
RawJson string `json:"-"`
RequestId string `json:"requestId"`
Offset int `json:"offset"`
Context string `json:"context"`
Expand All @@ -13,14 +13,14 @@ type UploadFileData struct {

// UploadNodeData 上传加速节点地址
type UploadNodeData struct {
RawJson string
RawJson string `json:"-"`
Lbs string `json:"lbs"`
Upload []string `json:"upload"`
}

// UploadEventImgData 用于发送动态的图片信息
type UploadEventImgData struct {
RawJson string
RawJson string `json:"-"`
PicSubtype string
PicInfo struct {
OriginId int `json:"originId"`
Expand Down
4 changes: 2 additions & 2 deletions types/artistDetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package types

// ArtistDetailData 获取歌手详细API返回数据
type ArtistDetailData struct {
RawJson string
Code int `json:"code"`
RawJson string `json:"-"`
Code int `json:"code"`
Data struct {
Cursor string `json:"cursor"`
Blocks []struct {
Expand Down
2 changes: 1 addition & 1 deletion types/circleGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

// GetCircleData 获取云圈动态API返回数据
type GetCircleData struct {
RawJson string
RawJson string `json:"-"`
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Expand Down
2 changes: 1 addition & 1 deletion types/cloudbeanNum.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

// CloudBeanNumData 音乐人云豆数量
type CloudBeanNumData struct {
RawJson string
RawJson string `json:"-"`
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Expand Down
2 changes: 1 addition & 1 deletion types/eventDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

// DelEventData 删除动态 API 返回数据
type DelEventData struct {
RawJson string
RawJson string `json:"-"`
Message string `json:"message"`
Msg string `json:"msg"`
Code int `json:"code"`
Expand Down
107 changes: 94 additions & 13 deletions types/eventSend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package types

// SendEventData 发送动态 API 的返回数据
type SendEventData struct {
RawJson string
RawJson string `json:"-"`
Code int `json:"code"`
Message string `json:"message"`
UserId int `json:"userId"`
Id int `json:"id"`
Id int64 `json:"id"`
Event struct {
DiscussId string `json:"discussId"`
ActName interface{} `json:"actName"`
PendantData interface{} `json:"pendantData"`
ForwardCount int `json:"forwardCount"`
LotteryEventData interface{} `json:"lotteryEventData"`
Json string `json:"json"`
TitleAlias interface{} `json:"titleAlias"`
User struct {
DefaultAvatar bool `json:"defaultAvatar"`
Province int `json:"province"`
Expand All @@ -22,15 +24,15 @@ type SendEventData struct {
AccountStatus int `json:"accountStatus"`
Gender int `json:"gender"`
City int `json:"city"`
Birthday int `json:"birthday"`
Birthday int64 `json:"birthday"`
UserId int `json:"userId"`
UserType int `json:"userType"`
Nickname string `json:"nickname"`
Signature string `json:"signature"`
Description string `json:"description"`
DetailDescription string `json:"detailDescription"`
AvatarImgId int `json:"avatarImgId"`
BackgroundImgId int `json:"backgroundImgId"`
AvatarImgId int64 `json:"avatarImgId"`
BackgroundImgId int64 `json:"backgroundImgId"`
BackgroundUrl string `json:"backgroundUrl"`
Authority int `json:"authority"`
Mutual bool `json:"mutual"`
Expand All @@ -50,13 +52,18 @@ type SendEventData struct {
IdentityLevel int `json:"identityLevel"`
IdentityIconUrl string `json:"identityIconUrl"`
} `json:"avatarDetail"`
CommonIdentity interface{} `json:"commonIdentity"`
CommonIdentity interface{} `json:"commonIdentity"`
RelationTag interface{} `json:"relationTag"`
AuthenticationTypes int `json:"authenticationTypes"`
} `json:"user"`
Uuid string `json:"uuid"`
ExpireTime int `json:"expireTime"`
RcmdInfo interface{} `json:"rcmdInfo"`
EventTime int `json:"eventTime"`
ActId int `json:"actId"`
ThreadId string `json:"threadId"`
ExtType string `json:"extType"`
ExtSource interface{} `json:"extSource"`
Pics []struct {
OriginUrl string `json:"originUrl"`
SquareUrl string `json:"squareUrl"`
Expand Down Expand Up @@ -109,32 +116,106 @@ type SendEventData struct {
Liked bool `json:"liked"`
Comments []interface{} `json:"comments"`
ResourceType int `json:"resourceType"`
ResourceId int `json:"resourceId"`
ResourceId int64 `json:"resourceId"`
ThreadId string `json:"threadId"`
ShareCount int `json:"shareCount"`
CommentCount int `json:"commentCount"`
LikedCount int `json:"likedCount"`
} `json:"info"`
TailMark interface{} `json:"tailMark"`
ExtJsonInfo struct {
TailMark struct {
MarkTitle string `json:"markTitle"`
MarkType string `json:"markType"`
MarkResourceId string `json:"markResourceId"`
MarkOrpheusUrl string `json:"markOrpheusUrl"`
ExtInfo interface{} `json:"extInfo"`
Circle struct {
ImageUrl string `json:"imageUrl"`
PostCount string `json:"postCount"`
Member string `json:"member"`
} `json:"circle"`
} `json:"tailMark"`
TypeDesc interface{} `json:"typeDesc"`
AlterLinkUrl interface{} `json:"alterLinkUrl"`
AlterLinkWebviewUrl interface{} `json:"alterLinkWebviewUrl"`
ExtJsonInfo struct {
ActId int `json:"actId"`
ActIds []interface{} `json:"actIds"`
Uuid string `json:"uuid"`
ExtType string `json:"extType"`
ExtSource interface{} `json:"extSource"`
ExtId string `json:"extId"`
CircleId interface{} `json:"circleId"`
CirclePubType interface{} `json:"circlePubType"`
TailMark interface{} `json:"tailMark"`
TypeDesc interface{} `json:"typeDesc"`
PrivacySetting int `json:"privacySetting"`
QuestionId interface{} `json:"questionId"`
ExtParams struct {
} `json:"extParams"`
VoiceInfo interface{} `json:"voiceInfo"`
PointTopicInfo struct {
Id interface{} `json:"id"`
Type interface{} `json:"type"`
SubType interface{} `json:"subType"`
Name interface{} `json:"name"`
Icon interface{} `json:"icon"`
Desc interface{} `json:"desc"`
Target interface{} `json:"target"`
ThroughInfo interface{} `json:"throughInfo"`
Ext interface{} `json:"ext"`
Parent interface{} `json:"parent"`
} `json:"pointTopicInfo"`
ActivityInfos interface{} `json:"activityInfos"`
AnonymityInfo struct {
Anonymous int `json:"anonymous"`
Name interface{} `json:"name"`
AvatarUrl interface{} `json:"avatarUrl"`
Me interface{} `json:"me"`
} `json:"anonymityInfo"`
TitleAlias interface{} `json:"titleAlias"`
} `json:"extJsonInfo"`
PrivacySetting int `json:"privacySetting"`
ExtPageParam interface{} `json:"extPageParam"`
LogInfo interface{} `json:"logInfo"`
PrivacySetting int `json:"privacySetting"`
ExtPageParam interface{} `json:"extPageParam"`
LogInfo interface{} `json:"logInfo"`
BottomActivityInfos []struct {
Id string `json:"id"`
Type int `json:"type"`
SubType interface{} `json:"subType"`
Name string `json:"name"`
Icon interface{} `json:"icon"`
Desc interface{} `json:"desc"`
Target string `json:"target"`
ThroughInfo interface{} `json:"throughInfo"`
Ext interface{} `json:"ext"`
Parent interface{} `json:"parent"`
} `json:"bottomActivityInfos"`
PointTopicInfo struct {
Id interface{} `json:"id"`
Type interface{} `json:"type"`
SubType interface{} `json:"subType"`
Name interface{} `json:"name"`
Icon interface{} `json:"icon"`
Desc interface{} `json:"desc"`
Target interface{} `json:"target"`
ThroughInfo interface{} `json:"throughInfo"`
Ext interface{} `json:"ext"`
Parent interface{} `json:"parent"`
} `json:"pointTopicInfo"`
Voice interface{} `json:"voice"`
TimingInfo interface{} `json:"timingInfo"`
EventActionToast interface{} `json:"eventActionToast"`
RelationTopic interface{} `json:"relationTopic"`
AnonymityInfo struct {
Anonymous int `json:"anonymous"`
Name interface{} `json:"name"`
AvatarUrl interface{} `json:"avatarUrl"`
Me int `json:"me"`
} `json:"anonymityInfo"`
Ctrp interface{} `json:"ctrp"`
} `json:"event"`
Sns struct {
} `json:"sns"`
ResUrl string `json:"resUrl"`
ResUrl string `json:"resUrl"`
AfterAction interface{} `json:"afterAction"`
JustReturn bool `json:"justReturn"`
}
4 changes: 2 additions & 2 deletions types/loginStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package types

// LoginStatusData 登录状态数据'
type LoginStatusData struct {
RawJson string
Code int `json:"code"`
RawJson string `json:"-"`
Code int `json:"code"`
Account struct {
Id int `json:"id"`
UserName string `json:"userName"`
Expand Down
2 changes: 1 addition & 1 deletion types/mlogSend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

// SendMlogData 发送 Mlog 返回数据
type SendMlogData struct {
RawJson string
RawJson string `json:"-"`
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Expand Down
4 changes: 2 additions & 2 deletions types/msgSend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package types

// SendMsgData 发送私信 API 的返回数据
type SendMsgData struct {
RawJson string
Code int `json:"code"`
RawJson string `json:"-"`
Code int `json:"code"`
NewMsgs []struct {
FromUser struct {
Description string `json:"description"`
Expand Down
Loading

0 comments on commit 8901f2f

Please sign in to comment.