消息服务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.8 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, thumb 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.Thumb = thumb
  67. arg.TemplateData = template_Data
  68. data_json, err := json.Marshal(arg)
  69. if err != nil {
  70. return false, err
  71. }
  72. now_int64 := time.Now().Unix()
  73. encryData := crypter.DesEn(string(data_json), DES_KEY)
  74. now := strconv.FormatInt(now_int64, 10)
  75. sign := Sign(encryData, now)
  76. req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
  77. res := &Response{}
  78. err = conn.SendNotcie(req, res)
  79. if err != nil {
  80. log.Println("msgrpc SendNotcie error:", err)
  81. return false, err
  82. }
  83. res_data, err := GetOrgData(res)
  84. if err != nil {
  85. return false, err
  86. }
  87. if res_data == "" {
  88. return false, nil
  89. }
  90. var notice_res bool
  91. err = json.Unmarshal([]byte(res_data), &notice_res)
  92. if err != nil {
  93. return false, err
  94. }
  95. return notice_res, nil
  96. }