8 Commits

Author SHA1 Message Date
  guzeng 639c701dec 修改查询条件 3 years ago
  guzeng 7077ff0fff 查询方法增加查询字段 3 years ago
  guzeng 0cbfce0db4 增加Get380Star方法 3 years ago
  guzeng 1838e087aa 修改调用方法 3 years ago
  guzeng 95ea9b3433 debug 3 years ago
  guzeng dfdf026195 变量集中单个文件 3 years ago
  guzeng bf3dace594 debug 3 years ago
  guzeng 61438902bd 修改调用方法 3 years ago
11 changed files with 247 additions and 56 deletions
Split View
  1. +47
    -15
      client.info.go
  2. +2
    -2
      client.info_test.go
  3. +47
    -3
      client.is_open.go
  4. +17
    -0
      client.is_open_test.go
  5. +0
    -2
      conn.go
  6. +37
    -7
      data.go
  7. +3
    -2
      go.mod
  8. +0
    -5
      sign.go
  9. +53
    -14
      supplier.pb.go
  10. +14
    -6
      supplier.proto
  11. +27
    -0
      variable.go

+ 47
- 15
client.info.go View File

@ -5,21 +5,53 @@ import (
"errors"
)
type GetParam struct {
SiteId string `json:"site_id"`
Dbname string `json:"database"`
Id string `json:"id"`
}
func Get(site_id, dbname, id string, field string, url ...string) (map[string]string, error) {
if dbname == "" || id == "" {
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
arg := ReqParam{site_id, dbname, id, field}
req, err := SetReqData(arg)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.Get(req, res)
if err != nil {
return nil, err
}
res_data_de, err := GetResData(res)
if err != nil {
return nil, err
}
if res_data_de == "" {
return nil, nil
}
var res_arr map[string]string
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return res_arr, nil
type GetUuidParam struct {
SiteId string `json:"site_id"`
Dbname string `json:"database"`
Uuid string `json:"uuid"`
}
func Get(site_id, dbname, id string, url ...string) (map[string]string, error) {
func Get380Star(site_id, dbname string, field string, url ...string) (map[string]string, error) {
if dbname == "" || id == "" {
if dbname == "" {
return nil, errors.New("参数错误")
}
@ -29,21 +61,21 @@ func Get(site_id, dbname, id string, url ...string) (map[string]string, error) {
}
defer conn.Close()
arg := GetParam{site_id, dbname, id}
arg := ReqParam{site_id, dbname, "", field}
req, err := SetReqData(arg)
if err != nil {
return nil, err
}
res := &Params{}
res := &Response{}
err = conn.Get(req, res)
err = conn.Get380Star(req, res)
if err != nil {
return nil, err
}
res_data_de, err := GetData(res)
res_data_de, err := GetResData(res)
if err != nil {
return nil, err
}


+ 2
- 2
client.info_test.go View File

@ -7,9 +7,9 @@ import (
func Test_Get(t *testing.T) {
siteid := "1056475"
dbname := "shop_v2"
key := "1"
key := "*"
res, err := Get(siteid, dbname, key)
res, err := Get380Star(siteid, dbname, key)
t.Log(res)
t.Log(err)


+ 47
- 3
client.is_open.go View File

@ -1,6 +1,50 @@
package supplierrpc
type BoolRet struct {
Value bool `json:"value"`
Msg string `json:"msg"`
import (
"encoding/json"
"errors"
)
func IsOpen(site_id, dbname, id string, url ...string) (*BoolRet, error) {
if dbname == "" || id == "" {
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
arg := GetParam{site_id, dbname, id}
req, err := SetReqData(arg)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.IsOpen(req, res)
if err != nil {
return nil, err
}
res_data_de, err := GetResData(res)
if err != nil {
return nil, err
}
if res_data_de == "" {
return nil, nil
}
var res_arr BoolRet
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return &res_arr, nil
}

+ 17
- 0
client.is_open_test.go View File

@ -0,0 +1,17 @@
package supplierrpc
import (
"testing"
)
func Test_IsOpen(t *testing.T) {
siteid := "1056475"
dbname := "shop_v2"
key := "1"
res, err := IsOpen(siteid, dbname, key)
t.Log(res)
t.Log(res.Value)
t.Log(err)
}

+ 0
- 2
conn.go View File

@ -4,8 +4,6 @@ import (
"git.tetele.net/tgo/conf"
)
var DES_KEY = "suppli22"
func rpc_server_conn(url ...string) (*SupplierServiceClient, error) {
var rpc_url string


+ 37
- 7
data.go View File

@ -10,7 +10,7 @@ import (
"github.com/golang/protobuf/proto"
)
func SetResData(data interface{}, res *Params) {
func SetResData(data interface{}, res *Response) {
res_data_json, err := json.Marshal(data)
if err == nil {
@ -27,7 +27,7 @@ func SetResData(data interface{}, res *Params) {
}
func SetReqData(arg interface{}) (*Params, error) {
func SetReqData(arg interface{}) (*Request, error) {
data_json, err := json.Marshal(arg)
if err != nil {
return nil, err
@ -41,16 +41,16 @@ func SetReqData(arg interface{}) (*Params, error) {
sign := Sign(encryData, now)
return &Params{proto.String(encryData), proto.String(now), proto.String(sign), nil}, nil
return &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}, nil
}
func GetData(param *Params) (string, error) {
res_data := param.GetData()
func GetReqData(req *Request) (string, error) {
res_data := req.GetData()
if res_data != "" {
time_int64, err := strconv.ParseInt(param.GetTime(), 10, 64)
time_int64, err := strconv.ParseInt(req.GetTime(), 10, 64)
if err != nil {
return "", err
}
@ -62,7 +62,37 @@ func GetData(param *Params) (string, error) {
return "", errors.New("返回时间错误")
}
check_sign := CheckSign(param.GetSign(), res_data, param.GetTime())
check_sign := CheckSign(req.GetSign(), res_data, req.GetTime())
if !check_sign {
return "", errors.New("返回数据签名错误")
}
//解密
return crypter.DesDe(res_data, DES_KEY), nil
}
return "", nil
}
func GetResData(res *Response) (string, error) {
res_data := res.GetData()
if res_data != "" {
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64)
if err != nil {
return "", err
}
now_int64 := time.Now().Unix()
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 {
//时间误差前后10秒,返回
return "", errors.New("返回时间错误")
}
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime())
if !check_sign {
return "", errors.New("返回数据签名错误")
}


+ 3
- 2
go.mod View File

@ -4,8 +4,9 @@ go 1.14
require (
git.tetele.net/tgo/conf v0.34.1 // indirect
git.tetele.net/tgo/crypter v0.2.2 // indirect
github.com/chai2010/protorpc v1.1.3 // indirect
git.tetele.net/tgo/crypter v0.2.2
github.com/chai2010/protorpc v1.1.3
github.com/golang/protobuf v1.0.0
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
)

+ 0
- 5
sign.go View File

@ -3,12 +3,7 @@ package supplierrpc
import (
"crypto/md5"
"encoding/hex"
"errors"
"strconv"
"strings"
"time"
"git.tetele.net/tgo/crypter"
)
/**


+ 53
- 14
supplier.pb.go View File

@ -9,7 +9,8 @@ It is generated from these files:
supplier.proto
It has these top-level messages:
Params
Request
Response
*/
package supplierrpc
@ -27,32 +28,66 @@ import protorpc "github.com/chai2010/protorpc"
var _ = proto.Marshal
var _ = math.Inf
type Params struct {
// 配置信息请求结构
type Request struct {
Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
Time *string `protobuf:"bytes,2,opt,name=time" json:"time,omitempty"`
Sign *string `protobuf:"bytes,3,opt,name=sign" json:"sign,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Params) Reset() { *m = Params{} }
func (m *Params) String() string { return proto.CompactTextString(m) }
func (*Params) ProtoMessage() {}
func (m *Request) Reset() { *m = Request{} }
func (m *Request) String() string { return proto.CompactTextString(m) }
func (*Request) ProtoMessage() {}
func (m *Params) GetData() string {
func (m *Request) GetData() string {
if m != nil && m.Data != nil {
return *m.Data
}
return ""
}
func (m *Params) GetTime() string {
func (m *Request) GetTime() string {
if m != nil && m.Time != nil {
return *m.Time
}
return ""
}
func (m *Params) GetSign() string {
func (m *Request) GetSign() string {
if m != nil && m.Sign != nil {
return *m.Sign
}
return ""
}
// 配置信息响应结构
type Response struct {
Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
Time *string `protobuf:"bytes,2,opt,name=time" json:"time,omitempty"`
Sign *string `protobuf:"bytes,3,opt,name=sign" json:"sign,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (m *Response) GetData() string {
if m != nil && m.Data != nil {
return *m.Data
}
return ""
}
func (m *Response) GetTime() string {
if m != nil && m.Time != nil {
return *m.Time
}
return ""
}
func (m *Response) GetSign() string {
if m != nil && m.Sign != nil {
return *m.Sign
}
@ -63,9 +98,10 @@ func init() {
}
type SupplierService interface {
Get(in *Params, out *Params) error
GetByUuid(in *Params, out *Params) error
IsOpen(in *Params, out *Params) error
Get(in *Request, out *Response) error
GetByUuid(in *Request, out *Response) error
IsOpen(in *Request, out *Response) error
Get380Star(in *Request, out *Response) error
}
// AcceptSupplierServiceClient accepts connections on the listener and serves requests
@ -137,15 +173,18 @@ func NewSupplierServiceClient(conn io.ReadWriteCloser) (*SupplierServiceClient,
return &SupplierServiceClient{c}, c
}
func (c *SupplierServiceClient) Get(in *Params, out *Params) error {
func (c *SupplierServiceClient) Get(in *Request, out *Response) error {
return c.Call("SupplierService.Get", in, out)
}
func (c *SupplierServiceClient) GetByUuid(in *Params, out *Params) error {
func (c *SupplierServiceClient) GetByUuid(in *Request, out *Response) error {
return c.Call("SupplierService.GetByUuid", in, out)
}
func (c *SupplierServiceClient) IsOpen(in *Params, out *Params) error {
func (c *SupplierServiceClient) IsOpen(in *Request, out *Response) error {
return c.Call("SupplierService.IsOpen", in, out)
}
func (c *SupplierServiceClient) Get380Star(in *Request, out *Response) error {
return c.Call("SupplierService.Get380Star", in, out)
}
// DialSupplierService connects to an SupplierService at the specified network address.
func DialSupplierService(network, addr string) (*SupplierServiceClient, *rpc.Client, error) {


+ 14
- 6
supplier.proto View File

@ -1,16 +1,24 @@
syntax = "proto3";
package supplierrpc;
message Params {
//
message Request {
string data = 1;
string time = 2;
string sign = 3;
}
//
message Response {
string data = 1;
string time = 2;
string sign = 3;
}
// rpc方法
service SupplierService {
rpc Get (Params) returns (Params); // 使id查询
rpc GetByUuid (Params) returns (Params); // 使uuid查询
rpc IsOpen (Params) returns (Params); //
rpc Get (Request) returns (Response); // 使id查询
rpc GetByUuid (Request) returns (Response); // 使uuid查询
rpc IsOpen (Request) returns (Response); //
rpc Get380Star (Request) returns (Response); // 380star供应商数据
}

+ 27
- 0
variable.go View File

@ -0,0 +1,27 @@
package supplierrpc
var DES_KEY = "suppli22"
type GetParam struct {
SiteId string `json:"site_id"`
Dbname string `json:"database"`
Id string `json:"id"`
}
type GetUuidParam struct {
SiteId string `json:"site_id"`
Dbname string `json:"database"`
Uuid string `json:"uuid"`
Field string `json:"field"`
}
type BoolRet struct {
Value bool `json:"value"`
Msg string `json:"msg"`
}
type ReqParam struct {
SiteId string `json:"site_id"`
Dbname string `json:"database"`
Id string `json:"id"`
Field string `json:"field"`
}

Loading…
Cancel
Save