sendMsg.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "log"
  7. "strconv"
  8. "time"
  9. qu "app.yhyue.com/moapp/jybase/common"
  10. "app.yhyue.com/moapp/jybase/date"
  11. cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
  12. "github.com/gogf/gf/v2/frame/g"
  13. )
  14. //将用户格式化成 123,456 格式
  15. func FormatUserId(useridArr []string) (userids string) {
  16. userids = ""
  17. for k, v := range useridArr {
  18. userids += v
  19. if k+1 != len(useridArr) {
  20. userids += ","
  21. }
  22. }
  23. return
  24. }
  25. //站内信推送
  26. func StationMailPush(userId, positionId, title, content, pcHref, mobileHref string) bool {
  27. pcLandingPage := "/front/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(pcHref)
  28. wxAppLandingPage := "/front/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(mobileHref)
  29. 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",
  30. cm.Push.StationMailHref, cm.Push.StationMailAction, userId, title, content, pcLandingPage, date.NowFormat(date.Date_Short_Layout), wxAppLandingPage, wxAppLandingPage, wxAppLandingPage, positionId)
  31. log.Println(href)
  32. resp := Get(href, nil)
  33. log.Println("resp:", resp)
  34. ret := map[string]interface{}{}
  35. err := json.Unmarshal([]byte(resp), &ret)
  36. if err != nil {
  37. return false
  38. }
  39. if ret != nil && len(ret) > 0 {
  40. if data := qu.ObjToMap(ret["data"]); data != nil && len(*data) > 0 {
  41. if qu.Int64All((*data)["status"]) != 1 {
  42. return false
  43. }
  44. }
  45. }
  46. return true
  47. }
  48. //公共get方法
  49. func Get(url string, param map[string]interface{}) (str string) {
  50. ctx := context.Background()
  51. if r, err := g.Client().Get(ctx, url, param); err != nil {
  52. log.Println("get err:", err)
  53. } else {
  54. defer r.Close()
  55. str = r.ReadAllString()
  56. }
  57. return
  58. }