| @ -1,109 +1,106 @@ | |||
| package site | |||
| import ( | |||
| "crypto/md5" | |||
| "encoding/hex" | |||
| "encoding/json" | |||
| "errors" | |||
| "strconv" | |||
| "strings" | |||
| "time" | |||
| // import ( | |||
| // "encoding/json" | |||
| // "errors" | |||
| // "strconv" | |||
| // "time" | |||
| "git.tetele.net/tgo/crypter" | |||
| // "git.tetele.net/tgo/crypter" | |||
| "github.com/golang/protobuf/proto" | |||
| ) | |||
| // "github.com/golang/protobuf/proto" | |||
| // ) | |||
| type SiteBalanceTypeReqArg struct { | |||
| SiteId string `json:"site_id"` | |||
| Dbname string `json:"dbname"` | |||
| } | |||
| // type SiteBalanceTypeReqArg struct { | |||
| // SiteId string `json:"site_id"` | |||
| // Dbname string `json:"dbname"` | |||
| // } | |||
| type SiteBalanceType struct { | |||
| Id string | |||
| Name string | |||
| UseLimit string | |||
| Unit string | |||
| Type string | |||
| CleanRate string | |||
| CleanTime string | |||
| } | |||
| // type SiteBalanceType struct { | |||
| // Id string | |||
| // Name string | |||
| // UseLimit string | |||
| // Unit string | |||
| // Type string | |||
| // CleanRate string | |||
| // CleanTime string | |||
| // } | |||
| /** | |||
| * 由配置key取对应value | |||
| * 请求及回均加密验签 | |||
| * 2021/01/20 | |||
| * GZ | |||
| */ | |||
| func GetBalanceType(site_id, dbname string, url ...string) (*[]SiteBalanceType, error) { | |||
| // /** | |||
| // * 由配置key取对应value | |||
| // * 请求及回均加密验签 | |||
| // * 2021/01/20 | |||
| // * GZ | |||
| // */ | |||
| // func GetBalanceType(site_id, dbname string, url ...string) (*[]SiteBalanceType, error) { | |||
| var site_rpc_url string = "127.0.0.1:7971" | |||
| if len(url) > 0 && url[0] != "" { | |||
| site_rpc_url = url[0] | |||
| } | |||
| conn, _, err := DialSiteService("tcp", site_rpc_url) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| defer conn.Close() | |||
| // var site_rpc_url string = "127.0.0.1:7971" | |||
| // if len(url) > 0 && url[0] != "" { | |||
| // site_rpc_url = url[0] | |||
| // } | |||
| // conn, _, err := DialSiteService("tcp", site_rpc_url) | |||
| // if err != nil { | |||
| // return nil, err | |||
| // } | |||
| // defer conn.Close() | |||
| arg := SiteConfigItemReqArg{site_id, dbname, key} | |||
| // arg := SiteConfigItemReqArg{site_id, dbname, key} | |||
| data_json, err := json.Marshal(arg) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| now_int64 := time.Now().Unix() | |||
| // data_json, err := json.Marshal(arg) | |||
| // if err != nil { | |||
| // return nil, err | |||
| // } | |||
| // now_int64 := time.Now().Unix() | |||
| encryData := crypter.DesEn(string(data_json), "confdata") | |||
| // encryData := crypter.DesEn(string(data_json), "confdata") | |||
| now := strconv.FormatInt(now_int64, 10) | |||
| // now := strconv.FormatInt(now_int64, 10) | |||
| sign := Sign(encryData, now) | |||
| // sign := Sign(encryData, now) | |||
| req := &ConfigRequest{proto.String(encryData), proto.String(now), proto.String(sign), nil} | |||
| // req := &ConfigRequest{proto.String(encryData), proto.String(now), proto.String(sign), nil} | |||
| res := &ConfigResponse{} | |||
| // res := &ConfigResponse{} | |||
| err = conn.GetConfig(req, res) | |||
| // err = conn.GetConfig(req, res) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| // if err != nil { | |||
| // return nil, err | |||
| // } | |||
| res_data := res.GetData() | |||
| // res_data := res.GetData() | |||
| if res_data != "" { | |||
| // if res_data != "" { | |||
| time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| // time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) | |||
| // if err != nil { | |||
| // return nil, err | |||
| // } | |||
| now_int64 = time.Now().Unix() | |||
| // now_int64 = time.Now().Unix() | |||
| if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
| //时间误差前后10秒,返回 | |||
| return nil, errors.New("返回时间错误") | |||
| } | |||
| // if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
| // //时间误差前后10秒,返回 | |||
| // return nil, errors.New("返回时间错误") | |||
| // } | |||
| check_sign := CheckSign(res.GetSign(), res_data, res.GetTime()) | |||
| if !check_sign { | |||
| return nil, errors.New("返回数据签名错误") | |||
| } | |||
| // check_sign := CheckSign(res.GetSign(), res_data, res.GetTime()) | |||
| // if !check_sign { | |||
| // return nil, errors.New("返回数据签名错误") | |||
| // } | |||
| //解密 | |||
| res_data_de := crypter.DesDe(res_data, "confdata") | |||
| // //解密 | |||
| // res_data_de := crypter.DesDe(res_data, "confdata") | |||
| var res_arr []SiteBalanceType | |||
| // var res_arr []SiteBalanceType | |||
| err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
| // err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| return &res_arr, nil | |||
| } | |||
| // if err != nil { | |||
| // return nil, err | |||
| // } | |||
| // return &res_arr, nil | |||
| // } | |||
| return nil, nil | |||
| } | |||
| // return nil, nil | |||
| // } | |||