|
|
- package siterpc
-
- import (
- "encoding/json"
- "log"
- "strconv"
- "time"
-
- "git.tetele.net/tgo/crypter"
-
- "github.com/golang/protobuf/proto"
- )
-
- type SiteInfoReq struct {
- Master string
- Host string
- }
-
- type SiteInfoRes struct {
- SiteId string `json:"site_id"`
- Dbname string `json:"database"`
- Domainname string `json:"domainname"`
- }
-
- /**
- * 由host取对应站点关键信息
- * 请求及回均加密验签
- * 2021/06/24
- * GZ
- */
- func GetSiteInfoByHost(master, host string, url ...string) (*SiteInfoRes, error) {
-
- conn, err := rpc_server_conn(url...)
- if err != nil {
- return nil, err
- }
- defer conn.Close()
-
- arg := SiteInfoReq{master, host}
-
- data_json, err := json.Marshal(arg)
- if err != nil {
- return nil, err
- }
- now_int64 := time.Now().Unix()
-
- encryData := crypter.DesEn(string(data_json), DES_KEY)
-
- now := strconv.FormatInt(now_int64, 10)
-
- sign := Sign(encryData, now)
-
- req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
-
- res := &Response{}
-
- err = conn.GetSiteInfoByHost(req, res)
-
- if err != nil {
- return nil, err
- }
-
- res_data, err := GetOrgData(res)
-
- log.Println(res_data, err)
-
- if err != nil {
- return nil, err
- }
- var res_arr SiteInfoRes
-
- err = json.Unmarshal([]byte(res_data), &res_arr)
-
- if err != nil {
- return nil, err
- }
- return &res_arr, nil
- }
|