feat 微信登录
This commit is contained in:
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.23.1
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
bou.ke/monkey v1.0.2
|
bou.ke/monkey v1.0.2
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260113014617-7812a3c669d7
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260113095415-34b2e45e3d50
|
||||||
github.com/alicebob/miniredis/v2 v2.35.0
|
github.com/alicebob/miniredis/v2 v2.35.0
|
||||||
github.com/gin-contrib/cors v1.7.6
|
github.com/gin-contrib/cors v1.7.6
|
||||||
github.com/gin-gonic/gin v1.11.0
|
github.com/gin-gonic/gin v1.11.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -2,8 +2,8 @@ bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI=
|
|||||||
bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA=
|
bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA=
|
||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260113014617-7812a3c669d7 h1:sNZWEsAy4G5HEigdnnIHQ4eqmifN3rDPPApeTG4c4h4=
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260113095415-34b2e45e3d50 h1:T0JZl2N+HMYRgyifEGFXD2y1MZOuoAS1xjnIg/JLGwM=
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260113014617-7812a3c669d7/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc=
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260113095415-34b2e45e3d50/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc=
|
||||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
|
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ import (
|
|||||||
// 这个模块处理用户登录
|
// 这个模块处理用户登录
|
||||||
|
|
||||||
type LoginReq struct {
|
type LoginReq struct {
|
||||||
Phone string `json:"phone" binding:"required,min=1"`
|
Phone string `json:"phone"` // 手机号
|
||||||
Code string `json:"code" binding:"required,min=1"`
|
Code string `json:"code"` // 验证码
|
||||||
|
WxMiniCode string `json:"wxMiniCode"` // 微信小程序登录
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginResp struct {
|
type LoginResp struct {
|
||||||
@@ -41,20 +42,39 @@ func Login(c *gin.Context) {
|
|||||||
http_resp.JsonOK(c, http_resp.Error(http_resp.Failed))
|
http_resp.JsonOK(c, http_resp.Error(http_resp.Failed))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
login, err := client.Login(c, &grpc_pb.LoginReq{
|
|
||||||
Phone: req.Phone,
|
usn, name := "", ""
|
||||||
Code: req.Code,
|
if req.Phone != "" {
|
||||||
})
|
// TODO 校验验证码
|
||||||
if err != nil {
|
login, err := client.PhoneLogin(c, &grpc_pb.PhoneLoginReq{
|
||||||
log.Errorf("Login Login error: %v", err)
|
Phone: req.Phone,
|
||||||
http_resp.JsonOK(c, http_resp.Error(http_resp.Failed))
|
Code: req.Code,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Login PhoneLogin error: %v", err)
|
||||||
|
http_resp.JsonOK(c, http_resp.Error(http_resp.Failed))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
usn, name = login.USN, login.Name
|
||||||
|
} else if req.WxMiniCode != "" {
|
||||||
|
login, err := client.WxMiniLogin(c, &grpc_pb.WxMiniLoginReq{
|
||||||
|
Code: req.WxMiniCode,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Login WxMiniLogin error: %v", err)
|
||||||
|
http_resp.JsonOK(c, http_resp.Error(http_resp.Failed))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
usn, name = login.USN, login.Name
|
||||||
|
} else {
|
||||||
|
http_resp.JsonBadRequest(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
at, rt, err := genToken(c, login.USN)
|
at, rt, err := genToken(c, usn)
|
||||||
http_resp.JsonOK(c, http_resp.Success(&LoginResp{
|
http_resp.JsonOK(c, http_resp.Success(&LoginResp{
|
||||||
USN: login.USN,
|
USN: usn,
|
||||||
Name: login.Name,
|
Name: name,
|
||||||
AccessToken: at,
|
AccessToken: at,
|
||||||
RefreshToken: rt,
|
RefreshToken: rt,
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user