支持登录类型wxnative
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
AuthTypeWeixin = "wxqrcode" // 微信扫码
|
AuthTypeWeixin = "wxqrcode" // 微信扫码
|
||||||
AuthTypeMP = "weixinsns" // 公众号
|
AuthTypeMP = "weixinsns" // 公众号
|
||||||
AuthTypeMini = "weixinmini" // 小程序
|
AuthTypeWXNative = "wxnative" // 微信APP
|
||||||
)
|
)
|
||||||
|
|
||||||
type Auther struct {
|
type Auther struct {
|
||||||
@@ -25,6 +25,7 @@ type Auther struct {
|
|||||||
var (
|
var (
|
||||||
AutherObjWX *Auther
|
AutherObjWX *Auther
|
||||||
AutherObjMP *Auther
|
AutherObjMP *Auther
|
||||||
|
AutherObjNative *Auther
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -41,16 +42,36 @@ func init() {
|
|||||||
authType: AuthTypeMP,
|
authType: AuthTypeMP,
|
||||||
}
|
}
|
||||||
auth2.RegisterAuther(AuthTypeMP, AutherObjMP)
|
auth2.RegisterAuther(AuthTypeMP, AutherObjMP)
|
||||||
|
|
||||||
|
AutherObjNative = &Auther{
|
||||||
|
authType: AuthTypeWXNative,
|
||||||
|
}
|
||||||
|
auth2.RegisterAuther(AuthTypeWXNative, AutherObjNative)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Auther) VerifySecret(state, code string) (authBindEx *auth2.AuthBindEx, err error) {
|
func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||||
globals.SugarLogger.Debugf("weixin VerifySecret code:%s", code)
|
globals.SugarLogger.Debugf("weixin VerifySecret id:%s secret:%s", secret, secret)
|
||||||
|
var openID, accessToken string
|
||||||
|
if a.authType != AuthTypeWXNative {
|
||||||
|
state := id
|
||||||
|
code := secret
|
||||||
if state == "" {
|
if state == "" {
|
||||||
token, err2 := a.getAPI().SNSRetrieveToken(code)
|
token, err2 := a.getAPI().SNSRetrieveToken(code)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
wxUserinfo, err2 := a.getAPI().SNSGetUserInfo(token.AccessToken, token.OpenID)
|
openID = token.OpenID
|
||||||
|
accessToken = token.AccessToken
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = ErrStateIsWrong
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
openID = id
|
||||||
|
accessToken = secret
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
wxUserinfo, err2 := a.getAPI().SNSGetUserInfo(accessToken, openID)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
if authBindEx, err = a.UnionFindAuthBind(a.authType, []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
|
if authBindEx, err = a.UnionFindAuthBind(a.authType, []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
|
||||||
authBindEx.UserHint = &auth2.UserBasic{
|
authBindEx.UserHint = &auth2.UserBasic{
|
||||||
Name: wxUserinfo.NickName,
|
Name: wxUserinfo.NickName,
|
||||||
Avatar: wxUserinfo.HeadImgURL,
|
Avatar: wxUserinfo.HeadImgURL,
|
||||||
@@ -58,9 +79,6 @@ func (a *Auther) VerifySecret(state, code string) (authBindEx *auth2.AuthBindEx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
err = ErrStateIsWrong
|
|
||||||
}
|
|
||||||
return authBindEx, err
|
return authBindEx, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AuthTypeMini = "weixinmini" // 小程序
|
||||||
|
)
|
||||||
|
|
||||||
type MiniAuther struct {
|
type MiniAuther struct {
|
||||||
authprovider.DefAuther
|
authprovider.DefAuther
|
||||||
}
|
}
|
||||||
@@ -37,7 +41,7 @@ func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBindEx *auth2.AuthB
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
sessionKey := sessionInfo.SessionKey
|
sessionKey := sessionInfo.SessionKey
|
||||||
sessionInfo.SessionKey = ""
|
sessionInfo.SessionKey = ""
|
||||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeMini, []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini}, sessionInfo.OpenID, sessionInfo.UnionID, sessionInfo); err == nil {
|
if authBindEx, err = a.UnionFindAuthBind(AuthTypeMini, []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative}, sessionInfo.OpenID, sessionInfo.UnionID, sessionInfo); err == nil {
|
||||||
authBindEx.UserData = sessionKey
|
authBindEx.UserData = sessionKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func (c *Auth2Controller) SendVerifyCode() {
|
|||||||
|
|
||||||
// @Title 登录接口
|
// @Title 登录接口
|
||||||
// @Description 登录接口(微信与公众号登录不能直接调用此接口)
|
// @Description 登录接口(微信与公众号登录不能直接调用此接口)
|
||||||
// @Param authType formData string true "登录类型,当前支持[localpass:本地账号密码,mobile:手机短信,wxqrcode:微信登录,weixinsns:微信公众号,weixinmini;小程序,ddstaff:钉钉企业,ddqrcode:钉钉扫码,alipaycode:支付宝小程序]"
|
// @Param authType formData string true "登录类型,当前支持[localpass:本地账号密码,mobile:手机短信,wxqrcode:微信登录,weixinsns:微信公众号,weixinmini;小程序,wxnative:微信APP,ddstaff:钉钉企业,ddqrcode:钉钉扫码,alipaycode:支付宝小程序]"
|
||||||
// @Param authSecret formData string true "不同登录类型的登录秘密,如果是localpass登录类型,是md5后的值(空串不要md5)"
|
// @Param authSecret formData string true "不同登录类型的登录秘密,如果是localpass登录类型,是md5后的值(空串不要md5)"
|
||||||
// @Param authID formData string false "登录ID,登录类型为localpass时依赖于authIDType,其它为相应登录类型的id"
|
// @Param authID formData string false "登录ID,登录类型为localpass时依赖于authIDType,其它为相应登录类型的id"
|
||||||
// @Param authIDType formData string false "只有在登录类型为localpass时,才有意义,分别为:userid2:用户名,email,mobile"
|
// @Param authIDType formData string false "只有在登录类型为localpass时,才有意义,分别为:userid2:用户名,email,mobile"
|
||||||
|
|||||||
Reference in New Issue
Block a user