httplib_mmm_open_api_service_gateway.go 1.9 KB
package serviceGateway

import (
	"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"`   // 个推内容
	Ext       MessageExt `json:"ext"`       // 为保证请求正常,保留字段. 暂时用不到的字段。
}

type MessageExt struct {
	TransData struct {
		MmmType    string `json:"mmmType"`
		MmmTitle   string `json:"mmmTitle"`
		MmmContent string `json:"mmmContent"`
	} `json:"transData"`
}

// PushInfo 个推
func (serviceGateway *HttplibMmmOpenApiServiceGateway) PushInfo(msgType int, project string, uids []int64, title string, content string) (map[string]interface{}, error) {
	url := "/v1/push/pushInfo"
	serviceGateway.CreateRequest("post", url)
	options := &MessageOptions{
		MmmType:   msgType,
		Project:   project,
		Receivers: uids,
		Title:     title,
		Content:   content,
	}
	options.Ext.TransData.MmmType = "103" //固定值,需要手机端配合设置
	options.Ext.TransData.MmmTitle = title
	options.Ext.TransData.MmmContent = 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,
		},
	}
}