作者 唐旭辉
... ... @@ -15,3 +15,8 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
source_host ="http://192.168.139.131:8080/"
source_virtual_path=file/ab
source_path =/home/tiptok/www/ab
#网易云信 IM
net_im_base_url ="https://api.netease.im/nimserver"
net_im_app_secret ="a8d231f5c13a"
net_im_app_key ="9c5410602597a7fe367aeeebd8210262"
\ No newline at end of file
... ...
... ... @@ -45,8 +45,7 @@ func init() {
//Password:"ibfduqhfmgypbffe", //授权码
//IsUseSsl:true,
})
//TODO:服务配置
im.InitImClient("","","")
im.InitImClient(beego.AppConfig.String("net_im_base_url"),beego.AppConfig.String("net_im_app_key"),beego.AppConfig.String("net_im_app_secret"))
}
func main() {
... ...
... ... @@ -171,3 +171,12 @@ func GetUsersByMobile(mobile string)(v *Users, err error) {
}
return nil, err
}
func GetUsersKefu()(v []*Users,err error){
o := orm.NewOrm()
sql :=`select * from users where is_kefu = 1`
if _,err = o.Raw(sql).QueryRows(&v); err == nil {
return v, nil
}
return nil, err
}
\ No newline at end of file
... ...
... ... @@ -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
}
if checkImResponse!=nil && checkImResponse.ImToken!=""{
userInfo.ImToken = checkImResponse.ImToken
if userInfo.CsAccount == 0 {
userInfo.CsAccount = checkImResponse.CsAccount
}
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
}
... ...