push config

This commit is contained in:
richboo111
2023-07-06 10:18:41 +08:00
parent 4debcc1c5d
commit da87f4e2f4
7 changed files with 83 additions and 46 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math/rand"
"time"
"git.rosy.net.cn/jx-callback/business/authz/autils"
@@ -21,6 +22,9 @@ const (
SoundsFileNewAfsOrder = "afsOrder.caf"
SoundsFileNewCancelOrder = "cancelOrder.caf"
SoundsFileNewImMsg = "newMsg.caf"
FlagOrder = 1 //订单渠道
FlagIm = 2 //消息类型
)
// NotifyNewOrder 推送新订单
@@ -50,7 +54,7 @@ func NotifyNewOrder(order *model.GoodsOrder) {
msg.VendorOrderId = order.VendorOrderID
context, _ := json.Marshal(msg)
body := fmt.Sprintf(msg.Context+"(%s)", model.VendorChineseNames[order.VendorID]+"#"+msg.OrderSqs)
pushMsgByUniApp(storeDetail.ID, storeDetail.Name, cid, string(context), body, SoundsFileNewOrder)
pushMsgByUniApp(storeDetail.ID, storeDetail.Name, cid, string(context), body, SoundsFileNewOrder, FlagOrder)
}
func NotifyAfsOrder(afsOrder *model.AfsOrder) (err error) {
@@ -78,7 +82,7 @@ func NotifyAfsOrder(afsOrder *model.AfsOrder) (err error) {
msg.Context = "老板订单申请退款了!"
context, _ := json.Marshal(msg)
body := fmt.Sprintf(msg.Context+"(%s)", model.VendorChineseNames[afsOrder.VendorID]+"#"+msg.OrderSqs)
pushMsgByUniApp(storeDetail.ID, storeDetail.Name, cid, string(context), body, SoundsFileNewAfsOrder)
pushMsgByUniApp(storeDetail.ID, storeDetail.Name, cid, string(context), body, SoundsFileNewAfsOrder, FlagOrder)
return err
}
@@ -107,7 +111,7 @@ func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
msg.Context = "老板订单被取消了!"
context, _ := json.Marshal(msg)
body := fmt.Sprintf(msg.Context+"(%s)", model.VendorChineseNames[order.VendorID]+"#"+msg.OrderSqs)
pushMsgByUniApp(storeDetail.ID, storeDetail.Name, cid, string(context), body, SoundsFileNewCancelOrder)
pushMsgByUniApp(storeDetail.ID, storeDetail.Name, cid, string(context), body, SoundsFileNewCancelOrder, FlagOrder)
return err
}
@@ -135,7 +139,7 @@ func NotifyImNewMessage(vendorStoreID string, vendorID int) error {
msg.Context = "老板,你有新的用户消息,请及时查看!"
context, _ := json.Marshal(msg)
pushMsgByUniApp(store.ID, store.Name, cid, string(context), "", SoundsFileNewImMsg)
pushMsgByUniApp(store.ID, store.Name, cid, string(context), "", SoundsFileNewImMsg, FlagIm)
return err
}
@@ -175,8 +179,42 @@ type MsgContext struct {
VendorOrderId string `json:"vendor_order_id"` // 订单id
}
func pushMsgByUniApp(storeId int, storeName string, cID []string, msg string, body string, soundsFileName string) {
var errs []error
func pushMsgByUniApp(storeId int, storeName string, cID []string, msg string, body string, soundsFileName string, flag int) {
var (
errs []error
options = make(map[string]interface{}, 0)
)
if flag == FlagOrder {
options = map[string]interface{}{
"XM": map[string]interface{}{
"/extra.channel_id": "108892", // 订单类填写108892消息通知类填写108898
},
"HW": map[string]interface{}{
"/message/android/category": "WORK", // 订单类填写WORK消息通知类填写IM
},
"OP": map[string]interface{}{
"/channel_id": "10110", // 订单类填写10110消息通知类填写10111
},
"VV": map[string]interface{}{
"/category": "ORDER", // 订单类填写ORDER消息通知类填写IM
},
}
} else if flag == FlagIm {
options = map[string]interface{}{
"XM": map[string]interface{}{
"/extra.channel_id": "108898", // 订单类填写108892消息通知类填写108898
},
"HW": map[string]interface{}{
"/message/android/category": "IM", // 订单类填写WORK消息通知类填写IM
},
"OP": map[string]interface{}{
"/channel_id": "10111", // 订单类填写10110消息通知类填写10111
},
"VV": map[string]interface{}{
"/category": "IM", // 订单类填写ORDER消息通知类填写IM
},
}
}
for _, v := range cID {
param := map[string]interface{}{
"request_id": utils.Int64ToStr(time.Now().Unix()) + "_" + utils.Int2Str(storeId),
@@ -192,7 +230,13 @@ func pushMsgByUniApp(storeId int, storeName string, cID []string, msg string, bo
"push_channel": map[string]interface{}{
"android": map[string]interface{}{
"ups": map[string]interface{}{
"transmission": msg,
"notification": map[string]interface{}{
"title": storeName,
"body": msg,
"click_type": "startapp",
"notify_id": rand.Int(), // 每次通知需要不一样 范围0-2147483647
},
"options": options,
},
},
"ios": map[string]interface{}{