Adaptive tyc mini login
This commit is contained in:
parent
0a0e1d09ed
commit
d9d90a030f
@ -51,6 +51,7 @@ type (
|
||||
type (
|
||||
WXMiniAuthReq {
|
||||
Code string `json:"code"`
|
||||
Platform string `json:"platform,optional,default=tyc"`
|
||||
}
|
||||
WXMiniAuthResp {
|
||||
AccessToken string `json:"accessToken"`
|
||||
|
@ -67,6 +67,8 @@ WechatH5:
|
||||
WechatMini:
|
||||
AppID: "wx781abb66b3368963" # 小程序的AppID
|
||||
AppSecret: "c7d02cdb0fc23c35c93187af9243b00d" # 小程序的AppSecret
|
||||
TycAppID: "wxe74617f3dd56c196"
|
||||
TycAppSecret: "c8207e54aef5689b2a7c1f91ed7ae8a0"
|
||||
Query:
|
||||
ShareLinkExpire: 604800 # 7天 = 7 * 24 * 60 * 60 = 604800秒
|
||||
AdminConfig:
|
||||
|
@ -68,6 +68,8 @@ WechatH5:
|
||||
WechatMini:
|
||||
AppID: "wx781abb66b3368963" # 小程序的AppID
|
||||
AppSecret: "c7d02cdb0fc23c35c93187af9243b00d" # 小程序的AppSecret
|
||||
TycAppID: "wxe74617f3dd56c196"
|
||||
TycAppSecret: "c8207e54aef5689b2a7c1f91ed7ae8a0"
|
||||
Query:
|
||||
ShareLinkExpire: 604800 # 7天 = 7 * 24 * 60 * 60 = 604800秒
|
||||
AdminConfig:
|
||||
|
@ -100,6 +100,8 @@ type WechatH5Config struct {
|
||||
type WechatMiniConfig struct {
|
||||
AppID string
|
||||
AppSecret string
|
||||
TycAppID string
|
||||
TycAppSecret string
|
||||
}
|
||||
type QueryConfig struct {
|
||||
ShareLinkExpire int64
|
||||
|
@ -33,7 +33,7 @@ func NewWxMiniAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WxMini
|
||||
|
||||
func (l *WxMiniAuthLogic) WxMiniAuth(req *types.WXMiniAuthReq) (resp *types.WXMiniAuthResp, err error) {
|
||||
// 1. 获取session_key和openid
|
||||
sessionKeyResp, err := l.GetSessionKey(req.Code)
|
||||
sessionKeyResp, err := l.GetSessionKey(req.Code, req.Platform)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取session_key失败: %v", err)
|
||||
}
|
||||
@ -103,9 +103,16 @@ type SessionKeyResp struct {
|
||||
}
|
||||
|
||||
// GetSessionKey 通过code获取小程序的session_key和openid
|
||||
func (l *WxMiniAuthLogic) GetSessionKey(code string) (*SessionKeyResp, error) {
|
||||
appID := l.svcCtx.Config.WechatMini.AppID
|
||||
appSecret := l.svcCtx.Config.WechatMini.AppSecret
|
||||
func (l *WxMiniAuthLogic) GetSessionKey(code string, platform string) (*SessionKeyResp, error) {
|
||||
var appID string
|
||||
var appSecret string
|
||||
if platform == "tyc" {
|
||||
appID = l.svcCtx.Config.WechatMini.TycAppID
|
||||
appSecret = l.svcCtx.Config.WechatMini.TycAppSecret
|
||||
} else {
|
||||
appID = l.svcCtx.Config.WechatMini.AppID
|
||||
appSecret = l.svcCtx.Config.WechatMini.AppSecret
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code",
|
||||
appID, appSecret, code)
|
||||
|
@ -1706,6 +1706,7 @@ type WXH5AuthResp struct {
|
||||
|
||||
type WXMiniAuthReq struct {
|
||||
Code string `json:"code"`
|
||||
Platform string `json:"platform,optional,default=tyc"`
|
||||
}
|
||||
|
||||
type WXMiniAuthResp struct {
|
||||
|
Loading…
Reference in New Issue
Block a user