Skip to content

Commit

Permalink
feat: 新增查询用户信息和用户统计数据(#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultrazg committed Jul 27, 2024
1 parent 93a79a4 commit 5196bec
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 16 deletions.
8 changes: 5 additions & 3 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* [查询单集详情](/episodeDetail)
* [查询节目详情](/podcastDetail)
* [相关节目推荐](/podcastRelated)
* [查询我的信息](/profile)
* [我的贴纸](/sticker)
* [我的贴纸墙](/stickerBoard)
* [查询用户信息](/profile)
* [查询已获得的贴纸](/sticker)
* [查询贴纸墙](/stickerBoard)
* [查询单集播放进度](/episodePlayProgress)
* [查询单集的评论](/commentPrimary)
* [查询回复评论](/commentThread)
Expand All @@ -33,4 +33,6 @@
* [更新收藏单集](/updateEpisodeFavorite)
* [查询收藏单集列表](/episodeFavoriteList)
* [收听历史](/episodePlayedHistoryList)
* [未读消息](/unreadCount)
* [用户统计数据](/userStats)
* [未读消息](/unreadCount)
109 changes: 109 additions & 0 deletions docs/getProfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
### 用户统计数据

根据 uid 查询用户的个人信息

#### 请求地址

> /get_profile
#### 请求方式

> POST
#### 支持格式

> JSON
#### 请求头

| 参数 | 必填 | 类型 | 说明 |
| :------------------ | :--- | :----- | ------------------- |
| x-jike-access-token | true | string | x-jike-access-token |

#### 请求参数

| 参数 | 必填 | 类型 | 说明 |
| :--- | :--- | :----- | -------- |
| uid | true | string | 用户 uid |

#### 返回字段

| 返回字段 | 类型 | 说明 |
| :------------- | :----- | :------------------------------------------------- |
| type | string | 类别。节目、单集等,详情看 type 对应的类别说明文档 |
| uid | string | 用户的 uid |
| avatar | object | 用户的头像信息 |
| nickname | string | 昵称 |
| wechatUserInfo | object | 绑定的微信信息 |
| phoneNumber | object | 绑定的手机号 |
| jikeUserInfo | object | 绑定的即刻 APP 信息 |
| relation | string | 是否关注此用户。值为 **FOLLOWING** 即为 **已关注** |
| ... | ... | ... |


#### 示例

> 地址:https://www.example.com/user_stats
参数

```javascript
{
"uid":"UID"
}
```

响应

```javascript
{
code: 200,
data: {
data: {
authorship: [],
avatar: {
picture: {
format: "jpeg",
height: 132,
largePicUrl:
"https://www.example.com",
middlePicUrl:
"https://www.example.com",
picUrl: "https://www.example.com",
smallPicUrl:
"https://www.example.com",
thumbnailUrl:
"https://www.example.com",
width: 132,
},
},
birthYear: 1998,
certifications: [],
debug: false,
gender: "MALE",
industry: "互联网/IT",
ipLoc: "广东",
isBlockedByViewer: false,
isCancelled: false,
isInvited: true,
isNicknameSet: true,
jikeUserInfo: {
nickname: "JIKE_NICKNAME",
},
nickname: "NICKNAME",
phoneNumber: {
areaCode: "+86",
mobilePhoneNumber: "131****1111",
},
phoneNumberNeeded: false,
readTrackInfo: {},
type: "USER",
uid: "UID",
wechatUserInfo: {
nickName: "WECHAT_NICKNAME",
},
},
},
msg: "OK",
}
```
24 changes: 12 additions & 12 deletions docs/profile.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### 查询我的信息
### 查询登录用户信息

查询已登录账号的个人信息
查询用户个人信息

#### 请求地址

Expand All @@ -26,16 +26,16 @@

#### 返回字段

| 返回字段 | 类型 | 说明 |
| :------------- | :----- | :------------------------------------------------- |
| type | string | 类别。节目、单集等,详情看 type 对应的类别说明文档 |
| uid | string | 当前登录用户的 uid |
| avatar | object | 登录用户的头像信息 |
| nickname | string | 昵称 |
| wechatUserInfo | object | 绑定的微信信息 |
| 返回字段 | 类型 | 说明 |
| :------------- | :----- |:---------------------------------------------|
| type | string | 类别。节目、单集等,详情看 type 对应的类别说明文档 |
| uid | string | 用户的 uid |
| avatar | object | 用户的头像信息 |
| nickname | string | 昵称 |
| wechatUserInfo | object | 绑定的微信信息 |
| phoneNumber | object | 绑定的手机号 |
| jikeUserInfo | object | 绑定的即刻 APP 信息 |
| ... | ... | ... |
| jikeUserInfo | object | 绑定的即刻 APP 信息 |
| ... | ... | ... |


#### 示例
Expand All @@ -48,7 +48,7 @@
{
"data": {
"type": "USER",
"uid": "YOUR-UID",
"uid": "UID",
"avatar": {
"picture": {
"picUrl": "https://www.example.com",
Expand Down
66 changes: 66 additions & 0 deletions docs/userStats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
### 用户统计数据

根据 uid 查询用户的粉丝数、关注数、订阅数和总收听时长

#### 请求地址

> /user_stats
#### 请求方式

> POST
#### 支持格式

> JSON
#### 请求头

| 参数 | 必填 | 类型 | 说明 |
| :------------------ | :--- | :----- | ------------------- |
| x-jike-access-token | true | string | x-jike-access-token |

#### 请求参数

| 参数 | 必填 | 类型 | 说明 |
| :--- | :--- | :----- | -------- |
| uid | true | string | 用户 uid |

#### 返回字段

| 返回字段 | 类型 | 说明 |
| :----------------- | :----- | :--------- |
| followerCount | number | 粉丝数 |
| followingCount | number | 关注数 |
| subscriptionCount | number | 订阅数 |
| totalPlayedSeconds | number | 播放总时长 |


#### 示例

> 地址:https://www.example.com/user_stats
参数

```javascript
{
"uid":"UID"
}
```

响应

```javascript
{
code: 200,
data: {
data: {
followerCount: 0,
followingCount: 1,
subscriptionCount: 5,
totalPlayedSeconds: 505379,
},
},
msg: "OK",
}
```
132 changes: 131 additions & 1 deletion handlers/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"github.com/gin-gonic/gin"
"github.com/ultrazg/xyz/constant"
"github.com/ultrazg/xyz/pkg/utils"
"github.com/ultrazg/xyz/utils"
"log"
"net/http"
"time"
Expand Down Expand Up @@ -54,3 +54,133 @@ var Profile = func(ctx *gin.Context) {

utils.ReturnJson(response, ctx)
}

type UserStatsBody struct {
Uid string `form:"uid"`
}

// GetUserStats 查询用户统计数据(关注数、粉丝数、订阅数和收听时长)
var GetUserStats = func(ctx *gin.Context) {
var params *UserStatsBody

err := ctx.ShouldBind(&params)
if err != nil {
utils.ReturnBadRequest(ctx, err)

return
}

if params.Uid == "" {
utils.ReturnBadRequest(ctx, nil)

return
}

XJikeAccessToken := ctx.Request.Header.Get("x-jike-access-token")
now := time.Now()
isoTime := now.Format("2006-01-02T15:04:05Z07:00")
url := constant.BaseUrl + "/v1/user-stats/get?uid=" + params.Uid
headers := map[string]string{
"Host": "api.xiaoyuzhoufm.com",
"User-Agent": "Xiaoyuzhou/2.57.1 (build:1576; iOS 17.4.1)",
"Market": "AppStore",
"App-BuildNo": "1576",
"OS": "ios",
"x-jike-access-token": XJikeAccessToken,
"x-jike-device-id": "81ADBFD6-6921-482B-9AB9-A29E7CC7BB55",
"Manufacturer": "Apple",
"BundleID": "app.podcast.cosmos",
"Connection": "keep-alive",
"abtest-info": "{\"old_user_discovery_feed\":\"enable\"}",
"Accept-Language": "zh-Hant-HK;q=1.0, zh-Hans-CN;q=0.9",
"Model": "iPhone14,2",
"app-permissions": "4",
"Accept": "*/*",
"App-Version": "2.57.1",
"WifiConnected": "true",
"OS-Version": "17.4.1",
"x-custom-xiaoyuzhou-app-dev": "",
"Local-Time": isoTime,
"Timezone": "Asia/Shanghai",
}

response, code, err := utils.Request(url, http.MethodGet, nil, headers)
if err != nil {
ctx.JSON(code, gin.H{
"code": code,
"msg": utils.GetMsg(code),
"data": err.Error(),
})

log.Println("/v1/user-stats/get?uid="+params.Uid, code, utils.GetMsg(code))

return
}

utils.ReturnJson(response, ctx)
}

type GetProfileByUidBody struct {
Uid string `form:"uid"`
}

// GetProfileByUid 根据 uid 查询用户信息
var GetProfileByUid = func(ctx *gin.Context) {
var params *UserStatsBody

err := ctx.ShouldBind(&params)
if err != nil {
utils.ReturnBadRequest(ctx, err)

return
}

if params.Uid == "" {
utils.ReturnBadRequest(ctx, nil)

return
}

XJikeAccessToken := ctx.Request.Header.Get("x-jike-access-token")
now := time.Now()
isoTime := now.Format("2006-01-02T15:04:05Z07:00")
url := constant.BaseUrl + "/v1/profile/get?uid=" + params.Uid
headers := map[string]string{
"Host": "api.xiaoyuzhoufm.com",
"User-Agent": "Xiaoyuzhou/2.57.1 (build:1576; iOS 17.4.1)",
"Market": "AppStore",
"App-BuildNo": "1576",
"OS": "ios",
"x-jike-access-token": XJikeAccessToken,
"x-jike-device-id": "81ADBFD6-6921-482B-9AB9-A29E7CC7BB55",
"Manufacturer": "Apple",
"BundleID": "app.podcast.cosmos",
"Connection": "keep-alive",
"abtest-info": "{\"old_user_discovery_feed\":\"enable\"}",
"Accept-Language": "zh-Hant-HK;q=1.0, zh-Hans-CN;q=0.9",
"Model": "iPhone14,2",
"app-permissions": "4",
"Accept": "*/*",
"App-Version": "2.57.1",
"WifiConnected": "true",
"OS-Version": "17.4.1",
"x-custom-xiaoyuzhou-app-dev": "",
"Local-Time": isoTime,
"Timezone": "Asia/Shanghai",
}

response, code, err := utils.Request(url, http.MethodGet, nil, headers)
if err != nil {
ctx.JSON(code, gin.H{
"code": code,
"msg": utils.GetMsg(code),
"data": err.Error(),
})

log.Println("/v1/profile/get?uid="+params.Uid, code, utils.GetMsg(code))

return
}

utils.ReturnJson(response, ctx)
}

0 comments on commit 5196bec

Please sign in to comment.