This commit is contained in:
jiangyong27 2024-12-05 11:28:49 +08:00
parent 91a71ef339
commit f06581c5d7
3 changed files with 14 additions and 7 deletions

View File

@ -14,5 +14,5 @@ func NewAppSdk(appid, secret string) *AppSdk {
}
func (o *AppSdk) GetUserInfoByCode(code string) (*UserInfo, error) {
return o.getUserInfoByCode(code)
return o.getUserInfoByCode(code, true)
}

View File

@ -69,7 +69,7 @@ func (o *BaseSdk) getAccessToken() (string, error) {
return o.accessToken, nil
}
func (o *BaseSdk) getUserInfoByCode(code string) (*UserInfo, error) {
func (o *BaseSdk) getUserInfoByCode(code string, auth bool) (*UserInfo, error) {
url := fmt.Sprintf("%s?appid=%s&secret=%s&code=%s&grant_type=authorization_code",
code2AccessTokenUrl, o.appid, o.secret, code)
res, err := http.Get(url)
@ -94,11 +94,14 @@ func (o *BaseSdk) getUserInfoByCode(code string) (*UserInfo, error) {
user.AccessToken = g.Get("access_token").String()
user.Openid = g.Get("openid").String()
if auth {
err = o.getUserInfo(&user)
if err != nil {
return nil, err
}
}
return &user, nil
}

View File

@ -57,8 +57,12 @@ func (o *OaSdk) GetQrCode(sceneStr string) (string, error) {
return qrcodeUrl, nil
}
func (o *BaseSdk) GetUserInfoByCode(code string) (*UserInfo, error) {
return o.getUserInfoByCode(code)
func (o *OaSdk) GetUserInfoByCode(code string) (*UserInfo, error) {
return o.getUserInfoByCode(code, true)
}
func (o *OaSdk) GetUserInfoByCodeNoAuth(code string) (*UserInfo, error) {
return o.getUserInfoByCode(code, false)
}
func (o *OaSdk) GetUserInfoByOpenid(openid string) (*UserInfo, error) {