package orderrpc import ( "errors" "strconv" "time" "git.tetele.net/tgo/crypter" ) 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 "", errors.New("未收到收据") } 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("返回数据签名错误") } //解密 res_data_de := crypter.DesDe(res_data, "ordernew") return res_data_de, nil } /** * 处理返回结果 */ func GetOrgData(res *Response) (string, error) { res_data := res.GetData() if res_data == "" { return "", errors.New("未收到收据") } 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("返回数据签名错误") } //解密 res_data_de := crypter.DesDe(res_data, DES_KEY) return res_data_de, nil }