Skip to content

Commit

Permalink
k
Browse files Browse the repository at this point in the history
  • Loading branch information
kslamp committed Nov 19, 2024
1 parent 117a0cf commit df23bbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
27 changes: 18 additions & 9 deletions wxlogin/wx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,31 @@ func (c *MemberCli) Cr(ctx context.Context) {
}
*/

// LoginOrCr 根据微信openid查询用户信息,如果用户不存在则创建新用户
//
// @param ctx
// @param wxOpenID
// @return *Member
// @return error
func (c *MemberCli) LoginOrCr(ctx context.Context, wxOpenID string) (*Member, error) {
// 根据微信openid查询用户信息
req, err := low.QueryWxMember(ctx, c.client, data.OpenIDReq{WxOpenID: wxOpenID})
if err != nil {
return nil, err
m := req.GetQueryWxMember()

}
found := true
if found {
m := req.GetQueryWxMember()
if err == nil && m == (data.MemberResp{}) {
// 创建用户
r, err := low.CreateWxMember(ctx, c.client, data.CreateWxMemberReq{Code: "xx", WxOpenID: wxOpenID})
if err != nil {
return nil, err
}
m = r.GetCreateWxMember()
return &Member{Code: m.Code, WxOpenID: m.WxOpenID}, nil
}
r, err := low.CreateWxMember(ctx, c.client, data.CreateWxMemberReq{Code: "xx", WxOpenID: wxOpenID})

// 查询出错
if err != nil {
return nil, err

}
m := r.GetCreateWxMember()

return &Member{Code: m.Code, WxOpenID: m.WxOpenID}, nil
}
1 change: 1 addition & 0 deletions wxlogin/wx/wx.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (c *WxCli) AuthUser(ctx context.Context, jsCode string) (*Codes, error) {
return &Codes{OpenID: resp.AuthUser.OpenID, Unionid: resp.AuthUser.UnionID}, nil
}

// Deprecated: use AuthUser instead
func (c *WxCli) AuthUser2(ctx context.Context, jsCode string) error {
_, err := low.AuthUser(ctx, c.client, data.JsCodeReq{JsCode: jsCode})
if err != nil {
Expand Down

0 comments on commit df23bbf

Please sign in to comment.