|
@@ -5,6 +5,8 @@ import ( |
|
@@ -5,6 +5,8 @@ import ( |
5
|
"encoding/json"
|
5
|
"encoding/json"
|
6
|
"fmt"
|
6
|
"fmt"
|
7
|
"html/template"
|
7
|
"html/template"
|
|
|
8
|
+ "math/rand"
|
|
|
9
|
+ "strconv"
|
8
|
"strings"
|
10
|
"strings"
|
9
|
"time"
|
11
|
"time"
|
10
|
|
12
|
|
|
@@ -90,17 +92,19 @@ Success: |
|
@@ -90,17 +92,19 @@ Success: |
90
|
if userInfo.Auth == "" {
|
92
|
if userInfo.Auth == "" {
|
91
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
93
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
92
|
}
|
94
|
}
|
93
|
- if checkImResponse, err = CheckIm(&protocol.CheckImRequest{
|
|
|
94
|
- Uid: fmt.Sprintf("%v", userInfo.Id),
|
|
|
95
|
- Uname: userInfo.Uname,
|
|
|
96
|
- Icon: userInfo.Icon,
|
|
|
97
|
- IsCreated: userInfo.ImToken == "",
|
|
|
98
|
- }); err != nil {
|
95
|
+ if checkImResponse,err=CheckIm(&protocol.CheckImRequest{
|
|
|
96
|
+ Uid:fmt.Sprintf("%v",userInfo.Id),
|
|
|
97
|
+ Uname:userInfo.Uname,
|
|
|
98
|
+ Icon:userInfo.Icon,
|
|
|
99
|
+ IsCreated:userInfo.ImToken!="",
|
|
|
100
|
+ });err!=nil{
|
99
|
return
|
101
|
return
|
100
|
}
|
102
|
}
|
|
|
103
|
+ if checkImResponse!=nil && checkImResponse.ImToken!=""{
|
101
|
userInfo.ImToken = checkImResponse.ImToken
|
104
|
userInfo.ImToken = checkImResponse.ImToken
|
102
|
- if userInfo.CsAccount == 0 {
|
|
|
103
|
- userInfo.CsAccount = checkImResponse.CsAccount
|
105
|
+ }
|
|
|
106
|
+ if userInfo.CsAccount==0{
|
|
|
107
|
+ userInfo.CsAccount = imGetRandomCSAccount()
|
104
|
}
|
108
|
}
|
105
|
userInfo.AuthExp = time.Now().Add(time.Second * protocol.TokenExpire)
|
109
|
userInfo.AuthExp = time.Now().Add(time.Second * protocol.TokenExpire)
|
106
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
110
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
|
@@ -483,3 +487,22 @@ func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImR |
|
@@ -483,3 +487,22 @@ func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImR |
483
|
rsp.ImToken = out.Info.Token
|
487
|
rsp.ImToken = out.Info.Token
|
484
|
return
|
488
|
return
|
485
|
}
|
489
|
}
|
|
|
490
|
+
|
|
|
491
|
+// 获取客服id
|
|
|
492
|
+func imGetRandomCSAccount()( acid int64){
|
|
|
493
|
+ kefus,err :=models.GetUsersKefu()
|
|
|
494
|
+ if err!=nil{
|
|
|
495
|
+ log.Error(err)
|
|
|
496
|
+ return
|
|
|
497
|
+ }
|
|
|
498
|
+ if len(kefus)<=0{
|
|
|
499
|
+ return
|
|
|
500
|
+ }
|
|
|
501
|
+ index :=rand.Intn(len(kefus))
|
|
|
502
|
+ acid,err = strconv.ParseInt(kefus[index].Accid,10,64)
|
|
|
503
|
+ if err!=nil{
|
|
|
504
|
+ log.Error(err)
|
|
|
505
|
+ }
|
|
|
506
|
+ return acid
|
|
|
507
|
+}
|
|
|
508
|
+ |