Adaptive tyc mini login
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user