|
@@ -13,6 +13,7 @@ import ( |
|
@@ -13,6 +13,7 @@ import ( |
13
|
"ability/models"
|
13
|
"ability/models"
|
14
|
"ability/protocol"
|
14
|
"ability/protocol"
|
15
|
s_sms "ability/services/sms"
|
15
|
s_sms "ability/services/sms"
|
|
|
16
|
+ s_im "ability/services/im"
|
16
|
|
17
|
|
17
|
"github.com/astaxie/beego"
|
18
|
"github.com/astaxie/beego"
|
18
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
19
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
|
@@ -51,6 +52,7 @@ func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.Login |
|
@@ -51,6 +52,7 @@ func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.Login |
51
|
user *models.Users
|
52
|
user *models.Users
|
52
|
userInfo *models.UserInfo
|
53
|
userInfo *models.UserInfo
|
53
|
result bool
|
54
|
result bool
|
|
|
55
|
+ checkImResponse *protocol.CheckImResponse
|
54
|
)
|
56
|
)
|
55
|
user, err = UserRepository.GetUsersByMobile(request.Phone)
|
57
|
user, err = UserRepository.GetUsersByMobile(request.Phone)
|
56
|
if err != nil {
|
58
|
if err != nil {
|
|
@@ -87,7 +89,18 @@ Success: |
|
@@ -87,7 +89,18 @@ Success: |
87
|
if userInfo.Auth == "" {
|
89
|
if userInfo.Auth == "" {
|
88
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
90
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
89
|
}
|
91
|
}
|
90
|
- //TODO:更新
|
92
|
+ if checkImResponse,err=CheckIm(&protocol.CheckImRequest{
|
|
|
93
|
+ Uid:fmt.Sprintf("%v",userInfo.Id),
|
|
|
94
|
+ Uname:userInfo.Uname,
|
|
|
95
|
+ Icon:userInfo.Icon,
|
|
|
96
|
+ IsCreated:userInfo.ImToken=="",
|
|
|
97
|
+ });err!=nil{
|
|
|
98
|
+ return
|
|
|
99
|
+ }
|
|
|
100
|
+ userInfo.ImToken = checkImResponse.ImToken
|
|
|
101
|
+ if userInfo.CsAccount==0{
|
|
|
102
|
+ userInfo.CsAccount = checkImResponse.CsAccount
|
|
|
103
|
+ }
|
91
|
userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire)
|
104
|
userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire)
|
92
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
105
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
93
|
return
|
106
|
return
|
|
@@ -312,3 +325,96 @@ Fail: |
|
@@ -312,3 +325,96 @@ Fail: |
312
|
}
|
325
|
}
|
313
|
return
|
326
|
return
|
314
|
}
|
327
|
}
|
|
|
328
|
+
|
|
|
329
|
+func CheckIm(request *protocol.CheckImRequest)(rsp *protocol.CheckImResponse,err error){
|
|
|
330
|
+ var (
|
|
|
331
|
+
|
|
|
332
|
+ )
|
|
|
333
|
+ if beego.BConfig.RunMode != "prod" {
|
|
|
334
|
+ return
|
|
|
335
|
+ }
|
|
|
336
|
+ rsp =&protocol.CheckImResponse{}
|
|
|
337
|
+ if !request.IsCreated{
|
|
|
338
|
+ if err = imUserCreate(request,rsp);err!=nil{
|
|
|
339
|
+ return
|
|
|
340
|
+ }
|
|
|
341
|
+ }else{
|
|
|
342
|
+ if err = imUserInfoUpdate(request,rsp);err!=nil{
|
|
|
343
|
+ return
|
|
|
344
|
+ }
|
|
|
345
|
+ }
|
|
|
346
|
+ if err = imUserRefreshToken(request,rsp);err!=nil{
|
|
|
347
|
+ return
|
|
|
348
|
+ }
|
|
|
349
|
+ return
|
|
|
350
|
+}
|
|
|
351
|
+//create
|
|
|
352
|
+func imUserCreate(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
353
|
+ var(
|
|
|
354
|
+ param s_im.UserCreate=s_im.UserCreate{
|
|
|
355
|
+ Accid:request.Uid,
|
|
|
356
|
+ Name:request.Uname,
|
|
|
357
|
+ Icon:request.Icon,
|
|
|
358
|
+ }
|
|
|
359
|
+ resp []byte
|
|
|
360
|
+ out s_im.UserCreateResult
|
|
|
361
|
+ )
|
|
|
362
|
+ if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
|
|
363
|
+ return
|
|
|
364
|
+ }
|
|
|
365
|
+ if err = json.Unmarshal(resp,&out);err!=nil{
|
|
|
366
|
+ return
|
|
|
367
|
+ }
|
|
|
368
|
+ if out.Code!=200 || (out.Info.Accid!=request.Uid){
|
|
|
369
|
+ return s_im.ErrorFailCall
|
|
|
370
|
+ }
|
|
|
371
|
+ rsp.ImToken = out.Info.Token
|
|
|
372
|
+ return
|
|
|
373
|
+}
|
|
|
374
|
+//update user info
|
|
|
375
|
+func imUserInfoUpdate(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
376
|
+ var(
|
|
|
377
|
+ param s_im.UserUpdateUinfo=s_im.UserUpdateUinfo{
|
|
|
378
|
+ s_im.UserCreate{
|
|
|
379
|
+ Accid:request.Uid,
|
|
|
380
|
+ Name:request.Uname,
|
|
|
381
|
+ Icon:request.Icon,
|
|
|
382
|
+ },
|
|
|
383
|
+ }
|
|
|
384
|
+ resp []byte
|
|
|
385
|
+ out s_im.BaseResp
|
|
|
386
|
+ )
|
|
|
387
|
+ if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
|
|
388
|
+ return
|
|
|
389
|
+ }
|
|
|
390
|
+ if err = json.Unmarshal(resp,&out);err!=nil{
|
|
|
391
|
+ return
|
|
|
392
|
+ }
|
|
|
393
|
+ if out.Code!=200{
|
|
|
394
|
+ return s_im.ErrorFailCall
|
|
|
395
|
+ }
|
|
|
396
|
+ return
|
|
|
397
|
+}
|
|
|
398
|
+//refresh token
|
|
|
399
|
+func imUserRefreshToken(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
400
|
+ var(
|
|
|
401
|
+ param s_im.UserRefreshToken=s_im.UserRefreshToken{
|
|
|
402
|
+ Accid:request.Uid,
|
|
|
403
|
+ }
|
|
|
404
|
+ resp []byte
|
|
|
405
|
+ out s_im.UserCreateResult
|
|
|
406
|
+ )
|
|
|
407
|
+ if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
|
|
408
|
+ return
|
|
|
409
|
+ }
|
|
|
410
|
+ if err = json.Unmarshal(resp,&out);err!=nil{
|
|
|
411
|
+ return
|
|
|
412
|
+ }
|
|
|
413
|
+ if out.Code!=200 || (out.Info.Accid!=request.Uid){
|
|
|
414
|
+ return s_im.ErrorFailCall
|
|
|
415
|
+ }
|
|
|
416
|
+ rsp.ImToken = out.Info.Token
|
|
|
417
|
+ return
|
|
|
418
|
+}
|
|
|
419
|
+
|
|
|
420
|
+ |