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

135 lines
2.4 KiB

  1. package msgrpc
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "log"
  6. "strconv"
  7. "time"
  8. "git.tetele.net/tgo/crypter"
  9. "github.com/golang/protobuf/proto"
  10. )
  11. func SendMsg(site_id, dbname, business_id, domainname, msg_type, order_sn, memo string, data interface{}, url ...string) (*MsgSend, error) {
  12. conn, err := rpc_server_conn(url...)
  13. if err != nil {
  14. return nil, err
  15. }
  16. defer conn.Close()
  17. arg_data, err := json.Marshal(data)
  18. if err != nil {
  19. log.Println("json marshal error:", err)
  20. }
  21. arg := MsgBody{}
  22. arg.SiteId = site_id
  23. arg.Dbname = dbname
  24. arg.Platform = "1"
  25. arg.BusinessId = business_id
  26. arg.Domainname = domainname
  27. arg.Type = msg_type
  28. arg.Data = string(arg_data)
  29. arg.OrderSn = order_sn
  30. arg.Memo = memo
  31. data_json, err := json.Marshal(arg)
  32. if err != nil {
  33. return nil, err
  34. }
  35. now_int64 := time.Now().Unix()
  36. encryData := crypter.DesEn(string(data_json), DES_KEY)
  37. now := strconv.FormatInt(now_int64, 10)
  38. sign := Sign(encryData, now)
  39. req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
  40. res := &Response{}
  41. err = conn.SendMsg(req, res)
  42. if err != nil {
  43. return nil, err
  44. }
  45. res_data, err := GetOrgData(res)
  46. var res_arr MsgSend
  47. err = json.Unmarshal([]byte(res_data), &res_arr)
  48. if err != nil {
  49. return nil, err
  50. }
  51. return &res_arr, nil
  52. }
  53. func SendNotcie(site_id, dbname, manager_id string, template_Data map[string]string, url ...string) (bool, error) {
  54. if dbname == "" || dbname == "" || manager_id == ""{
  55. return false, errors.New("参数错误")
  56. }
  57. conn, err := rpc_server_conn(url...)
  58. if err != nil {
  59. return false, err
  60. }
  61. defer conn.Close()
  62. arg := NoticeSend{}
  63. arg.SiteId = site_id
  64. arg.Dbname = dbname
  65. arg.ManagerId = manager_id
  66. arg.TemplateData = template_Data
  67. data_json, err := json.Marshal(arg)
  68. if err != nil {
  69. return false, err
  70. }
  71. now_int64 := time.Now().Unix()
  72. encryData := crypter.DesEn(string(data_json), DES_KEY)
  73. now := strconv.FormatInt(now_int64, 10)
  74. sign := Sign(encryData, now)
  75. req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
  76. res := &Response{}
  77. err = conn.SendNotcie(req, res)
  78. if err != nil {
  79. log.Println("msgrpc SendNotcie error:", err)
  80. return false, err
  81. }
  82. res_data, err := GetOrgData(res)
  83. if err != nil {
  84. return false, err
  85. }
  86. if res_data == "" {
  87. return false, nil
  88. }
  89. var notice_res bool
  90. err = json.Unmarshal([]byte(res_data), &notice_res)
  91. if err != nil {
  92. return false, err
  93. }
  94. return notice_res, nil
  95. }