This commit is contained in:
@@ -111,18 +111,19 @@ func (w *MiniUserApi) GetUserInfo(c *gin.Context) {
|
||||
|
||||
// 构造响应数据
|
||||
resp := wechatResponse.MiniUserInfoResponse{
|
||||
ID: user.ID,
|
||||
OpenID: user.OpenID,
|
||||
UnionID: user.UnionID,
|
||||
NickName: user.Nickname,
|
||||
Avatar: user.AvatarURL,
|
||||
Phone: user.Phone,
|
||||
Gender: user.Gender,
|
||||
City: user.City,
|
||||
Province: user.Province,
|
||||
Country: user.Country,
|
||||
CreateTime: user.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: user.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
ID: user.ID,
|
||||
OpenID: user.OpenID,
|
||||
UnionID: user.UnionID,
|
||||
NickName: user.Nickname,
|
||||
Avatar: user.AvatarURL,
|
||||
Phone: user.Phone,
|
||||
Gender: user.Gender,
|
||||
City: user.City,
|
||||
Province: user.Province,
|
||||
Country: user.Country,
|
||||
CreateTime: user.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: user.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
NeedPhoneAuth: user.Phone == nil || *user.Phone == "", // 如果没有手机号则需要授权
|
||||
}
|
||||
|
||||
c.JSON(200, wechatResponse.SuccessResponseWithMsg(resp, "获取成功"))
|
||||
|
||||
@@ -135,18 +135,19 @@ type MiniLoginResponse struct {
|
||||
|
||||
// MiniUserInfoResponse 小程序用户信息响应
|
||||
type MiniUserInfoResponse struct {
|
||||
ID uint `json:"id"` // 用户ID
|
||||
OpenID string `json:"openid"` // 用户openid
|
||||
UnionID *string `json:"unionid"` // 用户unionid
|
||||
NickName *string `json:"nickName"` // 用户昵称
|
||||
Avatar *string `json:"avatar"` // 用户头像
|
||||
Phone *string `json:"phone"` // 用户手机号
|
||||
Gender *int `json:"gender"` // 性别:0-未知,1-男,2-女
|
||||
City *string `json:"city"` // 城市
|
||||
Province *string `json:"province"` // 省份
|
||||
Country *string `json:"country"` // 国家
|
||||
CreateTime string `json:"createTime"` // 创建时间
|
||||
UpdateTime string `json:"updateTime"` // 更新时间
|
||||
ID uint `json:"id"` // 用户ID
|
||||
OpenID string `json:"openid"` // 用户openid
|
||||
UnionID *string `json:"unionid"` // 用户unionid
|
||||
NickName *string `json:"nickName"` // 用户昵称
|
||||
Avatar *string `json:"avatar"` // 用户头像
|
||||
Phone *string `json:"phone"` // 用户手机号
|
||||
Gender *int `json:"gender"` // 性别:0-未知,1-男,2-女
|
||||
City *string `json:"city"` // 城市
|
||||
Province *string `json:"province"` // 省份
|
||||
Country *string `json:"country"` // 国家
|
||||
CreateTime string `json:"createTime"` // 创建时间
|
||||
UpdateTime string `json:"updateTime"` // 更新时间
|
||||
NeedPhoneAuth bool `json:"needPhoneAuth"` // 是否需要授权手机号
|
||||
}
|
||||
|
||||
// PhoneUpdateResponse 手机号更新响应
|
||||
|
||||
@@ -56,9 +56,13 @@ func (w *MiniService) Code2Session(code string) (*model.MiniUser, error) {
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// 创建新用户
|
||||
// 生成默认昵称:萌宠爱 + OpenID的前6位
|
||||
defaultNickname := "萌宠爱" + session.OpenID[:6]
|
||||
|
||||
user = model.MiniUser{
|
||||
OpenID: session.OpenID,
|
||||
SessionKey: &session.SessionKey,
|
||||
Nickname: &defaultNickname,
|
||||
}
|
||||
if session.UnionID != "" {
|
||||
user.UnionID = &session.UnionID
|
||||
|
||||
Reference in New Issue
Block a user