...
|
...
|
@@ -5,6 +5,8 @@ import ( |
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"html/template"
|
|
|
"math/rand"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
...
|
...
|
@@ -90,17 +92,19 @@ Success: |
|
|
if userInfo.Auth == "" {
|
|
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
|
|
}
|
|
|
if checkImResponse, err = CheckIm(&protocol.CheckImRequest{
|
|
|
Uid: fmt.Sprintf("%v", userInfo.Id),
|
|
|
Uname: userInfo.Uname,
|
|
|
Icon: userInfo.Icon,
|
|
|
IsCreated: userInfo.ImToken == "",
|
|
|
}); err != nil {
|
|
|
if checkImResponse,err=CheckIm(&protocol.CheckImRequest{
|
|
|
Uid:fmt.Sprintf("%v",userInfo.Id),
|
|
|
Uname:userInfo.Uname,
|
|
|
Icon:userInfo.Icon,
|
|
|
IsCreated:userInfo.ImToken!="",
|
|
|
});err!=nil{
|
|
|
return
|
|
|
}
|
|
|
userInfo.ImToken = checkImResponse.ImToken
|
|
|
if userInfo.CsAccount == 0 {
|
|
|
userInfo.CsAccount = checkImResponse.CsAccount
|
|
|
if checkImResponse!=nil && checkImResponse.ImToken!=""{
|
|
|
userInfo.ImToken = checkImResponse.ImToken
|
|
|
}
|
|
|
if userInfo.CsAccount==0{
|
|
|
userInfo.CsAccount = imGetRandomCSAccount()
|
|
|
}
|
|
|
userInfo.AuthExp = time.Now().Add(time.Second * protocol.TokenExpire)
|
|
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
...
|
...
|
@@ -483,3 +487,22 @@ func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImR |
|
|
rsp.ImToken = out.Info.Token
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 获取客服id
|
|
|
func imGetRandomCSAccount()( acid int64){
|
|
|
kefus,err :=models.GetUsersKefu()
|
|
|
if err!=nil{
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if len(kefus)<=0{
|
|
|
return
|
|
|
}
|
|
|
index :=rand.Intn(len(kefus))
|
|
|
acid,err = strconv.ParseInt(kefus[index].Accid,10,64)
|
|
|
if err!=nil{
|
|
|
log.Error(err)
|
|
|
}
|
|
|
return acid
|
|
|
}
|
|
|
|
...
|
...
|
|