Browse Source

feat:发消息

wangchuanjin 1 year ago
parent
commit
7d96c74235
6 changed files with 60 additions and 45 deletions
  1. 2 12
      config/config.go
  2. 8 0
      etc/push.json
  3. 19 1
      handler/activity/newUserAward.go
  4. 1 0
      handler/activity/task.go
  5. 4 21
      rpc/message.go
  6. 26 11
      services/activity/task/task.go

+ 2 - 12
config/config.go

@@ -77,7 +77,8 @@ type pushConfig struct {
 	Points      string `json:"points"`
 	FullReduce  string `json:"fullReduce"`
 	Messages    struct {
-		NewUser *msgConf
+		NewUser          *msgConf
+		ConfirmChallenge *msgConf
 	}
 }
 
@@ -118,17 +119,6 @@ type TaskStruct struct {
 	Distinguish int    `json:"distinguish"` // 0不用区分身份 1区分身份
 }
 
-type msgConf struct {
-	Title      string
-	Content    string
-	MsgType    int64
-	Link       string
-	Appid      string
-	AppPushUrl string
-	WxPushUrl  string
-	IosPushUrl string
-}
-
 //var Config *config
 
 func init() {

+ 8 - 0
etc/push.json

@@ -42,6 +42,14 @@
 		"appid":"10000",
 		"pcUrl":"/home/work-bench/app/points/earn",
 		"mobileUrl":"/jy_mobile/points/earn"
+	},
+	"confirmChallenge":{
+		"title":"做任务赚好礼",
+		"content":"7天内完成新手任务,额外赠送超级订阅7天体验。获取更多采购项目信息,快速对接项目联系人!",
+		"msgType":2,
+		"appid":"10000",
+		"pcUrl":"/home/work-bench/app/points/earn",
+		"mobileUrl":"/jy_mobile/points/earn"
 	}
   }
 }

+ 19 - 1
handler/activity/newUserAward.go

@@ -1,9 +1,15 @@
 package activity
 
 import (
+	"strconv"
+	"time"
+
+	"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
+	. "app.yhyue.com/moapp/message/config"
 	"app.yhyue.com/moapp/message/handler/award"
 	"app.yhyue.com/moapp/message/model"
 	"app.yhyue.com/moapp/message/rpc"
+	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 	"github.com/gogf/gf/v2/os/gcfg"
 	"github.com/gogf/gf/v2/os/gctx"
 )
