消息服务RPC
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.

71 lines
1.3 KiB

  1. package msgrpc
  2. import (
  3. "encoding/json"
  4. "log"
  5. "strconv"
  6. "time"
  7. "git.tetele.net/tgo/crypter"
  8. "github.com/golang/protobuf/proto"
  9. )
  10. func SendMsg(site_id, dbname, business_id, domainname, msg_type, order_sn, memo string, data interface{}, url ...string) (*MsgSend, error) {
  11. conn, err := rpc_server_conn(url...)
  12. if err != nil {
  13. return nil, err
  14. }
  15. defer conn.Close()
  16. arg_data, err := json.Marshal(data)
  17. if err != nil {
  18. log.Println("json marshal error:", err)
  19. }
  20. arg := MsgBody{}
  21. arg.SiteId = site_id
  22. arg.Dbname = dbname
  23. arg.Platform = "1"
  24. arg.BusinessId = business_id
  25. arg.Domainname = domainname
  26. arg.Type = msg_type
  27. arg.Data = string(arg_data)
  28. arg.OrderSn = order_sn
  29. arg.Memo = memo
  30. data_json, err := json.Marshal(arg)
  31. if err != nil {
  32. return nil, err
  33. }
  34. now_int64 := time.Now().Unix()
  35. encryData := crypter.DesEn(string(data_json), DES_KEY)
  36. now := strconv.FormatInt(now_int64, 10)
  37. sign := Sign(encryData, now)
  38. req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
  39. res := &Response{}
  40. err = conn.SendMsg(req, res)
  41. if err != nil {
  42. return nil, err
  43. }
  44. res_data, err := GetOrgData(res)
  45. var res_arr MsgSend
  46. err = json.Unmarshal([]byte(res_data), &res_arr)
  47. if err != nil {
  48. return nil, err
  49. }
  50. return &res_arr, nil
  51. }