From 32966f913d26ec36b87fc87cc3675637504c88c4 Mon Sep 17 00:00:00 2001 From: guzeng Date: Wed, 2 Jun 2021 16:10:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0mod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cancel.go | 75 -------------------------------------------------- client.go | 2 +- client_test.go | 2 +- common.go | 54 ------------------------------------ go.mod | 3 ++ order.pb.go | 4 +-- order.proto | 2 +- 7 files changed, 8 insertions(+), 134 deletions(-) delete mode 100644 cancel.go delete mode 100644 common.go create mode 100644 go.mod diff --git a/cancel.go b/cancel.go deleted file mode 100644 index d71ca31..0000000 --- a/cancel.go +++ /dev/null @@ -1,75 +0,0 @@ -package order - -import ( - "crypto/md5" - "encoding/hex" - "encoding/json" - "errors" - "log" - "strconv" - "strings" - "time" - - "git.tetele.net/tgo/crypter" - - "github.com/golang/protobuf/proto" -) - -type OrderCancelRes struct { - Success bool -} - -func Cancel(dbname, site_id string, order_id string, url ...string) (*OrderCancelRes, error) { - - conn, err := rpc_server_conn(url...) - if err != nil { - return nil, err - } - defer conn.Close() - - data := map[string]string{ - "dbname": dbname, - "site_id": site_id, - "order_id": order_id, - } - - data_json, err := json.Marshal(data) - if err != nil { - return nil, err - } - - encryData := crypter.DesEn(string(data_json), DES_KEY) - - now_int64 := time.Now().Unix() - - now := strconv.FormatInt(now_int64, 10) - - sign := Sign(encryData, now) - - req := &CreateRequest{ - proto.String(encryData), - proto.String(now), - proto.String(sign), - nil} - - res := &CreateResponse{} - - err = conn.Cancel(req, res) - - if err != nil { - return nil, err - } - - res_data, err := HandleResponse(res) - - var res_arr OrderCancelRes - - err = json.Unmarshal([]byte(res_data_de), &res_arr) - - if err != nil { - return nil, err - } - - return &res_arr, nil - -} diff --git a/client.go b/client.go index 539c9ef..0d230ab 100644 --- a/client.go +++ b/client.go @@ -1,4 +1,4 @@ -package order +package orderrpc import ( "crypto/md5" diff --git a/client_test.go b/client_test.go index aa57085..3b7ec4b 100644 --- a/client_test.go +++ b/client_test.go @@ -1,4 +1,4 @@ -package order +package orderrpc import ( "testing" diff --git a/common.go b/common.go deleted file mode 100644 index 4a8eae8..0000000 --- a/common.go +++ /dev/null @@ -1,54 +0,0 @@ -package order - -const DES_KEY = "ordernew" - -func rpc_server_conn(url ...string) (*OrderServiceClient, error) { - - var order_rpc_url string = "127.0.0.1:7973" - if len(url) > 0 && url[0] != "" { - order_rpc_url = url[0] - } - - conn, _, err := DialOrderService("tcp", order_rpc_url) - if err != nil { - return nil, err - } - - return conn, nil -} - -/** - * 处理返回结果 - */ -func HandleResponse(res *CreateResponse) (string, error) { - - res_data := res.GetData() - - if res_data == "" { - - return nil, errors.New("未收到收据") - } - - time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) - if err != nil { - return nil, err - } - - now_int64 := time.Now().Unix() - - 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("返回数据签名错误") - } - - //解密 - res_data_de := crypter.DesDe(res_data, "ordernew") - - return res_data_de - -} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8418bf5 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.tetele.net/tgo/orderrpc + +go 1.14 diff --git a/order.pb.go b/order.pb.go index 88ac4ea..bf23c9d 100644 --- a/order.pb.go +++ b/order.pb.go @@ -3,7 +3,7 @@ // DO NOT EDIT! /* -Package order is a generated protocol buffer package. +Package orderrpc is a generated protocol buffer package. It is generated from these files: order.proto @@ -12,7 +12,7 @@ It has these top-level messages: CreateRequest CreateResponse */ -package order +package orderrpc import proto "github.com/chai2010/protorpc/proto" import math "math" diff --git a/order.proto b/order.proto index 4cf54b3..5dfb931 100644 --- a/order.proto +++ b/order.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package order; +package orderrpc; // 下单请求结构 message CreateRequest {