httplib_mmm_open_api_service_gateway.go 1.5 KB
package serviceGateway

import (
	"strings"

	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
)

type HttplibMmmOpenApiServiceGateway struct {
	httpLibBaseServiceGateway
}

// MessageOptions 个推参数
type MessageOptions struct {
	MmmType   int      `json:"mmmType"`   // 通知类型 0:系统透传消息 1:系统通知消息 默认:系统透传
	Project   string   `json:"project"`   // 单一终端类型 项目编码 "mmm.tianlian.performance"
	Projects  []string `json:"projects"`  // 多终端类型
	Receivers []int64  `json:"receivers"` // 消息接收者uid
	Title     string   `json:"title"`     // 个推标题
	Content   string   `json:"content"`   // 个推内容
}

// PushInfo 个推
func (serviceGateway *HttplibMmmOpenApiServiceGateway) PushInfo(msgType int, projects []string, uids []int64, title string, content string) (map[string]interface{}, error) {
	url := strings.Join([]string{serviceGateway.baseURL, "v1", "push", "pushInfo"}, "/")
	serviceGateway.CreateRequest("post", url)
	options := &MessageOptions{
		MmmType:   msgType,
		Projects:  projects,
		Receivers: uids,
		Title:     title,
		Content:   content,
	}
	serviceGateway.SetBody(options)
	response := make(map[string]interface{})
	err := serviceGateway.ToJson(&response)
	return response, err
}

func NewHttplibMmmOpenApiServiceGateway() *HttplibMmmOpenApiServiceGateway {
	return &HttplibMmmOpenApiServiceGateway{
		httpLibBaseServiceGateway{
			baseURL: constant.MMM_OPEN_API_SERVICE_HOST,
		},
	}
}