互动
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.

84 lines
2.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package im
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/kirinlabs/HttpRequest"
  7. "hudongzhuanjia/utils"
  8. )
  9. func AccountImport(identifier, nickname, faceurl string) (string, error) {
  10. //sign, err := tencentyun.GenSig(SdkAppid, SdkAppKey, "admin", 86400*180)
  11. sig, err := GenSig("admin")
  12. if err != nil {
  13. return "", err
  14. }
  15. random := utils.RandomStr(32)
  16. u := fmt.Sprintf("%s/im_open_login_svc/account_import?sdkappid=%d&identifier=admin&usersig=%s&random=%s&contenttype=json",
  17. TxImHostV4, SdkAppid, sig, random)
  18. bs, _ := json.Marshal(&AccountImportParam{
  19. Identifier: identifier,
  20. Nick: nickname,
  21. FaceUrl: faceurl,
  22. })
  23. resp, err := HttpRequest.NewRequest().Debug(true).JSON().Post(u, string(bs))
  24. if err != nil {
  25. return "", err
  26. }
  27. res := CommonResult{}
  28. err = resp.Json(&res)
  29. if err != nil {
  30. return "", err
  31. }
  32. if res.ErrorCode != 0 {
  33. return "", errors.New(res.ErrorInfo)
  34. }
  35. //return tencentyun.GenSig(SdkAppid, SdkAppKey, identifier, 86400000)
  36. return GenSig(identifier)
  37. }
  38. // 群通知
  39. type SendGroupSystemNotificationParam struct {
  40. GroupId string `json:"GroupId"`
  41. Content string `json:"Content"`
  42. ToMembersAccount []string `json:"ToMembers_Account,omitempty"`
  43. }
  44. func SendGroupSystemNotification(groupId string, status NoticeStatus, data map[string]interface{}, members ...string) error {
  45. sig, err := GenSig("admin")
  46. if err != nil {
  47. return err
  48. }
  49. random := utils.RandomStr(32)
  50. u := fmt.Sprintf("%s/group_open_http_svc/send_group_system_notification?sdkappid=%d&identifier=admin&usersig=%s&random=%s&contenttype=json",
  51. TxImHostV4, SdkAppid, sig, random)
  52. var m = make(map[string]interface{})
  53. m["status"] = status
  54. m["data"] = data
  55. content, err := json.Marshal(&m)
  56. if err != nil {
  57. return err
  58. }
  59. bs, err := json.Marshal(&SendGroupSystemNotificationParam{
  60. GroupId: groupId,
  61. Content: string(content),
  62. ToMembersAccount: members,
  63. })
  64. if err != nil {
  65. return err
  66. }
  67. resp, err := HttpRequest.NewRequest().Debug(true).JSON().Post(u, string(bs))
  68. res := CommonResult{}
  69. err = resp.Json(&res)
  70. if err != nil {
  71. return err
  72. }
  73. if res.ErrorCode != 0 {
  74. return errors.New(res.ErrorInfo)
  75. }
  76. return nil
  77. }