@@ -19,7 +25,19 @@ const (
 )
 
 func NewUserActivity(msg *model.Message) {
-	rpc.SendNewUserMsg(msg.E_userId)
+	wxUrl := "/front/sess/" + Se.EncodeString(msg.E_userId+",_id,identityKeep,") + "__" + Se.EncodeString(PushConfig.Messages.NewUser.MobileUrl)
+	appUrl := "/jyapp/free/sess/" + Se.EncodeString(msg.E_userId+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(PushConfig.Messages.NewUser.MobileUrl)
+	go rpc.SendMsg("新用户注册", &message.MultipleSaveMsgReq{
+		UserIds:    msg.E_userId,
+		Title:      PushConfig.Messages.NewUser.Title,
+		Content:    PushConfig.Messages.NewUser.Content,
+		MsgType:    PushConfig.Messages.NewUser.MsgType,
+		Link:       PushConfig.Messages.NewUser.PcUrl + "," + PushConfig.Messages.NewUser.MobileUrl + "," + PushConfig.Messages.NewUser.MobileUrl,
+		Appid:      PushConfig.Messages.NewUser.Appid,
+		AppPushUrl: appUrl,
+		WxPushUrl:  PushConfig.Webdomain + wxUrl,
+		IosPushUrl: appUrl,
+	})
 	_ = award.GivenPoints(msg.E_userId, award.Points{
 		Num:          gcfg.Instance().MustGet(gctx.New(), "newUserAward.points", nil).Int64(),
 		Type:         1002,

+ 1 - 0
handler/activity/task.go

@@ -6,6 +6,7 @@ import (
 	"log"
 	"net/rpc"
 	"strings"
+	"time"
 
 	"app.yhyue.com/moapp/message/config"
 

+ 4 - 21
rpc/message.go

@@ -3,14 +3,10 @@ package rpc
 import (
 	"fmt"
 	"log"
-	"strconv"
-	"time"
 
 	"app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
 	"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
 	"app.yhyue.com/moapp/jybase/go-logger/logger"
-	. "app.yhyue.com/moapp/message/config"
-	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 	"github.com/gogf/gf/v2/os/gcfg"
 	"github.com/gogf/gf/v2/os/gctx"
 	"github.com/zeromicro/go-zero/core/discov"
@@ -33,28 +29,15 @@ func init() {
 }
 
 //新用户注册,发送增送剑鱼币消息
-func SendNewUserMsg(userId string) error {
-	wxUrl := "/front/sess/" + Se.EncodeString(userId+",_id,identityKeep,") + "__" + Se.EncodeString(PushConfig.Messages.NewUser.MobileUrl)
-	appUrl := "/jyapp/free/sess/" + Se.EncodeString(userId+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(PushConfig.Messages.NewUser.MobileUrl)
-	req := &message.MultipleSaveMsgReq{
-		UserIds:    userId,
-		Title:      PushConfig.Messages.NewUser.Title,
-		Content:    PushConfig.Messages.NewUser.Content,
-		MsgType:    PushConfig.Messages.NewUser.MsgType,
-		Link:       PushConfig.Messages.NewUser.PcUrl + "," + PushConfig.Messages.NewUser.MobileUrl + "," + PushConfig.Messages.NewUser.MobileUrl,
-		Appid:      PushConfig.Messages.NewUser.Appid,
-		AppPushUrl: appUrl,
-		WxPushUrl:  PushConfig.Webdomain + wxUrl,
-		IosPushUrl: appUrl,
-	}
+func SendMsg(source string, req *message.MultipleSaveMsgReq) error {
 	resp, err := messageclient.NewMessage(messageClient).MultipleSaveMsg(gctx.New(), req)
 	if err != nil {
-		return fmt.Errorf(fmt.Sprintf("%+v", req), "新用户注册发送增送剑鱼币消息 error", err)
+		return fmt.Errorf(fmt.Sprintf("%+v", req), source, "发送消息 error", err)
 	}
 	if resp.Code == 1 {
-		logger.Info(fmt.Sprintf("%+v", req), "新用户注册已成功发送增送剑鱼币消息")
+		logger.Info(fmt.Sprintf("%+v", req), source, "已成功发送消息")
 		return nil
 	} else {
-		return fmt.Errorf(fmt.Sprintf("%+v", req), "新用户注册发送增送剑鱼币消息失败")
+		return fmt.Errorf(fmt.Sprintf("%+v", req), source, "发送消息失败")
 	}
 }

+ 26 - 11
services/activity/task/task.go

@@ -5,19 +5,20 @@ import (
 	"encoding/json"
 	"fmt"
 	"log"
+	"strconv"
 	"time"
 
-	"app.yhyue.com/moapp/message/config"
-	"app.yhyue.com/moapp/message/db"
-	"app.yhyue.com/moapp/message/model"
-
+	"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
 	. "app.yhyue.com/moapp/jybase/api"
-	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
-
 	qu "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"app.yhyue.com/moapp/message/config"
+	"app.yhyue.com/moapp/message/db"
+	"app.yhyue.com/moapp/message/model"
+	. "app.yhyue.com/moapp/message/rpc"
+	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 
-	// "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
 	"github.com/gogf/gf/v2/util/gconv"
 )
 
@@ -240,8 +241,6 @@ func (this *Task) ConfirmChallenge() {
 	sessVal := this.Session().GetMultiple()
 	positionId := gconv.Int64(sessVal["positionId"])
 	baseUserId := gconv.Int64(sessVal["base_user_id"])
-	// userId := gconv.String(sessVal["mgoUserId"])
-
 	rData, errMsg := func() (interface{}, error) {
 		infoMap := map[string]interface{}{}
 		if string(this.Body()) == "" {
@@ -262,8 +261,24 @@ func (this *Task) ConfirmChallenge() {
 			}, map[string]interface{}{
 				"end_time": endTime,
 			}) {
-				//用户点击“确认挑战”给用户发消息
-				// go SendNewUserMsg(userId)
+				go func() {
+					//用户点击“确认挑战”给用户发消息
+					userId := gconv.String(sessVal["mgoUserId"])
+					wxUrl := "/front/sess/" + Se.EncodeString(userId+",_id,identityKeep,") + "__" + Se.EncodeString(config.PushConfig.Messages.ConfirmChallenge.MobileUrl)
+					appUrl := "/jyapp/free/sess/" + Se.EncodeString(userId+",id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(config.PushConfig.Messages.ConfirmChallenge.MobileUrl)
+					req := &message.MultipleSaveMsgReq{
+						UserIds:    userId,
+						Title:      config.PushConfig.Messages.ConfirmChallenge.Title,
+						Content:    config.PushConfig.Messages.ConfirmChallenge.Content,
+						MsgType:    config.PushConfig.Messages.ConfirmChallenge.MsgType,
+						Link:       config.PushConfig.Messages.ConfirmChallenge.PcUrl + "," + config.PushConfig.Messages.ConfirmChallenge.MobileUrl + "," + config.PushConfig.Messages.ConfirmChallenge.MobileUrl,
+						Appid:      config.PushConfig.Messages.ConfirmChallenge.Appid,
+						AppPushUrl: appUrl,
+						WxPushUrl:  config.PushConfig.Webdomain + wxUrl,
+						IosPushUrl: appUrl,
+					}
+					SendMsg("确认挑战", req)
+				}()
 				return map[string]interface{}{"status": 1}, nil
 			}
 		}