dao.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package dao
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "go-common/app/interface/live/web-ucenter/conf"
  6. rank_api "go-common/app/service/live/rankdb/api/liverpc"
  7. rc_api "go-common/app/service/live/rc/api/liverpc"
  8. room_api "go-common/app/service/live/room/api/liverpc"
  9. "go-common/library/net/rpc/liverpc"
  10. "net/url"
  11. "strconv"
  12. "time"
  13. )
  14. // RoomAPI liverpc room-service api
  15. var RoomAPI *room_api.Client
  16. // RcApi liverpc rc api
  17. var RcApi *rc_api.Client
  18. // RankdbApi liverpc rankdb api
  19. var RankdbApi *rank_api.Client
  20. // InitAPI init all service APIs
  21. func InitAPI() {
  22. RoomAPI = room_api.New(getConf("room"))
  23. RcApi = rc_api.New(getConf("rc"))
  24. RankdbApi = rank_api.New(getConf("rank"))
  25. }
  26. func getConf(appName string) *liverpc.ClientConfig {
  27. c := conf.Conf.LiveRpc
  28. if c != nil {
  29. return c[appName]
  30. }
  31. return nil
  32. }
  33. // EncodeHttpParams end http params and return encoded string
  34. func EncodeHttpParams(params map[string]string, appKey, appSecret string) string {
  35. v := url.Values{}
  36. for key, value := range params {
  37. v.Set(key, value)
  38. }
  39. v.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  40. v.Set("appkey", appKey)
  41. tmp := v.Encode() + appSecret
  42. mh := md5.Sum([]byte(tmp))
  43. sign := hex.EncodeToString(mh[:])
  44. v.Set("sign", sign)
  45. return v.Encode()
  46. }