From 185baa5d12181534e53da1f4c7f721211ee7dae2 Mon Sep 17 00:00:00 2001 From: Che Kun Date: Thu, 26 Nov 2020 12:09:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E5=90=8E=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E4=BF=A1=E6=81=AF=E6=94=AF=E6=8C=81=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E5=85=A5=E5=8F=82=20#344=20(#345)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- officialaccount/oauth/oauth.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/officialaccount/oauth/oauth.go b/officialaccount/oauth/oauth.go index 94c84bd..27dde91 100644 --- a/officialaccount/oauth/oauth.go +++ b/officialaccount/oauth/oauth.go @@ -15,7 +15,7 @@ const ( webAppRedirectOauthURL = "https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect" accessTokenURL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code" refreshAccessTokenURL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s" - userInfoURL = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN" + userInfoURL = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=%s" checkAccessTokenURL = "https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s" ) @@ -144,8 +144,11 @@ type UserInfo struct { } //GetUserInfo 如果scope为 snsapi_userinfo 则可以通过此方法获取到用户基本信息 -func (oauth *Oauth) GetUserInfo(accessToken, openID string) (result UserInfo, err error) { - urlStr := fmt.Sprintf(userInfoURL, accessToken, openID) +func (oauth *Oauth) GetUserInfo(accessToken, openID, lang string) (result UserInfo, err error) { + if lang == "" { + lang = "zh_CN" + } + urlStr := fmt.Sprintf(userInfoURL, accessToken, openID, lang) var response []byte response, err = util.HTTPGet(urlStr) if err != nil {