first commit
This commit is contained in:
93
pkg/partner/mq/http/client.go
Normal file
93
pkg/partner/mq/http/client.go
Normal file
@ -0,0 +1,93 @@
|
||||
package mq_http
|
||||
|
||||
import (
|
||||
"servicebase/pkg/htools"
|
||||
"servicebase/pkg/partner/mq/message"
|
||||
"servicebase/pkg/partner/mq/pusher"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
dataHost string
|
||||
}
|
||||
|
||||
func init() {
|
||||
//rlog.SetLogger()
|
||||
}
|
||||
|
||||
func NewHttpClient() pusher.PushClient {
|
||||
return &Client{
|
||||
dataHost: viper.GetString("service.host.data"),
|
||||
}
|
||||
}
|
||||
|
||||
func (client *Client) Push(tag, key string, message []byte) error {
|
||||
var e error
|
||||
switch tag {
|
||||
case "transaction":
|
||||
_, e = htools.HttpPost(fmt.Sprintf("%s%s", client.dataHost, "/api/subscriber/transaction"), string(message))
|
||||
case "transaction-update":
|
||||
_, e = htools.HttpPost(fmt.Sprintf("%s%s", client.dataHost, "/api/subscriber/transaction/update"), string(message))
|
||||
case "register":
|
||||
_, e = htools.HttpPost(fmt.Sprintf("%s%s", client.dataHost, "/api/subscriber/register"), string(message))
|
||||
case "event":
|
||||
_, e = htools.HttpPost(fmt.Sprintf("%s%s", client.dataHost, "/api/subscriber/event"), string(message))
|
||||
case "active":
|
||||
_, e = htools.HttpPost(fmt.Sprintf("%s%s", client.dataHost, "/api/subscriber/active"), string(message))
|
||||
case "error":
|
||||
_, e = htools.HttpPost(fmt.Sprintf("%s%s", client.dataHost, "/api/subscriber/error"), string(message))
|
||||
case "active-new":
|
||||
default:
|
||||
// "ignore"
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func (client *Client) PushString(tag, key, message string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 发布注册消息
|
||||
func (client *Client) PushRegisterMessage(message message.RegisterMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("register", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布事件消息
|
||||
func (client *Client) PushEventTopicMessage(message message.EventMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("event", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布交易消息
|
||||
func (client *Client) PushTransactionMessage(message message.TransactionMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("transaction", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布交易更新消息
|
||||
func (client *Client) PushTransactionUpdateMessage(message message.TransactionUpdateMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("transaction-update", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布活跃消息
|
||||
func (client *Client) PushActiveTopicMessage(message message.ActiveMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("active", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布错误消息
|
||||
func (client *Client) PushErrorTopicMessage(message message.ErrorMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("error", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布激活消息
|
||||
func (client *Client) PushActiveNewTopicMessage(message message.ActiveNewMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("active-new", message.MessageId, bytes)
|
||||
}
|
||||
5
pkg/partner/mq/message/message.go
Normal file
5
pkg/partner/mq/message/message.go
Normal file
@ -0,0 +1,5 @@
|
||||
package message
|
||||
|
||||
type Message struct {
|
||||
MessageId string
|
||||
}
|
||||
12
pkg/partner/mq/message/message_active.go
Normal file
12
pkg/partner/mq/message/message_active.go
Normal file
@ -0,0 +1,12 @@
|
||||
package message
|
||||
|
||||
// 活跃消息
|
||||
type ActiveMessage struct {
|
||||
Message
|
||||
UserId string // 用户ID
|
||||
DeviceId string // 设备ID
|
||||
ActiveTime string // 活跃的平台
|
||||
ActivePlatform string // 活跃的平台
|
||||
ActiveDeviceModel string // 活跃的设备型号
|
||||
ActiveIp string // 活跃的IP
|
||||
}
|
||||
16
pkg/partner/mq/message/message_active_new.go
Normal file
16
pkg/partner/mq/message/message_active_new.go
Normal file
@ -0,0 +1,16 @@
|
||||
package message
|
||||
|
||||
// 激活消息
|
||||
type ActiveNewMessage struct {
|
||||
Message
|
||||
ClientIp string // 用户Ip
|
||||
ClientVersion string // 用户ID
|
||||
DeviceId string // 设备ID
|
||||
Platform string // 活跃的平台
|
||||
MarketChannel string // 活跃的平台
|
||||
DeviceModel string // 活跃的设备型号
|
||||
TimeStamp string // 活跃的IP
|
||||
BundleId string // 活跃的IP
|
||||
OsVersion string // 活跃的IP
|
||||
ApiVersionNum string // 活跃的IP
|
||||
}
|
||||
34
pkg/partner/mq/message/message_error.go
Normal file
34
pkg/partner/mq/message/message_error.go
Normal file
@ -0,0 +1,34 @@
|
||||
package message
|
||||
|
||||
// 错误消息(补偿)
|
||||
type ErrorMessage struct {
|
||||
Message
|
||||
Code string // 错误代码
|
||||
Content string // 错误内容(json)
|
||||
Tag ErrorTag // 消息标签:auto=自动处理 manual=手动处理 auto_to_manual=自动转手动
|
||||
}
|
||||
|
||||
type ErrorTag string
|
||||
|
||||
const (
|
||||
Auto ErrorTag = "AUTO"
|
||||
Manual ErrorTag = "MANUAL"
|
||||
AutoToManual ErrorTag = "AUTO_TO_MANUAL"
|
||||
)
|
||||
|
||||
// CMQ异常消息code
|
||||
const (
|
||||
// 注册云信失败 需要自动补偿注册
|
||||
CMQ_ERROR_CODE_SIGNUP_TO_YUNXIN_FAIL = "CMQ_E001"
|
||||
// 抽奖更新总奖池失败
|
||||
CMQ_ERROR_CODE_OPEN_BOX_UPDATE_DATA_FAIL = "CMQ_E002"
|
||||
// 系统警告
|
||||
CMQ_ERROR_CODE_SYSTEM_WARN = "CMQ_E003"
|
||||
)
|
||||
|
||||
// 系统警告
|
||||
type SystemWarnBody struct {
|
||||
ServiceName string
|
||||
ApiName string
|
||||
ErrMsg string
|
||||
}
|
||||
35
pkg/partner/mq/message/message_event.go
Normal file
35
pkg/partner/mq/message/message_event.go
Normal file
@ -0,0 +1,35 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// 事件
|
||||
type EventMessage struct {
|
||||
Message
|
||||
Tag EventTag // 消息标签:EventTagUser=用户
|
||||
Flag EventFlag // 消息标签:EventFlagCreate=创建 EventFlagUpdate=更新 EventFlagSave=创建或更新 EventFlagDelete=删除
|
||||
EventId string // 事件ID
|
||||
EventContent interface{} // 事件内容
|
||||
}
|
||||
|
||||
type EventTag string
|
||||
|
||||
const (
|
||||
EventTagUser = "user"
|
||||
EventTagRoomInto EventTag = "into_room"
|
||||
)
|
||||
|
||||
type EventFlag string
|
||||
|
||||
const (
|
||||
EventFlagSave EventFlag = "save"
|
||||
EventFlagCreate EventFlag = "create"
|
||||
EventFlagUpdate EventFlag = "update"
|
||||
EventFlagDelete EventFlag = "delete"
|
||||
)
|
||||
|
||||
func (message *EventMessage) ToJson() string {
|
||||
b, _ := json.Marshal(message)
|
||||
return string(b)
|
||||
}
|
||||
12
pkg/partner/mq/message/message_register.go
Normal file
12
pkg/partner/mq/message/message_register.go
Normal file
@ -0,0 +1,12 @@
|
||||
package message
|
||||
|
||||
// 注册消息
|
||||
type RegisterMessage struct {
|
||||
Message
|
||||
Platform string // 设备平台
|
||||
UserId string // 用户ID
|
||||
DeviceId string // 设备ID
|
||||
RegisterTime string // 注册时间
|
||||
ChannelCode string // 渠道代码
|
||||
Ip string //ip
|
||||
}
|
||||
104
pkg/partner/mq/message/message_transaction.go
Normal file
104
pkg/partner/mq/message/message_transaction.go
Normal file
@ -0,0 +1,104 @@
|
||||
package message
|
||||
|
||||
// 交易消息
|
||||
type TransactionMessage struct {
|
||||
Message
|
||||
FromUserId string // 发起用户ID
|
||||
FromCurrency TransactionCurrencyEnum // 扣款类型
|
||||
FromAmount string // 扣款数量
|
||||
ToUserId string // 接收用户
|
||||
ToCurrency TransactionCurrencyEnum // 接收类型
|
||||
ToAmount string // 接收数量
|
||||
TransactionRate string // 交易抽成
|
||||
TransactionState TransactionStateEnum // 交易状态
|
||||
TransactionType TransactionTypeEnum // 充值、打赏、购买表情、购买守护、兑换、砸蛋、提现、订单等
|
||||
TransactionId string // 充值ID、打赏ID、购买表情ID、购买守护ID、兑换ID、砸蛋ID、提现ID、订单ID等
|
||||
TransactionCreateTime string // 交易创建时间
|
||||
TransactionCompleteTime string // 交易完成时间
|
||||
TransactionSubjectId string // 充值为产品ID、打赏为房间ID、购买表情为表情ID、购买守护为房间ID、兑换为配置ID、砸蛋为配置ID、提现为配置ID、订单为品类ID
|
||||
TransactionCode TransactionCodeEnum // 充值为充值渠道(支付宝H5、支付宝App、微信、运营赠送等)、打赏为打赏类型(单个、批量)、购买表情为空、购买守护为守护类型、兑换为空、砸蛋为中奖等级、提现为银行名称、订单为空
|
||||
TransactionAmount string // 交易金额(单位为扣款类型)
|
||||
TransactionAmountCoupon string // 交易优惠金额(单位为扣款类型)
|
||||
TransactionAmountCouponId string // 交易优惠凭证ID
|
||||
TransactionAmountPay string // 交易实际支付金额(单位为扣款类型)
|
||||
FromPlatform string // 操作用户的平台
|
||||
GuildId string // 俱乐部ID
|
||||
}
|
||||
|
||||
// TransactionUpdateMessage 交易更新消息
|
||||
type TransactionUpdateMessage struct {
|
||||
Message
|
||||
TransactionState TransactionStateEnum // 交易状态
|
||||
TransactionId string // 充值ID、打赏ID、购买表情ID、购买守护ID、兑换ID、砸蛋ID、提现ID、订单ID等
|
||||
TransactionCompleteTime string // 交易完成时间
|
||||
}
|
||||
|
||||
type TransactionCodeEnum string
|
||||
|
||||
const (
|
||||
RewardSimple TransactionCodeEnum = "SIMPLE" // 单个打赏
|
||||
RewardMulti TransactionCodeEnum = "MULTI" // 批量打赏
|
||||
RewardBagSimple TransactionCodeEnum = "BAG_SIMPLE" // 背包礼物单个打赏
|
||||
RewardBagMulti TransactionCodeEnum = "BAG_MULTI" // 背包礼物批量打赏
|
||||
|
||||
GuardLevel01 TransactionCodeEnum = "1" // 青铜守护
|
||||
GuardLevel02 TransactionCodeEnum = "2" // 白银守护
|
||||
GuardLevel03 TransactionCodeEnum = "3" // 黄金守护
|
||||
|
||||
Hunting1 TransactionCodeEnum = "1" // 单砸
|
||||
Hunting10 TransactionCodeEnum = "10" // 十砸
|
||||
Hunting100 TransactionCodeEnum = "100" // 百砸
|
||||
|
||||
RechargeAppAlipay TransactionCodeEnum = "AppAlipay" //app支付宝
|
||||
RechargeAppWeChat TransactionCodeEnum = "AppWeChat" //app微信
|
||||
RechargeAppIap TransactionCodeEnum = "AppIap" //appIap
|
||||
RechargeH5Alipay TransactionCodeEnum = "H5Alipay" //H5支付宝
|
||||
RechargeH5WeChatClub TransactionCodeEnum = "H5WeChatClub" //H5微信公众号
|
||||
RechargeOperation TransactionCodeEnum = "Operation" //Operation,后台充值
|
||||
RechargeH5WeChatWap TransactionCodeEnum = "H5WeChatWap" //H5网页支付
|
||||
)
|
||||
|
||||
type TransactionStateEnum string
|
||||
|
||||
const (
|
||||
CREATED TransactionStateEnum = "CREATED" // 已创建
|
||||
SUCCESS TransactionStateEnum = "SUCCESS" // 成功
|
||||
FAILED TransactionStateEnum = "FAILED" // 失败
|
||||
)
|
||||
|
||||
type TransactionCurrencyEnum string
|
||||
|
||||
const (
|
||||
DIAMOND TransactionCurrencyEnum = "DIAMOND" // 钻石
|
||||
NCoin TransactionCurrencyEnum = "GOLD" //N币
|
||||
CRYSTAL TransactionCurrencyEnum = "CRYSTAL" // 晶石
|
||||
MONEY TransactionCurrencyEnum = "MONEY" // 钱
|
||||
FRAGMENT TransactionCurrencyEnum = "FRAGMENT" // 碎片
|
||||
)
|
||||
|
||||
type TransactionTypeEnum string
|
||||
|
||||
const (
|
||||
RECHARGE TransactionTypeEnum = "RECHARGE" // 充值
|
||||
RechargeNCoin TransactionTypeEnum = "RECHARGE_N_COIN" // 充值N币
|
||||
REWARD TransactionTypeEnum = "REWARD" // 打赏
|
||||
REWARDNCoin TransactionTypeEnum = "REWARD_N_COIN" // 打赏
|
||||
GUARD TransactionTypeEnum = "GUARD" // 购买守护
|
||||
EMOJI TransactionTypeEnum = "EMOJI" // 购买表情
|
||||
OperationDiamond TransactionTypeEnum = "OPERATION_DIAMOND" // 手工加钻石
|
||||
OperationDiamondRetrieve TransactionTypeEnum = "OPERATION_DIAMOND_RETRIEVE" // 手工扣除钻石
|
||||
OperationCrystal TransactionTypeEnum = "OPERATION_CRYSTAL" // 手工加晶石
|
||||
OperationCrystalReduce TransactionTypeEnum = "OPERATION_CRYSTAL_REDUCE" // 手工扣除晶石
|
||||
EXCHANGE TransactionTypeEnum = "EXCHANGE" // 兑换
|
||||
EXCHANGENCoin TransactionTypeEnum = "EXCHANGE_N_COIN" // 兑换
|
||||
HUNTING TransactionTypeEnum = "HUNTING" // 星空寻宝
|
||||
WITHDRAW TransactionTypeEnum = "WITHDRAW" // 提现
|
||||
WithdrawNCoin TransactionTypeEnum = "WITHDRAW_N_COIN" // 提现 N币
|
||||
WithdrawTimely TransactionTypeEnum = "WITHDRAW_TIMELY" // 提现
|
||||
ORDER TransactionTypeEnum = "ORDER" // 订单
|
||||
ORDERNCoin TransactionTypeEnum = "ORDER_N_COIN" // 订单
|
||||
OrderH5 TransactionTypeEnum = "ORDER_H5" // 订单-H5
|
||||
OrderH5NCoin TransactionTypeEnum = "ORDER_H5_N_COIN" // 订单-H5
|
||||
LuckGift TransactionTypeEnum = "LUCK_GIFT" // 幸运礼物
|
||||
LuckGiftNCoin TransactionTypeEnum = "LUCK_GIFT_N_COIN" // 幸运礼物
|
||||
)
|
||||
625
pkg/partner/mq/message_client.go
Normal file
625
pkg/partner/mq/message_client.go
Normal file
@ -0,0 +1,625 @@
|
||||
package mq
|
||||
|
||||
import (
|
||||
"servicebase/pkg/common/HyTools"
|
||||
mq_http "servicebase/pkg/partner/mq/http"
|
||||
message2 "servicebase/pkg/partner/mq/message"
|
||||
"servicebase/pkg/partner/mq/pusher"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
client pusher.PushClient
|
||||
)
|
||||
|
||||
// MessageClient Message客户端
|
||||
type MessageClient struct {
|
||||
}
|
||||
|
||||
type MessageClientStarter struct {
|
||||
}
|
||||
|
||||
func (s *MessageClientStarter) Init() error {
|
||||
client = mq_http.NewHttpClient()
|
||||
return nil
|
||||
}
|
||||
|
||||
// PushRewardMessage 发布打赏消息
|
||||
func (*MessageClient) PushRewardMessage(from, to string, fromAmount, toAmount, createTime, rewardId, roomId, fromPlatform, guildId string, code message2.TransactionCodeEnum) (e error) {
|
||||
fromA, _ := strconv.Atoi(fromAmount)
|
||||
toA, _ := strconv.Atoi(toAmount)
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: from, FromCurrency: message2.DIAMOND, FromAmount: fromAmount,
|
||||
ToUserId: to, ToCurrency: message2.CRYSTAL, ToAmount: toAmount,
|
||||
TransactionRate: strconv.Itoa(fromA - toA),
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.REWARD,
|
||||
TransactionId: rewardId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: roomId,
|
||||
TransactionCode: code,
|
||||
TransactionAmount: fromAmount,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: fromAmount,
|
||||
FromPlatform: fromPlatform,
|
||||
GuildId: guildId,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushRewardNCoinMessage 发布打赏消息
|
||||
func (*MessageClient) PushRewardNCoinMessage(from, to string, fromAmount, toAmount, createTime, rewardId, roomId, fromPlatform, guildId string, code message2.TransactionCodeEnum) (e error) {
|
||||
fromA, _ := strconv.Atoi(fromAmount)
|
||||
toA, _ := strconv.Atoi(toAmount)
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: from, FromCurrency: message2.DIAMOND, FromAmount: fromAmount,
|
||||
ToUserId: to, ToCurrency: message2.CRYSTAL, ToAmount: toAmount,
|
||||
TransactionRate: strconv.Itoa(fromA - toA),
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.REWARDNCoin,
|
||||
TransactionId: rewardId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: roomId,
|
||||
TransactionCode: code,
|
||||
TransactionAmount: fromAmount,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: fromAmount,
|
||||
FromPlatform: fromPlatform,
|
||||
GuildId: guildId,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushGuardMessage 发布购买守护消息
|
||||
func (*MessageClient) PushGuardMessage(from, to string, fromAmount, toAmount, createTime, rewardId, roomId, fromPlatform string, code message2.TransactionCodeEnum) (e error) {
|
||||
fromA, _ := strconv.Atoi(fromAmount)
|
||||
toA, _ := strconv.Atoi(toAmount)
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: from, FromCurrency: message2.DIAMOND, FromAmount: fromAmount,
|
||||
ToUserId: to, ToCurrency: message2.CRYSTAL, ToAmount: toAmount,
|
||||
TransactionRate: strconv.Itoa(fromA - toA),
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.GUARD,
|
||||
TransactionId: rewardId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: roomId,
|
||||
TransactionCode: code,
|
||||
TransactionAmount: fromAmount,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: fromAmount,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushExchangeMessage 发布兑换消息
|
||||
func (*MessageClient) PushExchangeMessage(userId, crystal, exchangeId, createTime, fromPlatform string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.CRYSTAL, FromAmount: crystal,
|
||||
ToUserId: userId, ToCurrency: message2.DIAMOND, ToAmount: crystal,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.EXCHANGE,
|
||||
TransactionId: exchangeId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: crystal,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: crystal,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushExchangeNCoinMessage 发布兑换消息
|
||||
func (*MessageClient) PushExchangeNCoinMessage(userId, crystal, exchangeId, createTime, fromPlatform string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.CRYSTAL, FromAmount: crystal,
|
||||
ToUserId: userId, ToCurrency: message2.DIAMOND, ToAmount: crystal,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.EXCHANGENCoin,
|
||||
TransactionId: exchangeId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: crystal,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: crystal,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushHuntingMessage 发布星空寻宝(砸蛋)消息
|
||||
func (*MessageClient) PushHuntingMessage(userId, pay, win, huntingId, solutionId, createTime, fromPlatform string, code message2.TransactionCodeEnum) (e error) {
|
||||
payAmount, _ := strconv.Atoi(pay)
|
||||
winAmount, _ := strconv.Atoi(win)
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.DIAMOND, FromAmount: pay,
|
||||
ToUserId: userId, ToCurrency: message2.DIAMOND, ToAmount: win,
|
||||
TransactionRate: strconv.Itoa(payAmount - winAmount),
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.HUNTING,
|
||||
TransactionId: huntingId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: solutionId,
|
||||
TransactionCode: code,
|
||||
TransactionAmount: pay,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: pay,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushLuckGiftMessage 发布幸运礼物消息
|
||||
func (*MessageClient) PushLuckGiftMessage(userId, toUserId, pay, win, luckId, solutionId, createTime, fromPlatform string, code message2.TransactionCodeEnum) (e error) {
|
||||
payAmount, _ := strconv.Atoi(pay)
|
||||
winAmount, _ := strconv.Atoi(win)
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.DIAMOND, FromAmount: pay,
|
||||
ToUserId: toUserId, ToCurrency: message2.DIAMOND, ToAmount: win,
|
||||
TransactionRate: strconv.Itoa(payAmount - winAmount),
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.LuckGift,
|
||||
TransactionId: luckId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: solutionId,
|
||||
TransactionCode: code,
|
||||
TransactionAmount: pay,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: pay,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushLuckGiftNCoinMessage 发布幸运礼物消息
|
||||
func (*MessageClient) PushLuckGiftNCoinMessage(userId, toUserId, pay, win, luckId, solutionId, createTime, fromPlatform string, code message2.TransactionCodeEnum) (e error) {
|
||||
payAmount, _ := strconv.Atoi(pay)
|
||||
winAmount, _ := strconv.Atoi(win)
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.DIAMOND, FromAmount: pay,
|
||||
ToUserId: toUserId, ToCurrency: message2.DIAMOND, ToAmount: win,
|
||||
TransactionRate: strconv.Itoa(payAmount - winAmount),
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.LuckGiftNCoin,
|
||||
TransactionId: luckId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: solutionId,
|
||||
TransactionCode: code,
|
||||
TransactionAmount: pay,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: pay,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushRechargeMessage 发布充值消息(还未到账)
|
||||
func (*MessageClient) PushRechargeMessage(userId, pay, get, rechargeId, productId, createTime, fromPlatform string, code message2.TransactionCodeEnum) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.MONEY, FromAmount: pay,
|
||||
ToUserId: userId, ToCurrency: message2.DIAMOND, ToAmount: get,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.RECHARGE,
|
||||
TransactionId: rechargeId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: productId,
|
||||
TransactionCode: code,
|
||||
TransactionAmount: pay,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: pay,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushRechargeNCoinMessage 发布充值N币消息(还未到账)
|
||||
func (*MessageClient) PushRechargeNCoinMessage(userId, pay, get, rechargeId, productId, createTime, fromPlatform string, code message2.TransactionCodeEnum) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.MONEY, FromAmount: pay,
|
||||
ToUserId: userId, ToCurrency: message2.NCoin, ToAmount: get,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.RechargeNCoin,
|
||||
TransactionId: rechargeId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: productId,
|
||||
TransactionCode: code,
|
||||
TransactionAmount: pay,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: pay,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushOperationDiamondMessage 发布加钻石消息
|
||||
func (*MessageClient) PushOperationDiamondMessage(userId, amount, businessId, createTime string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.MONEY, FromAmount: "0",
|
||||
ToUserId: userId, ToCurrency: message2.DIAMOND, ToAmount: amount,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.OperationDiamond,
|
||||
TransactionId: businessId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: amount,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: "0",
|
||||
FromPlatform: "OPERATION",
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushOperationDiamondRetrieveMessage 发布钻石回收消息
|
||||
func (*MessageClient) PushOperationDiamondRetrieveMessage(userId, amount, businessId, createTime string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.MONEY, FromAmount: "0",
|
||||
ToUserId: userId, ToCurrency: message2.DIAMOND, ToAmount: amount,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.OperationDiamond,
|
||||
TransactionId: businessId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: amount,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: "0",
|
||||
FromPlatform: "OPERATION",
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushOperationCrystalMessage 发布加晶石消息
|
||||
func (*MessageClient) PushOperationCrystalMessage(userId, amount, businessId, createTime string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.MONEY, FromAmount: "0",
|
||||
ToUserId: userId, ToCurrency: message2.CRYSTAL, ToAmount: amount,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.OperationCrystal,
|
||||
TransactionId: businessId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: amount,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: "0",
|
||||
FromPlatform: "OPERATION",
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushOperationCrystalReduceMessage 发布扣除晶石消息
|
||||
func (*MessageClient) PushOperationCrystalReduceMessage(userId, amount, businessId, createTime string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.MONEY, FromAmount: "0",
|
||||
ToUserId: userId, ToCurrency: message2.CRYSTAL, ToAmount: amount,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.SUCCESS,
|
||||
TransactionType: message2.OperationCrystalReduce,
|
||||
TransactionId: businessId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: createTime,
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: amount,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: "0",
|
||||
FromPlatform: "OPERATION",
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushWithdrawMessage 发布提现消息(还未完成)
|
||||
func (*MessageClient) PushWithdrawMessage(userId, crystal, money, huntingId, createTime, fromPlatform string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.CRYSTAL, FromAmount: crystal,
|
||||
ToUserId: userId, ToCurrency: message2.MONEY, ToAmount: money,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.WITHDRAW,
|
||||
TransactionId: huntingId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: crystal,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: crystal,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushWithdrawNCoinMessage 发布N币提现消息(还未完成)
|
||||
func (*MessageClient) PushWithdrawNCoinMessage(userId, crystal, money, huntingId, createTime, fromPlatform string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.NCoin, FromAmount: crystal,
|
||||
ToUserId: userId, ToCurrency: message2.MONEY, ToAmount: money,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.WithdrawNCoin,
|
||||
TransactionId: huntingId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: crystal,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: crystal,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushWithdrawTimelyMessage 发布提现消息(还未完成)
|
||||
func (*MessageClient) PushWithdrawTimelyMessage(userId, crystal, money, rate, payMoney, huntingId, createTime, fromPlatform string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: userId, FromCurrency: message2.CRYSTAL, FromAmount: crystal,
|
||||
ToUserId: userId, ToCurrency: message2.MONEY, ToAmount: money,
|
||||
TransactionRate: rate,
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.WithdrawTimely,
|
||||
TransactionId: huntingId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: "",
|
||||
TransactionCode: "",
|
||||
TransactionAmount: crystal,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: crystal,
|
||||
FromPlatform: fromPlatform,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushOrderMessage 发布订单消息(还未完成)下单用户、接单用户、支付钻石、到账晶石、订单id、技能id、创建时间、下单平台
|
||||
func (*MessageClient) PushOrderMessage(fromUserId, toUserId, diamond, crystal, orderId, skillId, createTime, fromPlatform, guildId string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: fromUserId, FromCurrency: message2.DIAMOND, FromAmount: diamond,
|
||||
ToUserId: toUserId, ToCurrency: message2.CRYSTAL, ToAmount: crystal,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.ORDER,
|
||||
TransactionId: orderId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: skillId,
|
||||
TransactionCode: "",
|
||||
TransactionAmount: diamond,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: diamond,
|
||||
FromPlatform: fromPlatform,
|
||||
GuildId: guildId,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushOrderNCoinMessage 发布订单消息(还未完成)下单用户、接单用户、支付钻石、到账晶石、订单id、技能id、创建时间、下单平台
|
||||
func (*MessageClient) PushOrderNCoinMessage(fromUserId, toUserId, diamond, crystal, orderId, skillId, createTime, fromPlatform, guildId string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: fromUserId, FromCurrency: message2.DIAMOND, FromAmount: diamond,
|
||||
ToUserId: toUserId, ToCurrency: message2.CRYSTAL, ToAmount: crystal,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.ORDERNCoin,
|
||||
TransactionId: orderId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: skillId,
|
||||
TransactionCode: "",
|
||||
TransactionAmount: diamond,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: diamond,
|
||||
FromPlatform: fromPlatform,
|
||||
GuildId: guildId,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushOrderMessageH5 发布订单消息(还未完成)下单用户、接单用户、支付钻石、到账晶石、订单id、技能id、创建时间、下单平台
|
||||
func (*MessageClient) PushOrderMessageH5(fromUserId, toUserId, diamond, crystal, orderId, skillId, createTime, fromPlatform, guildId, channel string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: fromUserId, FromCurrency: message2.DIAMOND, FromAmount: diamond,
|
||||
ToUserId: toUserId, ToCurrency: message2.CRYSTAL, ToAmount: crystal,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.OrderH5,
|
||||
TransactionId: orderId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: skillId,
|
||||
TransactionCode: message2.TransactionCodeEnum(channel),
|
||||
TransactionAmount: diamond,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: diamond,
|
||||
FromPlatform: fromPlatform,
|
||||
GuildId: guildId,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushOrderNCoinMessageH5 发布订单消息(还未完成)下单用户、接单用户、支付钻石、到账晶石、订单id、技能id、创建时间、下单平台
|
||||
func (*MessageClient) PushOrderNCoinMessageH5(fromUserId, toUserId, diamond, crystal, orderId, skillId, createTime, fromPlatform, guildId, channel string) (e error) {
|
||||
message := message2.TransactionMessage{
|
||||
FromUserId: fromUserId, FromCurrency: message2.DIAMOND, FromAmount: diamond,
|
||||
ToUserId: toUserId, ToCurrency: message2.CRYSTAL, ToAmount: crystal,
|
||||
TransactionRate: "0",
|
||||
TransactionState: message2.CREATED,
|
||||
TransactionType: message2.OrderH5NCoin,
|
||||
TransactionId: orderId,
|
||||
TransactionCreateTime: createTime,
|
||||
TransactionCompleteTime: "",
|
||||
TransactionSubjectId: skillId,
|
||||
TransactionCode: message2.TransactionCodeEnum(channel),
|
||||
TransactionAmount: diamond,
|
||||
TransactionAmountCoupon: "0",
|
||||
TransactionAmountCouponId: "",
|
||||
TransactionAmountPay: diamond,
|
||||
FromPlatform: fromPlatform,
|
||||
GuildId: guildId,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushTransactionCompleteMessage 发布交易更新消息(提现完成、充值到账等)
|
||||
func (*MessageClient) PushTransactionCompleteMessage(businessId, completeTime string, state message2.TransactionStateEnum) (e error) {
|
||||
if (state) != (message2.SUCCESS) && (state) != (message2.FAILED) {
|
||||
e = errors.New("交易状态只能是完成状态")
|
||||
return
|
||||
}
|
||||
message := message2.TransactionUpdateMessage{
|
||||
TransactionState: state,
|
||||
TransactionId: businessId,
|
||||
TransactionCompleteTime: completeTime,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushTransactionUpdateMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushActiveMessage 发布活跃消息
|
||||
func (*MessageClient) PushActiveMessage(userId, deviceId, time, platform, deviceModel, ip string) (e error) {
|
||||
if len(strings.Split(time, " ")) != 2 {
|
||||
e = errors.New("活跃时间格式错误!")
|
||||
return
|
||||
}
|
||||
message := message2.ActiveMessage{
|
||||
UserId: userId,
|
||||
DeviceId: deviceId,
|
||||
ActiveTime: time,
|
||||
ActivePlatform: platform,
|
||||
ActiveDeviceModel: deviceModel,
|
||||
ActiveIp: ip,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushActiveTopicMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushErrorMessage 发布错误消息
|
||||
func (*MessageClient) PushErrorMessage(code string, content interface{}, tag message2.ErrorTag) (e error) {
|
||||
b, e := json.Marshal(content)
|
||||
if nil != e {
|
||||
return
|
||||
}
|
||||
message := message2.ErrorMessage{
|
||||
Code: code,
|
||||
Content: string(b),
|
||||
Tag: tag,
|
||||
}
|
||||
e = client.PushErrorTopicMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushEventMessage 发布事件消息
|
||||
func (*MessageClient) PushEventMessage(tag message2.EventTag, flag message2.EventFlag, eventId string, content interface{}) (e error) {
|
||||
message := message2.EventMessage{
|
||||
Tag: tag,
|
||||
Flag: flag,
|
||||
EventId: eventId,
|
||||
EventContent: content,
|
||||
}
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
e = client.PushEventTopicMessage(message)
|
||||
return
|
||||
}
|
||||
|
||||
// PushActiveNewTopicMessage 发布激活消息
|
||||
func (*MessageClient) PushActiveNewTopicMessage(message message2.ActiveNewMessage) (e error) {
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
return client.PushActiveNewTopicMessage(message)
|
||||
}
|
||||
|
||||
// PushRegisterMessage 发布注册消息
|
||||
func (*MessageClient) PushRegisterMessage(message message2.RegisterMessage) (e error) {
|
||||
message.MessageId = HyTools.GetUUID()
|
||||
return client.PushRegisterMessage(message)
|
||||
}
|
||||
13
pkg/partner/mq/pusher/push_client.go
Normal file
13
pkg/partner/mq/pusher/push_client.go
Normal file
@ -0,0 +1,13 @@
|
||||
package pusher
|
||||
|
||||
import "servicebase/pkg/partner/mq/message"
|
||||
|
||||
type PushClient interface {
|
||||
PushRegisterMessage(m message.RegisterMessage) (e error)
|
||||
PushEventTopicMessage(m message.EventMessage) (e error)
|
||||
PushTransactionMessage(m message.TransactionMessage) (e error)
|
||||
PushTransactionUpdateMessage(m message.TransactionUpdateMessage) (e error)
|
||||
PushActiveTopicMessage(m message.ActiveMessage) (e error)
|
||||
PushErrorTopicMessage(m message.ErrorMessage) (e error)
|
||||
PushActiveNewTopicMessage(m message.ActiveNewMessage) (e error)
|
||||
}
|
||||
159
pkg/partner/mq/rocket/client.go
Normal file
159
pkg/partner/mq/rocket/client.go
Normal file
@ -0,0 +1,159 @@
|
||||
package rocket
|
||||
|
||||
import (
|
||||
"servicebase/pkg/common"
|
||||
"servicebase/pkg/partner/mq/message"
|
||||
"servicebase/pkg/partner/mq/pusher"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/anxpp/beego/logs"
|
||||
"github.com/apache/rocketmq-client-go/v2"
|
||||
"github.com/apache/rocketmq-client-go/v2/primitive"
|
||||
"github.com/apache/rocketmq-client-go/v2/producer"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
mqProducer rocketmq.Producer
|
||||
mP sync.Mutex
|
||||
topicName string
|
||||
topicGroup string
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
//rlog.SetLogger()
|
||||
}
|
||||
|
||||
func NewRocketMQClient(topic, group string) pusher.PushClient {
|
||||
mP.Lock()
|
||||
defer mP.Unlock()
|
||||
|
||||
if mqProducer != nil {
|
||||
return &Client{}
|
||||
}
|
||||
|
||||
topicName = topic
|
||||
topicGroup = group
|
||||
|
||||
nsList := strings.Split(viper.GetString("mq.default.nameserver"), ";")
|
||||
var ns []string
|
||||
if len(nsList) > 0 {
|
||||
for _, item := range nsList {
|
||||
ns = append(ns, item)
|
||||
}
|
||||
} else {
|
||||
ns = []string{"47.97.157.234:9876"}
|
||||
}
|
||||
|
||||
logs.Info("NewRocketMQClient: %s %s %v", topicName, topicGroup, ns)
|
||||
|
||||
var e error
|
||||
mqProducer, e = producer.NewDefaultProducer(
|
||||
producer.WithNameServer(ns),
|
||||
producer.WithRetry(2),
|
||||
producer.WithGroupName(topicGroup),
|
||||
)
|
||||
if e != nil {
|
||||
logs.Error("producer.NewDefaultProducer error: " + e.Error())
|
||||
panic(e)
|
||||
}
|
||||
if mqProducer == nil {
|
||||
logs.Error("producer.NewDefaultProducer error: mqProducer==nil")
|
||||
}
|
||||
err := mqProducer.Start()
|
||||
if err != nil {
|
||||
logs.Error("start producer error: %s", err.Error())
|
||||
panic(err)
|
||||
} else {
|
||||
logs.Info("NewRocketMQClient success")
|
||||
}
|
||||
return &Client{}
|
||||
}
|
||||
|
||||
func (client *Client) Push(tag, key string, message []byte) error {
|
||||
|
||||
defer func() {
|
||||
if x := recover(); x != nil {
|
||||
logs.Error(common.LOG_QUOTE_STRING+"服务器异常 Push Message 获取到Panic @%"+common.LOG_QUOTE_STRING, x)
|
||||
return
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
|
||||
if nil == mqProducer {
|
||||
NewRocketMQClient(topicName, topicName)
|
||||
}
|
||||
|
||||
msg := primitive.NewMessage(topicName, message)
|
||||
msg.WithTag(tag)
|
||||
msg.WithKeys([]string{key})
|
||||
res, err := mqProducer.SendSync(context.Background(), msg)
|
||||
if err != nil {
|
||||
fmt.Printf("send message error: %s\n", err)
|
||||
} else {
|
||||
fmt.Printf("send message success: result=%s\n", res.String())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (client *Client) PushString(tag, key, message string) error {
|
||||
msg := primitive.NewMessage(topicName, []byte(message))
|
||||
msg.WithTag(tag)
|
||||
msg.WithKeys([]string{key})
|
||||
res, err := mqProducer.SendSync(context.Background(), msg)
|
||||
if err != nil {
|
||||
fmt.Printf("send message error: %s\n", err)
|
||||
} else {
|
||||
fmt.Printf("send message success: result=%s\n", res.String())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 发布注册消息
|
||||
func (client *Client) PushRegisterMessage(message message.RegisterMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("register", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布事件消息
|
||||
func (client *Client) PushEventTopicMessage(message message.EventMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("event", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布交易消息
|
||||
func (client *Client) PushTransactionMessage(message message.TransactionMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("transaction", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布交易更新消息
|
||||
func (client *Client) PushTransactionUpdateMessage(message message.TransactionUpdateMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("transaction-update", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布活跃消息
|
||||
func (client *Client) PushActiveTopicMessage(message message.ActiveMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("active", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布错误消息
|
||||
func (client *Client) PushErrorTopicMessage(message message.ErrorMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("error", message.MessageId, bytes)
|
||||
}
|
||||
|
||||
// 发布激活消息
|
||||
func (client *Client) PushActiveNewTopicMessage(message message.ActiveNewMessage) (e error) {
|
||||
bytes, _ := json.Marshal(message)
|
||||
return client.Push("active-new", message.MessageId, bytes)
|
||||
}
|
||||
25
pkg/partner/mq/rocket_test.go
Normal file
25
pkg/partner/mq/rocket_test.go
Normal file
@ -0,0 +1,25 @@
|
||||
package mq
|
||||
|
||||
import (
|
||||
"servicebase/pkg/common"
|
||||
"servicebase/pkg/partner/mq/message"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/anxpp/beego"
|
||||
)
|
||||
|
||||
func TestRocket(t *testing.T) {
|
||||
e := client.PushRegisterMessage(message.RegisterMessage{
|
||||
Message: message.Message{
|
||||
MessageId: "001",
|
||||
},
|
||||
Platform: "android",
|
||||
UserId: "001",
|
||||
DeviceId: "001",
|
||||
RegisterTime: beego.Date(time.Now(), common.TimeDefaultFormat),
|
||||
ChannelCode: "001",
|
||||
Ip: "0.0.0.0",
|
||||
})
|
||||
println(e)
|
||||
}
|
||||
Reference in New Issue
Block a user