站点RPC方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.4 KiB

  1. package siterpc
  2. import (
  3. "encoding/json"
  4. "log"
  5. "strconv"
  6. "time"
  7. "git.tetele.net/tgo/crypter"
  8. "github.com/golang/protobuf/proto"
  9. )
  10. type SiteInfoReq struct {
  11. Master string
  12. Host string
  13. }
  14. type SiteInfoRes struct {
  15. SiteId string `json:"site_id"`
  16. Dbname string `json:"database"`
  17. Domainname string `json:"domainname"`
  18. }
  19. /**
  20. * 由host取对应站点关键信息
  21. * 请求及回均加密验签
  22. * 2021/06/24
  23. * GZ
  24. */
  25. func GetSiteInfoByHost(host string, params ...string) (*SiteInfoRes, error) {
  26. var url string = ""
  27. var master string = ""
  28. if len(params) > 1 {
  29. master = params[1]
  30. }
  31. if len(params) > 0 {
  32. url = params[0]
  33. }
  34. conn, err := rpc_server_conn(url)
  35. if err != nil {
  36. return nil, err
  37. }
  38. defer conn.Close()
  39. arg := SiteInfoReq{master, host}
  40. data_json, err := json.Marshal(arg)
  41. if err != nil {
  42. return nil, err
  43. }
  44. now_int64 := time.Now().Unix()
  45. encryData := crypter.DesEn(string(data_json), DES_KEY)
  46. now := strconv.FormatInt(now_int64, 10)
  47. sign := Sign(encryData, now)
  48. req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
  49. res := &Response{}
  50. err = conn.GetSiteInfoByHost(req, res)
  51. if err != nil {
  52. return nil, err
  53. }
  54. res_data, err := GetOrgData(res)
  55. log.Println(res_data, err)
  56. if err != nil {
  57. return nil, err
  58. }
  59. var res_arr SiteInfoRes
  60. err = json.Unmarshal([]byte(res_data), &res_arr)
  61. if err != nil {
  62. return nil, err
  63. }
  64. return &res_arr, nil
  65. }