This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/wecom
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git
The following commit(s) were added to refs/heads/feat/wecom by this push:
new 5f29879 feat(wecom): get email from from biz_email first
5f29879 is described below
commit 5f298799c8c74538867aa16aa15e8d1241441f7e
Author: LinkinStars <[email protected]>
AuthorDate: Wed Apr 24 17:19:59 2024 +0800
feat(wecom): get email from from biz_email first
---
user-center-wecom/schema.go | 8 ++++++++
user-center-wecom/wecom_user_center.go | 4 ++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/user-center-wecom/schema.go b/user-center-wecom/schema.go
index a3c691b..3750da6 100644
--- a/user-center-wecom/schema.go
+++ b/user-center-wecom/schema.go
@@ -50,6 +50,7 @@ type UserInfo struct {
Mobile string `json:"mobile"`
Gender string `json:"gender"`
Email string `json:"email"`
+ BizEmail string `json:"biz_mail"`
Avatar string `json:"avatar"`
QrCode string `json:"qr_code"`
Address string `json:"address"`
@@ -59,6 +60,13 @@ type UserInfo struct {
IsAvailable bool `json:"is_available"`
}
+func (u *UserInfo) GetEmail() string {
+ if len(u.BizEmail) > 0 {
+ return u.BizEmail
+ }
+ return u.Email
+}
+
type UserDetailInfo struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
diff --git a/user-center-wecom/wecom_user_center.go
b/user-center-wecom/wecom_user_center.go
index 979db5c..23d9db9 100644
--- a/user-center-wecom/wecom_user_center.go
+++ b/user-center-wecom/wecom_user_center.go
@@ -150,7 +150,7 @@ func (uc *UserCenter) LoginCallback(ctx *plugin.GinContext)
(userInfo *plugin.Us
if !info.IsAvailable {
return nil, fmt.Errorf("user is not available")
}
- if len(info.Email) == 0 {
+ if len(info.GetEmail()) == 0 {
ctx.Redirect(http.StatusFound, "/user-center/auth-failed")
ctx.Abort()
return nil, fmt.Errorf("user email is empty")
@@ -160,7 +160,7 @@ func (uc *UserCenter) LoginCallback(ctx *plugin.GinContext)
(userInfo *plugin.Us
userInfo.ExternalID = info.Userid
userInfo.Username = info.Userid
userInfo.DisplayName = info.Name
- userInfo.Email = info.Email
+ userInfo.Email = info.GetEmail()
userInfo.Rank = 0
userInfo.Avatar = info.Avatar
userInfo.Mobile = info.Mobile