Browse Source

增加mod

master v0.2.2
guzeng 3 years ago
parent
commit
32966f913d
7 changed files with 8 additions and 134 deletions
  1. +0
    -75
      cancel.go
  2. +1
    -1
      client.go
  3. +1
    -1
      client_test.go
  4. +0
    -54
      common.go
  5. +3
    -0
      go.mod
  6. +2
    -2
      order.pb.go
  7. +1
    -1
      order.proto

+ 0
- 75
cancel.go View File

@ -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
}

+ 1
- 1
client.go View File

@ -1,4 +1,4 @@
package order
package orderrpc
import ( import (
"crypto/md5" "crypto/md5"


+ 1
- 1
client_test.go View File

@ -1,4 +1,4 @@
package order
package orderrpc
import ( import (
"testing" "testing"


+ 0
- 54
common.go View File

@ -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
}

+ 3
- 0
go.mod View File

@ -0,0 +1,3 @@
module git.tetele.net/tgo/orderrpc
go 1.14

+ 2
- 2
order.pb.go View File

@ -3,7 +3,7 @@
// DO NOT EDIT! // 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: It is generated from these files:
order.proto order.proto
@ -12,7 +12,7 @@ It has these top-level messages:
CreateRequest CreateRequest
CreateResponse CreateResponse
*/ */
package order
package orderrpc
import proto "github.com/chai2010/protorpc/proto" import proto "github.com/chai2010/protorpc/proto"
import math "math" import math "math"


+ 1
- 1
order.proto View File

@ -1,5 +1,5 @@
syntax = "proto3"; syntax = "proto3";
package order;
package orderrpc;
// //
message CreateRequest { message CreateRequest {


Loading…
Cancel
Save