42 lines
993 B
Go
42 lines
993 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/zeromicro/go-queue/kq"
|
|
"tianyuan-api/pkg/models"
|
|
"time"
|
|
)
|
|
|
|
type ApiRequestMqsService struct {
|
|
KqPusherClient *kq.Pusher
|
|
}
|
|
|
|
// NewApiRequestMqsService
|
|
func NewApiRequestMqsService(KqPusherClient *kq.Pusher) *ApiRequestMqsService {
|
|
return &ApiRequestMqsService{
|
|
KqPusherClient: KqPusherClient,
|
|
}
|
|
}
|
|
func (s *ApiRequestMqsService) SendApiRequestMessage(ctx context.Context, transactionID string, userId int64, productCode string, status string, charges bool, remark string) error {
|
|
message := models.ApiRequestMessage{
|
|
TransactionID: transactionID,
|
|
UserId: userId,
|
|
ProductCode: productCode,
|
|
Status: status,
|
|
Charges: charges,
|
|
Remark: remark,
|
|
Timestamp: time.Now(),
|
|
}
|
|
|
|
msgBytes, marshalErr := json.Marshal(message)
|
|
if marshalErr != nil {
|
|
return marshalErr
|
|
}
|
|
|
|
if pushErr := s.KqPusherClient.Push(ctx, string(msgBytes)); pushErr != nil {
|
|
return pushErr
|
|
}
|
|
return nil
|
|
}
|