app微信登录
This commit is contained in:
@@ -15,6 +15,7 @@ const (
|
|||||||
AuthTypeWeixin = "wxqrcode" // 微信扫码
|
AuthTypeWeixin = "wxqrcode" // 微信扫码
|
||||||
AuthTypeMP = "weixinsns" // 公众号
|
AuthTypeMP = "weixinsns" // 公众号
|
||||||
AuthTypeWXNative = "wxnative" // 微信APP
|
AuthTypeWXNative = "wxnative" // 微信APP
|
||||||
|
AuthTypeWxApp = "weixinapp" //app微信登录
|
||||||
)
|
)
|
||||||
|
|
||||||
type Auther struct {
|
type Auther struct {
|
||||||
@@ -26,6 +27,7 @@ var (
|
|||||||
AutherObjWX *Auther
|
AutherObjWX *Auther
|
||||||
AutherObjMP *Auther
|
AutherObjMP *Auther
|
||||||
AutherObjNative *Auther
|
AutherObjNative *Auther
|
||||||
|
AutherObjApp *Auther
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -47,6 +49,11 @@ func init() {
|
|||||||
authType: AuthTypeWXNative,
|
authType: AuthTypeWXNative,
|
||||||
}
|
}
|
||||||
auth2.RegisterAuther(AuthTypeWXNative, AutherObjNative)
|
auth2.RegisterAuther(AuthTypeWXNative, AutherObjNative)
|
||||||
|
|
||||||
|
AutherObjApp = &Auther{
|
||||||
|
authType: AuthTypeWxApp,
|
||||||
|
}
|
||||||
|
auth2.RegisterAuther(AuthTypeWxApp, AutherObjApp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx, err error) {
|
func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||||
@@ -71,7 +78,7 @@ func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx,
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
wxUserinfo, err2 := a.getAPI().SNSGetUserInfo(accessToken, openID)
|
wxUserinfo, err2 := a.getAPI().SNSGetUserInfo(accessToken, openID)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
if authBindEx, err = a.UnionFindAuthBind(a.authType, a.getAPI().GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
|
if authBindEx, err = a.UnionFindAuthBind(a.authType, a.getAPI().GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative, AuthTypeWxApp}, 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,
|
||||||
@@ -86,6 +93,9 @@ func (a *Auther) getAPI() *weixinapi.API {
|
|||||||
if a.authType == AuthTypeWeixin {
|
if a.authType == AuthTypeWeixin {
|
||||||
return api.WeixinPageAPI
|
return api.WeixinPageAPI
|
||||||
}
|
}
|
||||||
|
if a.authType == AuthTypeWxApp {
|
||||||
|
return api.WeixinApp
|
||||||
|
}
|
||||||
return api.WeixinAPI
|
return api.WeixinAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,9 +92,6 @@ func getWxApp(appID string) (miniApi *weixinapi.API) {
|
|||||||
if len(appID) > 0 && appID == api.WeixinMiniAppID2 {
|
if len(appID) > 0 && appID == api.WeixinMiniAppID2 {
|
||||||
miniApi = api.WeixinMiniAPI2
|
miniApi = api.WeixinMiniAPI2
|
||||||
}
|
}
|
||||||
if len(appID) > 0 && appID == api.WeixinMiniAppID3 {
|
|
||||||
miniApi = api.WeixinMiniAPI3
|
|
||||||
}
|
|
||||||
return miniApi
|
return miniApi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,29 +166,29 @@ func RefreshWeixin2Token() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RefreshWeixin3Token() (err error) {
|
func RefreshWeixin3Token() (err error) {
|
||||||
if api.WeixinMiniAPI3 != nil {
|
// if api.WeixinMiniAPI3 != nil {
|
||||||
err = RefreshConfig("wechat3", weixinTokenExpires, func() (token string, expireTimeStr string) {
|
// err = RefreshConfig("wechat3", weixinTokenExpires, func() (token string, expireTimeStr string) {
|
||||||
globals.SugarLogger.Debugf("RefreshWeixin3Token RunMode:%s", beego.BConfig.RunMode)
|
// globals.SugarLogger.Debugf("RefreshWeixin3Token RunMode:%s", beego.BConfig.RunMode)
|
||||||
if globals.IsMainProductEnv() {
|
// if globals.IsMainProductEnv() {
|
||||||
if tokenInfo, err := api.WeixinMiniAPI3.CBRetrieveToken(); err == nil {
|
// if tokenInfo, err := api.WeixinMiniAPI3.CBRetrieveToken(); err == nil {
|
||||||
globals.SugarLogger.Debugf("RefreshWeixin3Token tokenInfo:%s", utils.Format4Output(tokenInfo, true))
|
// globals.SugarLogger.Debugf("RefreshWeixin3Token tokenInfo:%s", utils.Format4Output(tokenInfo, true))
|
||||||
token = tokenInfo.AccessToken
|
// token = tokenInfo.AccessToken
|
||||||
} else {
|
// } else {
|
||||||
globals.SugarLogger.Errorf("RefreshWeixin3Token RefreshToken failed with error:%v", err)
|
// globals.SugarLogger.Errorf("RefreshWeixin3Token RefreshToken failed with error:%v", err)
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if tokenInfo := getWX3TokenFromRemote(api.WeixinMiniAPI3.CBGetToken()); tokenInfo != nil {
|
// if tokenInfo := getWX3TokenFromRemote(api.WeixinMiniAPI3.CBGetToken()); tokenInfo != nil {
|
||||||
expireTimeStr = utils.Time2Str(time.Now().Add(-weixinTokenExpires))
|
// expireTimeStr = utils.Time2Str(time.Now().Add(-weixinTokenExpires))
|
||||||
token = tokenInfo.Token
|
// token = tokenInfo.Token
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return token, expireTimeStr
|
// return token, expireTimeStr
|
||||||
}, func(value string) {
|
// }, func(value string) {
|
||||||
globals.SugarLogger.Debugf("RefreshWeixinToken setter value:%s", value)
|
// globals.SugarLogger.Debugf("RefreshWeixinToken setter value:%s", value)
|
||||||
syseventhub.SysEventHub.OnNewWX3Token(value)
|
// syseventhub.SysEventHub.OnNewWX3Token(value)
|
||||||
api.WeixinMiniAPI3.CBSetToken(value)
|
// api.WeixinMiniAPI3.CBSetToken(value)
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ var (
|
|||||||
WeixinAPI *weixinapi.API // 微信公众号
|
WeixinAPI *weixinapi.API // 微信公众号
|
||||||
WeixinMiniAPI *weixinapi.API // 小程序
|
WeixinMiniAPI *weixinapi.API // 小程序
|
||||||
WeixinMiniAPI2 *weixinapi.API // 小程序2
|
WeixinMiniAPI2 *weixinapi.API // 小程序2
|
||||||
WeixinMiniAPI3 *weixinapi.API // 小程序3
|
WeixinApp *weixinapi.API // app微信登录
|
||||||
WeixinMiniAppID2 string
|
WeixinMiniAppID2 string
|
||||||
WeixinMiniAppID3 string
|
WeixinMiniAppID3 string
|
||||||
WxpayAPI *wxpayapi.API // 微信支付API
|
WxpayAPI *wxpayapi.API // 微信支付API
|
||||||
@@ -213,7 +213,7 @@ func Init() {
|
|||||||
}
|
}
|
||||||
WeixinPageAPI = weixinapi.New(beego.AppConfig.String("weixinPageAppID"), beego.AppConfig.String("weixinPageSecret"))
|
WeixinPageAPI = weixinapi.New(beego.AppConfig.String("weixinPageAppID"), beego.AppConfig.String("weixinPageSecret"))
|
||||||
if WeixinMiniAppID3 = beego.AppConfig.String("weixinMiniAppID3"); WeixinMiniAppID3 != "" {
|
if WeixinMiniAppID3 = beego.AppConfig.String("weixinMiniAppID3"); WeixinMiniAppID3 != "" {
|
||||||
WeixinMiniAPI3 = weixinapi.New(WeixinMiniAppID3, beego.AppConfig.String("weixinMiniSecret3"))
|
WeixinApp = weixinapi.New(WeixinMiniAppID3, beego.AppConfig.String("weixinMiniSecret3"))
|
||||||
}
|
}
|
||||||
if globals.WxpayNotifyURL != "" {
|
if globals.WxpayNotifyURL != "" {
|
||||||
// WxpayAPI = wxpayapi.New(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID"))
|
// WxpayAPI = wxpayapi.New(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID"))
|
||||||
|
|||||||
Reference in New Issue
Block a user