|
@@ -2,10 +2,10 @@ package user |
|
@@ -2,10 +2,10 @@ package user |
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
"context"
|
4
|
"context"
|
|
|
5
|
+ "fmt"
|
5
|
"github.com/silenceper/wechat/v2"
|
6
|
"github.com/silenceper/wechat/v2"
|
6
|
"github.com/silenceper/wechat/v2/cache"
|
7
|
"github.com/silenceper/wechat/v2/cache"
|
7
|
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
|
8
|
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
|
8
|
- "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
|
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/smslib"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/smslib"
|
11
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
|
11
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
|
|
@@ -53,11 +53,6 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res |
|
@@ -53,11 +53,6 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res |
53
|
|
53
|
|
54
|
var users []*domain.User
|
54
|
var users []*domain.User
|
55
|
conn := l.svcCtx.DefaultDBConn()
|
55
|
conn := l.svcCtx.DefaultDBConn()
|
56
|
- //保存微信用户信息
|
|
|
57
|
- err = saveUserWechat(l.svcCtx, l.ctx, conn, loginInfo)
|
|
|
58
|
- if err != nil {
|
|
|
59
|
- return nil, err
|
|
|
60
|
- }
|
|
|
61
|
_, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
56
|
_, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
62
|
MustWithKV("phone", loginInfo.Phone).
|
57
|
MustWithKV("phone", loginInfo.Phone).
|
63
|
MustWithKV("auditStatus", []int{domain.UserAuditStatusWait, domain.UserAuditStatusPassed}).
|
58
|
MustWithKV("auditStatus", []int{domain.UserAuditStatusWait, domain.UserAuditStatusPassed}).
|
|
@@ -92,23 +87,6 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res |
|
@@ -92,23 +87,6 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res |
92
|
return
|
87
|
return
|
93
|
}
|
88
|
}
|
94
|
|
89
|
|
95
|
-// saveUserWechat 保存微信授权信息
|
|
|
96
|
-func saveUserWechat(svcCtx *svc.ServiceContext, ctx context.Context, conn transaction.Conn, loginInfo *domain.LoginInfo) error {
|
|
|
97
|
- if loginInfo.Phone != "" && loginInfo.OpenId != "" {
|
|
|
98
|
- _, err := svcCtx.UserWechatRepository.FindOneByPhone(ctx, conn, loginInfo.Phone)
|
|
|
99
|
- if err != nil { // 未存储
|
|
|
100
|
- _, err = svcCtx.UserWechatRepository.Insert(ctx, conn, &domain.UserWechat{
|
|
|
101
|
- OpenId: loginInfo.OpenId,
|
|
|
102
|
- Phone: loginInfo.Phone,
|
|
|
103
|
- })
|
|
|
104
|
- if err != nil {
|
|
|
105
|
- return err
|
|
|
106
|
- }
|
|
|
107
|
- }
|
|
|
108
|
- }
|
|
|
109
|
- return nil
|
|
|
110
|
-}
|
|
|
111
|
-
|
|
|
112
|
func generateToken(svcCtx *svc.ServiceContext, user *domain.User) (token string, err error) {
|
90
|
func generateToken(svcCtx *svc.ServiceContext, user *domain.User) (token string, err error) {
|
113
|
var userJwtToken = tool.UserToken{}
|
91
|
var userJwtToken = tool.UserToken{}
|
114
|
if user != nil {
|
92
|
if user != nil {
|
|
@@ -138,25 +116,14 @@ func (c WxClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.Lo |
|
@@ -138,25 +116,14 @@ func (c WxClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.Lo |
138
|
AppSecret: c.svcCtx.Config.Wechat.AppSecret,
|
116
|
AppSecret: c.svcCtx.Config.Wechat.AppSecret,
|
139
|
Cache: cache.NewMemory(),
|
117
|
Cache: cache.NewMemory(),
|
140
|
})
|
118
|
})
|
141
|
- result, err := miniprogram.GetAuth().Code2Session(code)
|
|
|
142
|
- if err != nil {
|
|
|
143
|
- return nil, xerr.NewErrMsgErr("发起授权请求失败", err)
|
|
|
144
|
- }
|
|
|
145
|
- plainData, err := miniprogram.GetEncryptor().Decrypt(result.SessionKey, r.EncryptedData, r.IV)
|
|
|
146
|
- if err != nil {
|
|
|
147
|
- return nil, xerr.NewErrMsgErr("获取授权用户失败", err)
|
|
|
148
|
- }
|
|
|
149
|
- //增加微信用户openId
|
|
|
150
|
- response.OpenId = plainData.OpenID
|
|
|
151
|
- response.Phone = plainData.PhoneNumber
|
|
|
152
|
- /*authResult, err := miniprogram.GetAuth().GetPhoneNumber(code)
|
119
|
+ authResult, err := miniprogram.GetAuth().GetPhoneNumber(code)
|
153
|
if err != nil || authResult.ErrCode != 0 || authResult.PhoneInfo.PhoneNumber == "" {
|
120
|
if err != nil || authResult.ErrCode != 0 || authResult.PhoneInfo.PhoneNumber == "" {
|
154
|
return response, xerr.NewCodeErrMsg(xerr.ErrWxMiniAuthFailError, nil, fmt.Sprintf("发起授权请求失败1 err : %v , code : %s , authResult : %+v", err, code, authResult))
|
121
|
return response, xerr.NewCodeErrMsg(xerr.ErrWxMiniAuthFailError, nil, fmt.Sprintf("发起授权请求失败1 err : %v , code : %s , authResult : %+v", err, code, authResult))
|
155
|
}
|
122
|
}
|
156
|
var (
|
123
|
var (
|
157
|
phone = authResult.PhoneInfo.PhoneNumber
|
124
|
phone = authResult.PhoneInfo.PhoneNumber
|
158
|
)
|
125
|
)
|
159
|
- response.Phone = phone*/
|
126
|
+ response.Phone = phone
|
160
|
return response, nil
|
127
|
return response, nil
|
161
|
}
|
128
|
}
|
162
|
|
129
|
|
|
@@ -164,6 +131,23 @@ func (c WxClientLogin) WechatLogin(r domain.WechatLoginRequest) (*domain.LoginIn |
|
@@ -164,6 +131,23 @@ func (c WxClientLogin) WechatLogin(r domain.WechatLoginRequest) (*domain.LoginIn |
164
|
return nil, nil
|
131
|
return nil, nil
|
165
|
}
|
132
|
}
|
166
|
|
133
|
|
|
|
134
|
+func (c WxClientLogin) GetOpenId(r domain.WechatLoginRequest) (string, error) {
|
|
|
135
|
+ miniprogram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{
|
|
|
136
|
+ AppID: c.svcCtx.Config.Wechat.AppID,
|
|
|
137
|
+ AppSecret: c.svcCtx.Config.Wechat.AppSecret,
|
|
|
138
|
+ Cache: cache.NewMemory(),
|
|
|
139
|
+ })
|
|
|
140
|
+ result, err := miniprogram.GetAuth().Code2Session(r.Code)
|
|
|
141
|
+ if err != nil {
|
|
|
142
|
+ return "", xerr.NewErrMsgErr("发起授权请求失败", err)
|
|
|
143
|
+ }
|
|
|
144
|
+ plainData, err := miniprogram.GetEncryptor().Decrypt(result.SessionKey, r.EncryptedData, r.IV)
|
|
|
145
|
+ if err != nil {
|
|
|
146
|
+ return "", xerr.NewErrMsgErr("获取授权用户失败", err)
|
|
|
147
|
+ }
|
|
|
148
|
+ return plainData.OpenID, nil
|
|
|
149
|
+}
|
|
|
150
|
+
|
167
|
func (c WxClientLogin) PhonePasswordLogin(phone string, password string) (*domain.LoginInfo, error) {
|
151
|
func (c WxClientLogin) PhonePasswordLogin(phone string, password string) (*domain.LoginInfo, error) {
|
168
|
panic("implement me")
|
152
|
panic("implement me")
|
169
|
}
|
153
|
}
|