sendMsg.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. //站内信推送 msgType 11待办 2服务通知
  26. func StationMailPush(userId, positionId, title, content, pcHref, mobileHref string, msgType string) bool {
  27. pcLandingPage := "/front/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(pcHref)
  28. wxLandingPage := "/front/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(mobileHref)
  29. appLandingPage := "/jyapp/free/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(mobileHref)
  30. href := fmt.Sprintf("%s?_action=%s&userIds=%s&msgType=%s&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",
  31. cm.Push.StationMailHref, cm.Push.StationMailAction, userId, msgType, title, content, pcLandingPage, date.NowFormat(date.Date_Short_Layout), appLandingPage, appLandingPage, wxLandingPage, positionId)
  32. log.Println(href)
  33. resp := Get(href, nil)
  34. log.Println("resp:", resp)
  35. ret := map[string]interface{}{}
  36. err := json.Unmarshal([]byte(resp), &ret)
  37. if err != nil {
  38. return false
  39. }
  40. if ret != nil && len(ret) > 0 {
  41. if data := qu.ObjToMap(ret["data"]); data != nil && len(*data) > 0 {
  42. if qu.Int64All((*data)["status"]) != 1 {
  43. return false
  44. }
  45. }
  46. }
  47. return true
  48. }
  49. //公共get方法
  50. func Get(url string, param map[string]interface{}) (str string) {
  51. ctx := context.Background()
  52. if r, err := g.Client().Get(ctx, url, param); err != nil {
  53. log.Println("get err:", err)
  54. } else {
  55. defer r.Close()
  56. str = r.ReadAllString()
  57. }
  58. return
  59. }