Adaptive tyc mini login

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

View File

@@ -98,8 +98,10 @@ type WechatH5Config struct {
AppSecret string
}
type WechatMiniConfig struct {
AppID string
AppSecret string
AppID string
AppSecret string
TycAppID string
TycAppSecret string
}
type QueryConfig struct {
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) {
// 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)

View File

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