作者 yangfu

im check

@@ -14,4 +14,9 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5" @@ -14,4 +14,9 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
14 #存储 http://ability.fjmaimaimai.com:8080/ 14 #存储 http://ability.fjmaimaimai.com:8080/
15 source_host ="http://192.168.139.131:8080/" 15 source_host ="http://192.168.139.131:8080/"
16 source_virtual_path=file/ab 16 source_virtual_path=file/ab
17 -source_path =/home/tiptok/www/ab  
  17 +source_path =/home/tiptok/www/ab
  18 +
  19 +#网易云信 IM
  20 +net_im_base_url ="https://api.netease.im/nimserver"
  21 +net_im_app_secret ="a8d231f5c13a"
  22 +net_im_app_key ="9c5410602597a7fe367aeeebd8210262"
@@ -45,8 +45,7 @@ func init() { @@ -45,8 +45,7 @@ func init() {
45 //Password:"ibfduqhfmgypbffe", //授权码 45 //Password:"ibfduqhfmgypbffe", //授权码
46 //IsUseSsl:true, 46 //IsUseSsl:true,
47 }) 47 })
48 - //TODO:服务配置  
49 - im.InitImClient("","","") 48 + im.InitImClient(beego.AppConfig.String("net_im_base_url"),beego.AppConfig.String("net_im_app_key"),beego.AppConfig.String("net_im_app_secret"))
50 } 49 }
51 50
52 func main() { 51 func main() {
@@ -171,3 +171,12 @@ func GetUsersByMobile(mobile string)(v *Users, err error) { @@ -171,3 +171,12 @@ func GetUsersByMobile(mobile string)(v *Users, err error) {
171 } 171 }
172 return nil, err 172 return nil, err
173 } 173 }
  174 +
  175 +func GetUsersKefu()(v []*Users,err error){
  176 + o := orm.NewOrm()
  177 + sql :=`select * from users where is_kefu = 1`
  178 + if _,err = o.Raw(sql).QueryRows(&v); err == nil {
  179 + return v, nil
  180 + }
  181 + return nil, err
  182 +}
@@ -6,6 +6,8 @@ import ( @@ -6,6 +6,8 @@ import (
6 "fmt" 6 "fmt"
7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid" 7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
8 "html/template" 8 "html/template"
  9 + "math/rand"
  10 + "strconv"
9 "strings" 11 "strings"
10 "time" 12 "time"
11 13
@@ -93,13 +95,15 @@ Success: @@ -93,13 +95,15 @@ Success:
93 Uid:fmt.Sprintf("%v",userInfo.Id), 95 Uid:fmt.Sprintf("%v",userInfo.Id),
94 Uname:userInfo.Uname, 96 Uname:userInfo.Uname,
95 Icon:userInfo.Icon, 97 Icon:userInfo.Icon,
96 - IsCreated:userInfo.ImToken=="", 98 + IsCreated:userInfo.ImToken!="",
97 });err!=nil{ 99 });err!=nil{
98 return 100 return
99 } 101 }
100 - userInfo.ImToken = checkImResponse.ImToken 102 + if checkImResponse!=nil && checkImResponse.ImToken!=""{
  103 + userInfo.ImToken = checkImResponse.ImToken
  104 + }
101 if userInfo.CsAccount==0{ 105 if userInfo.CsAccount==0{
102 - userInfo.CsAccount = checkImResponse.CsAccount 106 + userInfo.CsAccount = imGetRandomCSAccount()
103 } 107 }
104 userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire) 108 userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire)
105 if err = UserRepository.UpdateUserInfoById(userInfo); err != nil { 109 if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
@@ -414,5 +418,22 @@ func imUserRefreshToken(request *protocol.CheckImRequest,rsp *protocol.CheckImRe @@ -414,5 +418,22 @@ func imUserRefreshToken(request *protocol.CheckImRequest,rsp *protocol.CheckImRe
414 rsp.ImToken = out.Info.Token 418 rsp.ImToken = out.Info.Token
415 return 419 return
416 } 420 }
  421 +// 获取客服id
  422 +func imGetRandomCSAccount()( acid int64){
  423 + kefus,err :=models.GetUsersKefu()
  424 + if err!=nil{
  425 + log.Error(err)
  426 + return
  427 + }
  428 + if len(kefus)<=0{
  429 + return
  430 + }
  431 + index :=rand.Intn(len(kefus))
  432 + acid,err = strconv.ParseInt(kefus[index].Accid,10,64)
  433 + if err!=nil{
  434 + log.Error(err)
  435 + }
  436 + return acid
  437 +}
417 438
418 439
@@ -71,4 +71,4 @@ func Test_RefreshToken(t *testing.T) { @@ -71,4 +71,4 @@ func Test_RefreshToken(t *testing.T) {
71 if rsp,err :=auth.RefreshToken(req);err!=nil{ 71 if rsp,err :=auth.RefreshToken(req);err!=nil{
72 t.Fatal(err,rsp) 72 t.Fatal(err,rsp)
73 } 73 }
74 -} 74 +}