用户接口远程调用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

150 lines
2.5 KiB

package userrpc
import (
"encoding/json"
"errors"
"strconv"
"time"
"git.tetele.net/tgo/crypter"
"github.com/golang/protobuf/proto"
)
/**
* 查找商户信息
* 2021/04/06
* gz
*/
func GetBusiness(site_id, dbname, business_id string, url ...string) (*Business, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
data := GetBusinessReq{}
data.SiteId = site_id
data.Dbname = dbname
data.BusinessId = business_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 := &Request{
proto.String(encryData),
proto.String(now),
proto.String(sign),
nil}
res := &Response{}
err = conn.GetBusiness(req, res)
if err != nil {
return nil, err
}
return HandleGetBusinessRes(res)
}
/**
* 处理返回结果
*/
func HandleGetBusinessRes(res *Response) (*Business, 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, DES_KEY)
var res_arr Business
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return &res_arr, nil
}
func GetBusinessInfo(site_id, dbname, id 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()
data := GetBusinessReq{}
data.SiteId = site_id
data.Dbname = dbname
data.BusinessId = id
req, err := SetReqData(data)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.GetBusinessInfo(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
}