Adaptive tyc mini login

This commit is contained in:
liangzai 2025-06-25 00:54:27 +08:00
parent 0a0e1d09ed
commit d9d90a030f
6 changed files with 23 additions and 8 deletions

View File

@ -50,7 +50,8 @@ type (
type ( type (
WXMiniAuthReq { WXMiniAuthReq {
Code string `json:"code"` Code string `json:"code"`
Platform string `json:"platform,optional,default=tyc"`
} }
WXMiniAuthResp { WXMiniAuthResp {
AccessToken string `json:"accessToken"` AccessToken string `json:"accessToken"`

View File

@ -67,6 +67,8 @@ WechatH5:
WechatMini: WechatMini:
AppID: "wx781abb66b3368963" # 小程序的AppID AppID: "wx781abb66b3368963" # 小程序的AppID
AppSecret: "c7d02cdb0fc23c35c93187af9243b00d" # 小程序的AppSecret AppSecret: "c7d02cdb0fc23c35c93187af9243b00d" # 小程序的AppSecret
TycAppID: "wxe74617f3dd56c196"
TycAppSecret: "c8207e54aef5689b2a7c1f91ed7ae8a0"
Query: Query:
ShareLinkExpire: 604800 # 7天 = 7 * 24 * 60 * 60 = 604800秒 ShareLinkExpire: 604800 # 7天 = 7 * 24 * 60 * 60 = 604800秒
AdminConfig: AdminConfig:

View File

@ -68,6 +68,8 @@ WechatH5:
WechatMini: WechatMini:
AppID: "wx781abb66b3368963" # 小程序的AppID AppID: "wx781abb66b3368963" # 小程序的AppID
AppSecret: "c7d02cdb0fc23c35c93187af9243b00d" # 小程序的AppSecret AppSecret: "c7d02cdb0fc23c35c93187af9243b00d" # 小程序的AppSecret
TycAppID: "wxe74617f3dd56c196"
TycAppSecret: "c8207e54aef5689b2a7c1f91ed7ae8a0"
Query: Query:
ShareLinkExpire: 604800 # 7天 = 7 * 24 * 60 * 60 = 604800秒 ShareLinkExpire: 604800 # 7天 = 7 * 24 * 60 * 60 = 604800秒
AdminConfig: AdminConfig:

View File

@ -98,8 +98,10 @@ type WechatH5Config struct {
AppSecret string AppSecret string
} }
type WechatMiniConfig struct { type WechatMiniConfig struct {
AppID string AppID string
AppSecret string AppSecret string
TycAppID string
TycAppSecret string
} }
type QueryConfig struct { type QueryConfig struct {
ShareLinkExpire int64 ShareLinkExpire int64

View File

@ -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) { func (l *WxMiniAuthLogic) WxMiniAuth(req *types.WXMiniAuthReq) (resp *types.WXMiniAuthResp, err error) {
// 1. 获取session_key和openid // 1. 获取session_key和openid
sessionKeyResp, err := l.GetSessionKey(req.Code) sessionKeyResp, err := l.GetSessionKey(req.Code, req.Platform)
if err != nil { if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取session_key失败: %v", err) 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 // GetSessionKey 通过code获取小程序的session_key和openid
func (l *WxMiniAuthLogic) GetSessionKey(code string) (*SessionKeyResp, error) { func (l *WxMiniAuthLogic) GetSessionKey(code string, platform string) (*SessionKeyResp, error) {
appID := l.svcCtx.Config.WechatMini.AppID var appID string
appSecret := l.svcCtx.Config.WechatMini.AppSecret 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", url := fmt.Sprintf("https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code",
appID, appSecret, code) appID, appSecret, code)

View File

@ -1705,7 +1705,8 @@ type WXH5AuthResp struct {
} }
type WXMiniAuthReq struct { type WXMiniAuthReq struct {
Code string `json:"code"` Code string `json:"code"`
Platform string `json:"platform,optional,default=tyc"`
} }
type WXMiniAuthResp struct { type WXMiniAuthResp struct {