sendMsg.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "log"
  7. qu "app.yhyue.com/moapp/jybase/common"
  8. "app.yhyue.com/moapp/jybase/date"
  9. cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
  10. "github.com/gogf/gf/v2/frame/g"
  11. )
  12. //将用户格式化成 123,456 格式
  13. func FormatUserId(useridArr []string) (userids string) {
  14. userids = ""
  15. for k, v := range useridArr {
  16. userids += v
  17. if k+1 != len(useridArr) {
  18. userids += ","
  19. }
  20. }
  21. return
  22. }
  23. //站内信推送
  24. func StationMailPush(userIds, positionIds, title, content, pcLandingPage, appLandingPage, wxLandingPage string) {
  25. href := fmt.Sprintf("%s?_action=%s&userIds=%s&msgType=11&title=%s&content=%s&link=%s&sendMode=2&sendTime=%s&androidUrl=%s&iosUrl=%s&weChatUrl=%s&_token=12311&reqSource=1&callPlatform=crm&menuname=message&positionIds=%s",
  26. cm.C.StationMailHref, cm.C.StationMailAction, userIds, title, content, pcLandingPage, date.NowFormat(date.Date_Short_Layout), appLandingPage, appLandingPage, wxLandingPage, positionIds)
  27. log.Println(href)
  28. resp := Get(href, nil)
  29. log.Println(resp)
  30. ret := map[string]interface{}{}
  31. err := json.Unmarshal([]byte(resp), &ret)
  32. if err != nil {
  33. log.Println(err)
  34. return
  35. }
  36. if ret != nil && len(ret) > 0 {
  37. if data := qu.ObjToMap(ret["data"]); data != nil && len(*data) > 0 {
  38. if qu.Int64All((*data)["status"]) != 1 {
  39. log.Println("推送失败")
  40. }
  41. }
  42. }
  43. return
  44. }
  45. //公共get方法
  46. func Get(url string, param map[string]interface{}) (str string) {
  47. ctx := context.Background()
  48. if r, err := g.Client().Get(ctx, url, param); err != nil {
  49. g.Log().Error(ctx, err)
  50. } else {
  51. defer r.Close()
  52. str = r.ReadAllString()
  53. }
  54. return
  55. }