此前“查询设备号”功能的 SDK(GetUserDeviceParam / Request / Response + client.GetUserDevice 方法)仅手工存在于 center-api 的 vendor 中,未合入 golib, 导致每次 go mod vendor 都会被冲掉。此处正式补入 golib,与 vendor 内容保持一致。
97 lines
3.2 KiB
Go
97 lines
3.2 KiB
Go
package big_data
|
||
|
||
import (
|
||
"bytes"
|
||
"encoding/json"
|
||
"io"
|
||
"strings"
|
||
|
||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||
)
|
||
|
||
// GetUserDeviceParam 用户设备号查询参数(全部为数组,空数组表示不限定该条件)
|
||
type GetUserDeviceParam struct {
|
||
Uid []string `json:"uid"`
|
||
DeviceId []string `json:"device_id"`
|
||
Ip []string `json:"ip"`
|
||
LoginDate []string `json:"login_date"` // 登录日期区间 [开始, 结束]
|
||
Page int `json:"page"`
|
||
PageSize int `json:"page_size"`
|
||
XDebug string `json:"x_debug"` // 测试环境调试头,正式调用可留空
|
||
}
|
||
|
||
// GetUserDeviceRequest 用户设备号查询请求
|
||
type GetUserDeviceRequest struct {
|
||
*requests.JsonRequest
|
||
Uid []string `position:"Json" field:"uid"`
|
||
DeviceId []string `position:"Json" field:"device_id"`
|
||
Ip []string `position:"Json" field:"ip"`
|
||
LoginDate []string `position:"Json" field:"login_date"`
|
||
Page int `position:"Json" field:"page"`
|
||
PageSize int `position:"Json" field:"page_size"`
|
||
Authorization string `position:"Header" field:"Authorization"`
|
||
XDebug string `position:"Header" field:"x-debug"`
|
||
}
|
||
|
||
// getUserDeviceBody 自定义请求体序列化:切片统一为非 nil 空数组 [],避免 nil→null 触发 DMS 类型校验失败
|
||
type getUserDeviceBody struct {
|
||
Uid []string `json:"uid"`
|
||
DeviceId []string `json:"device_id"`
|
||
Ip []string `json:"ip"`
|
||
LoginDate []string `json:"login_date"`
|
||
Page int `json:"page"`
|
||
PageSize int `json:"page_size"`
|
||
}
|
||
|
||
// GetBodyReader 覆盖 JsonRequest 默认实现,使用自定义结构序列化 body
|
||
func (request *GetUserDeviceRequest) GetBodyReader() io.Reader {
|
||
body := getUserDeviceBody{
|
||
Uid: emptyStrSlice(request.Uid),
|
||
DeviceId: emptyStrSlice(request.DeviceId),
|
||
Ip: emptyStrSlice(request.Ip),
|
||
LoginDate: emptyStrSlice(request.LoginDate),
|
||
Page: request.Page,
|
||
PageSize: request.PageSize,
|
||
}
|
||
b, err := json.Marshal(body)
|
||
if err != nil {
|
||
return strings.NewReader("")
|
||
}
|
||
return bytes.NewReader(b)
|
||
}
|
||
|
||
// GetUserDeviceResponse 用户设备号查询响应(data 原样透出)
|
||
type GetUserDeviceResponse struct {
|
||
*responses.BaseResponse
|
||
Code int `json:"code"`
|
||
Message string `json:"message"`
|
||
Data json.RawMessage `json:"data"`
|
||
}
|
||
|
||
// CreateGetUserDeviceRequest 创建用户设备号查询请求
|
||
func CreateGetUserDeviceRequest(token string, param GetUserDeviceParam) *GetUserDeviceRequest {
|
||
req := &GetUserDeviceRequest{
|
||
JsonRequest: &requests.JsonRequest{},
|
||
Uid: param.Uid,
|
||
DeviceId: param.DeviceId,
|
||
Ip: param.Ip,
|
||
LoginDate: param.LoginDate,
|
||
Page: param.Page,
|
||
PageSize: param.PageSize,
|
||
Authorization: token,
|
||
XDebug: param.XDebug,
|
||
}
|
||
req.InitWithApiInfo(HOST, VERSION, "/api/internal/v1/get_user_device")
|
||
req.Method = requests.POST
|
||
req.Scheme = requests.HTTPS
|
||
return req
|
||
}
|
||
|
||
// CreateGetUserDeviceResponse 创建用户设备号查询响应
|
||
func CreateGetUserDeviceResponse() *GetUserDeviceResponse {
|
||
return &GetUserDeviceResponse{
|
||
BaseResponse: &responses.BaseResponse{},
|
||
}
|
||
}
|