作者 yangfu

im check

... ... @@ -14,4 +14,9 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
#存储 http://ability.fjmaimaimai.com:8080/
source_host ="http://192.168.139.131:8080/"
source_virtual_path=file/ab
source_path =/home/tiptok/www/ab
\ No newline at end of file
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
... ...
... ... @@ -6,6 +6,8 @@ import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
"html/template"
"math/rand"
"strconv"
"strings"
"time"
... ... @@ -93,13 +95,15 @@ Success:
Uid:fmt.Sprintf("%v",userInfo.Id),
Uname:userInfo.Uname,
Icon:userInfo.Icon,
IsCreated:userInfo.ImToken=="",
IsCreated:userInfo.ImToken!="",
});err!=nil{
return
}
userInfo.ImToken = checkImResponse.ImToken
if checkImResponse!=nil && checkImResponse.ImToken!=""{
userInfo.ImToken = checkImResponse.ImToken
}
if userInfo.CsAccount==0{
userInfo.CsAccount = checkImResponse.CsAccount
userInfo.CsAccount = imGetRandomCSAccount()
}
userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire)
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
... ... @@ -414,5 +418,22 @@ func imUserRefreshToken(request *protocol.CheckImRequest,rsp *protocol.CheckImRe
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
}
... ...
... ... @@ -71,4 +71,4 @@ func Test_RefreshToken(t *testing.T) {
if rsp,err :=auth.RefreshToken(req);err!=nil{
t.Fatal(err,rsp)
}
}
}
\ No newline at end of file
... ...