You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
529 lines
17 KiB
529 lines
17 KiB
package workWechat
|
|
|
|
import (
|
|
"appPlatform/overall/publicmethod"
|
|
"errors"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:17:09
|
|
@ 功能: 模板卡片消息
|
|
*/
|
|
func (s *SendMessage) TemplateCardMethod() (templateCardMap map[string]interface{}, err error) {
|
|
templateCard := publicmethod.MapOut[string]() //模版输出
|
|
if s.TemplateCard.TemplateCommon.TaskId == "" {
|
|
err = errors.New("没有任务id!不可发送信息")
|
|
return
|
|
} else {
|
|
templateCard["task_id"] = s.TemplateCard.TemplateCommon.TaskId //任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节
|
|
}
|
|
sourceMap, sourceIsTrue := s.TemplateCard.TemplateCommon.Source.Source() //卡片来源样式信息,不需要来源样式可不填写
|
|
if sourceIsTrue {
|
|
sourceMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range sourceMap {
|
|
sourceMapAry[i] = v
|
|
}
|
|
templateCard["source"] = sourceMapAry
|
|
}
|
|
mainTitleMap, mainTitleIsTrue := s.TemplateCard.TemplateCommon.MainTitle.Main_title() //一级标题
|
|
if mainTitleIsTrue {
|
|
mainTitleMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range mainTitleMap {
|
|
mainTitleMapAry[i] = v
|
|
}
|
|
templateCard["main_title"] = mainTitleMapAry
|
|
}
|
|
templateCard["card_type"] = s.TemplateCard.TemplateCommon.CardType
|
|
switch s.TemplateCard.TemplateCommon.CardType {
|
|
case "text_notice": //文本类型
|
|
actionMenuMap, actionMenuIsTrue := s.TemplateCard.TextTemplate.ActionMenu.ActionMenu() //卡片右上角更多操作按钮
|
|
if actionMenuIsTrue {
|
|
actionMenuMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range actionMenuMap {
|
|
actionMenuMapAry[i] = v
|
|
}
|
|
templateCard["action_menu"] = actionMenuMapAry
|
|
}
|
|
|
|
quoteAreaMap, quoteAreaIsTrue := s.TemplateCard.TextTemplate.QuoteArea.Quote_area() //引用文献样式
|
|
if quoteAreaIsTrue {
|
|
quoteAreaMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range quoteAreaMap {
|
|
quoteAreaMapAry[i] = v
|
|
}
|
|
templateCard["quote_area"] = quoteAreaMapAry
|
|
}
|
|
if s.TemplateCard.TextTemplate.SubTitleText != "" {
|
|
templateCard["sub_title_text"] = s.TemplateCard.TextTemplate.SubTitleText //二级普通文本,建议不超过160个字
|
|
}
|
|
if len(s.TemplateCard.TextTemplate.HorizontalContentList) > 0 { //二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
|
var horContList []interface{}
|
|
for _, v := range s.TemplateCard.TextTemplate.HorizontalContentList {
|
|
horCont, horContIsTrue := v.Horizontal_content_list()
|
|
if horContIsTrue {
|
|
horContList = append(horContList, horCont)
|
|
}
|
|
}
|
|
if len(horContList) > 0 {
|
|
templateCard["horizontal_content_list"] = horContList
|
|
}
|
|
}
|
|
if len(s.TemplateCard.TextTemplate.JumpList) > 0 { //跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
|
|
var jumpListtList []interface{}
|
|
for _, v := range s.TemplateCard.TextTemplate.JumpList {
|
|
jumpCont, jumpContIsTrue := v.Jump_list()
|
|
if jumpContIsTrue {
|
|
jumpListtList = append(jumpListtList, jumpCont)
|
|
}
|
|
}
|
|
if len(jumpListtList) > 0 {
|
|
templateCard["jump_list"] = jumpListtList
|
|
}
|
|
}
|
|
// fmt.Printf("s.TemplateCard.TextTemplate.CardAction==>%v\n", s.TemplateCard.TextTemplate.CardAction)
|
|
//整体卡片的点击跳转事件,text_notice必填本字段
|
|
cardMap, cardIsTrue := s.TemplateCard.TextTemplate.CardAction.Card_action() //卡片来源样式信息,不需要来源样式可不填写
|
|
if cardIsTrue {
|
|
cardMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range cardMap {
|
|
cardMapAry[i] = v
|
|
}
|
|
templateCard["card_action"] = cardMapAry
|
|
} else {
|
|
err = errors.New("没有任务整体卡片的点击跳转事件!不可发送信息")
|
|
return
|
|
}
|
|
empVal, empIsTrue := s.TemplateCard.TextTemplate.EmphasisContent.Emphasis_content()
|
|
if empIsTrue {
|
|
templateCard["emphasis_content"] = empVal
|
|
}
|
|
case "news_notice": //图文类型
|
|
actionMenuMap, actionMenuIsTrue := s.TemplateCard.ActionMenu.ActionMenu() //卡片右上角更多操作按钮
|
|
if actionMenuIsTrue {
|
|
actionMenuMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range actionMenuMap {
|
|
actionMenuMapAry[i] = v
|
|
}
|
|
templateCard["action_menu"] = actionMenuMapAry
|
|
}
|
|
|
|
quoteAreaMap, quoteAreaIsTrue := s.TemplateCard.QuoteArea.Quote_area() //引用文献样式
|
|
if quoteAreaIsTrue {
|
|
quoteAreaMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range quoteAreaMap {
|
|
quoteAreaMapAry[i] = v
|
|
}
|
|
templateCard["quote_area"] = quoteAreaMapAry
|
|
}
|
|
if len(s.TemplateCard.HorizontalContentList) > 0 { //二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
|
var horContList []interface{}
|
|
for _, v := range s.TemplateCard.HorizontalContentList {
|
|
horCont, horContIsTrue := v.Horizontal_content_list()
|
|
if horContIsTrue {
|
|
horContList = append(horContList, horCont)
|
|
}
|
|
}
|
|
if len(horContList) > 0 {
|
|
templateCard["horizontal_content_list"] = horContList
|
|
}
|
|
}
|
|
if len(s.TemplateCard.JumpList) > 0 { //跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
|
|
var jumpListtList []interface{}
|
|
for _, v := range s.TemplateCard.JumpList {
|
|
jumpCont, jumpContIsTrue := v.Jump_list()
|
|
if jumpContIsTrue {
|
|
jumpListtList = append(jumpListtList, jumpCont)
|
|
}
|
|
}
|
|
if len(jumpListtList) > 0 {
|
|
templateCard["jump_list"] = jumpListtList
|
|
}
|
|
}
|
|
//整体卡片的点击跳转事件,text_notice必填本字段
|
|
cardMap, cardIsTrue := s.TemplateCard.CardAction.Card_action() //卡片来源样式信息,不需要来源样式可不填写
|
|
if cardIsTrue {
|
|
cardMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range cardMap {
|
|
cardMapAry[i] = v
|
|
}
|
|
templateCard["card_action"] = cardMapAry
|
|
} else {
|
|
err = errors.New("没有任务整体卡片的点击跳转事件!不可发送信息")
|
|
return
|
|
}
|
|
imgAreaMap, imgAreaIsTrue := s.TemplateCard.ImageTemplate.ImageTextArea.Image_text_area() //左图右文样式,news_notice类型的卡片,card_image和image_text_area两者必填一个字段,不可都不填
|
|
if imgAreaIsTrue {
|
|
imgAreaMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range imgAreaMap {
|
|
imgAreaMapAry[i] = v
|
|
}
|
|
templateCard["image_text_area"] = imgAreaMapAry
|
|
}
|
|
cardImgMap, cardImgIsTrue := s.TemplateCard.ImageTemplate.CardImage.Card_image() //卡片二级垂直内容,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过4
|
|
if cardImgIsTrue {
|
|
cardImgMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range cardImgMap {
|
|
cardImgMapAry[i] = v
|
|
}
|
|
templateCard["card_image"] = cardImgMapAry
|
|
}
|
|
if len(s.TemplateCard.ImageTemplate.VerticalContentList) > 0 {
|
|
var verContList []interface{}
|
|
for _, v := range s.TemplateCard.ImageTemplate.VerticalContentList {
|
|
verCont, horContIsTrue := v.Vertical_content_list()
|
|
if horContIsTrue {
|
|
verContList = append(verContList, verCont)
|
|
}
|
|
}
|
|
if len(verContList) > 0 {
|
|
templateCard["vertical_content_list"] = verContList
|
|
}
|
|
}
|
|
case "button_interaction": //按钮类型
|
|
actionMenuMap, actionMenuIsTrue := s.TemplateCard.ActionMenu.ActionMenu() //卡片右上角更多操作按钮
|
|
if actionMenuIsTrue {
|
|
actionMenuMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range actionMenuMap {
|
|
actionMenuMapAry[i] = v
|
|
}
|
|
templateCard["action_menu"] = actionMenuMapAry
|
|
}
|
|
|
|
quoteAreaMap, quoteAreaIsTrue := s.TemplateCard.QuoteArea.Quote_area() //引用文献样式
|
|
if quoteAreaIsTrue {
|
|
quoteAreaMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range quoteAreaMap {
|
|
quoteAreaMapAry[i] = v
|
|
}
|
|
templateCard["quote_area"] = quoteAreaMapAry
|
|
}
|
|
if s.TemplateCard.SubTitleText != "" {
|
|
templateCard["sub_title_text"] = s.TemplateCard.SubTitleText //二级普通文本,建议不超过160个字
|
|
}
|
|
if len(s.TemplateCard.HorizontalContentList) > 0 { //二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
|
var horContList []interface{}
|
|
for _, v := range s.TemplateCard.HorizontalContentList {
|
|
horCont, horContIsTrue := v.Horizontal_content_list()
|
|
if horContIsTrue {
|
|
horContList = append(horContList, horCont)
|
|
}
|
|
}
|
|
if len(horContList) > 0 {
|
|
templateCard["horizontal_content_list"] = horContList
|
|
}
|
|
}
|
|
//整体卡片的点击跳转事件,text_notice必填本字段
|
|
cardMap, cardIsTrue := s.TemplateCard.CardAction.Card_action() //卡片来源样式信息,不需要来源样式可不填写
|
|
if cardIsTrue {
|
|
cardMapAry := publicmethod.MapOut[string]()
|
|
for i, v := range cardMap {
|
|
cardMapAry[i] = v
|
|
}
|
|
templateCard["card_action"] = cardMapAry
|
|
} else {
|
|
err = errors.New("没有任务整体卡片的点击跳转事件!不可发送信息")
|
|
return
|
|
}
|
|
butVal, butIsTrue := s.TemplateCard.ButtonTemplate.ButtonSelection.Button_selection() //下拉式的选择器
|
|
if butIsTrue {
|
|
templateCard["button_selection"] = butVal
|
|
}
|
|
|
|
if len(s.TemplateCard.ButtonTemplate.ButtonList) > 0 { //按钮列表,列表长度不超过6
|
|
var butListContList []interface{}
|
|
for _, v := range s.TemplateCard.ButtonTemplate.ButtonList {
|
|
butListCont, butListIsTrue := v.Button_list()
|
|
if butListIsTrue {
|
|
butListContList = append(butListContList, butListCont)
|
|
}
|
|
}
|
|
if len(butListContList) > 0 {
|
|
templateCard["button_list"] = butListContList
|
|
}
|
|
} else {
|
|
err = errors.New("您没有设定操作按钮!不可发送信息")
|
|
return
|
|
}
|
|
case "vote_interaction": //投票类型
|
|
cheVal, cheIsTrue := s.TemplateCard.VoteTemplate.CheckBox.Checkbox()
|
|
if cheIsTrue {
|
|
templateCard["checkbox"] = cheVal
|
|
} else {
|
|
err = errors.New("您没有设定选择题!不可发送信息")
|
|
return
|
|
}
|
|
subButVal, subButIsTrue := s.TemplateCard.VoteTemplate.SubmitButton.Submit_button()
|
|
if subButIsTrue {
|
|
templateCard["submit_button"] = subButVal
|
|
} else {
|
|
err = errors.New("您没有设定提交按钮!不可发送信息")
|
|
return
|
|
}
|
|
case "multiple_interaction": //多项选择型
|
|
if len(s.TemplateCard.MultipleTemplate.SelectList) > 0 {
|
|
var selectList []interface{}
|
|
for _, v := range s.TemplateCard.MultipleTemplate.SelectList {
|
|
selListCont, selListIsTrue := v.Button_selection()
|
|
if selListIsTrue {
|
|
selectList = append(selectList, selListCont)
|
|
}
|
|
}
|
|
if len(selectList) > 0 {
|
|
templateCard["select_list"] = selectList
|
|
}
|
|
} else {
|
|
err = errors.New("您没有设定下拉式的选择器列表数据!不可发送信息")
|
|
return
|
|
}
|
|
subButVal, subButIsTrue := s.TemplateCard.SubmitButton.Submit_button()
|
|
if subButIsTrue {
|
|
templateCard["submit_button"] = subButVal
|
|
} else {
|
|
err = errors.New("您没有设定提交按钮!不可发送信息")
|
|
return
|
|
}
|
|
default:
|
|
err = errors.New("没有选择模板卡片类型!不可发送信息")
|
|
return
|
|
}
|
|
templateCardMap = templateCard
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 文本消息
|
|
*/
|
|
func (s *SendMessage) TextMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if s.TextMsg.Content != "" {
|
|
msgInfo["content"] = s.TextMsg.Content
|
|
} else {
|
|
err = errors.New("没有要发送的消息内容!不可发送信息")
|
|
return
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 图片消息
|
|
*/
|
|
func (s *SendMessage) ImageMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if s.ImageMsg.MediaId != "" {
|
|
msgInfo["media_id"] = s.ImageMsg.MediaId
|
|
} else {
|
|
err = errors.New("没有要发送的图片媒体文件id!不可发送信息")
|
|
return
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 语音消息
|
|
*/
|
|
func (s *SendMessage) VoiceMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if s.VoiceMsg.MediaId != "" {
|
|
msgInfo["media_id"] = s.VoiceMsg.MediaId
|
|
} else {
|
|
err = errors.New("没有要发送的语音文件id!不可发送信息")
|
|
return
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 视频消息
|
|
*/
|
|
func (s *SendMessage) VideoMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if s.VideoMsg.MediaId != "" {
|
|
msgInfo["media_id"] = s.VideoMsg.MediaId
|
|
} else {
|
|
err = errors.New("没有要发送的视频媒体文件id!不可发送信息")
|
|
return
|
|
}
|
|
if s.VideoMsg.Title != "" {
|
|
msgInfo["title"] = s.VideoMsg.Title
|
|
}
|
|
if s.VideoMsg.Description != "" {
|
|
msgInfo["description"] = s.VideoMsg.Description
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 文件消息
|
|
*/
|
|
func (s *SendMessage) FileMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if s.FileMsg.MediaId != "" {
|
|
msgInfo["media_id"] = s.FileMsg.MediaId
|
|
} else {
|
|
err = errors.New("没有要发送的文件id!不可发送信息")
|
|
return
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 文本卡片消息
|
|
*/
|
|
func (s *SendMessage) TextcardMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if s.Textcard.Title != "" && s.Textcard.Description != "" && s.Textcard.Url != "" {
|
|
msgInfo["title"] = s.Textcard.Title
|
|
msgInfo["description"] = s.Textcard.Description
|
|
msgInfo["url"] = s.Textcard.Url
|
|
} else {
|
|
err = errors.New("发送信息不全!不可发送信息")
|
|
return
|
|
}
|
|
if s.Textcard.Btntxt != "" {
|
|
msgInfo["btntxt"] = s.Textcard.Btntxt
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 图文消息
|
|
*/
|
|
func (s *SendMessage) NewsMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if len(s.NewsMsg.Articles) > 0 {
|
|
var artList []interface{}
|
|
for _, v := range s.NewsMsg.Articles {
|
|
artMap, artIsOk := v.Articles_list()
|
|
if artIsOk {
|
|
artList = append(artList, artMap)
|
|
}
|
|
}
|
|
if len(artList) > 0 {
|
|
msgInfo["articles"] = artList
|
|
} else {
|
|
err = errors.New("没有要发送得信息!不可发送信息")
|
|
return
|
|
}
|
|
} else {
|
|
err = errors.New("没有要发送得信息!不可发送信息")
|
|
return
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 图文消息(mpnews)
|
|
*/
|
|
func (s *SendMessage) MpnewsMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if len(s.MpnewsMsg.Articles) > 0 {
|
|
var newList []interface{}
|
|
for _, v := range s.MpnewsMsg.Articles {
|
|
newCont, newIsTrue := v.Articles_list_mpn()
|
|
if newIsTrue {
|
|
newList = append(newList, newCont)
|
|
}
|
|
}
|
|
if len(newList) > 0 {
|
|
msgInfo["articles"] = newList
|
|
} else {
|
|
err = errors.New("没有要发送得信息!不可发送信息")
|
|
return
|
|
}
|
|
} else {
|
|
err = errors.New("没有要发送得信息!不可发送信息")
|
|
return
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: markdown消息
|
|
*/
|
|
func (s *SendMessage) MarkdownMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if s.MarkdownMsg.Content != "" {
|
|
msgInfo["content"] = s.MarkdownMsg.Content
|
|
} else {
|
|
err = errors.New("没有要发送的markdown消息内容!不可发送信息")
|
|
return
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 13:40:45
|
|
@ 功能: 小程序通知消息
|
|
*/
|
|
func (s *SendMessage) MiniprogramNoticeMethod() (msgMap map[string]interface{}, err error) {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
if s.MiniprogramMoticeMsg.Appid != "" && s.MiniprogramMoticeMsg.Title != "" {
|
|
msgInfo := publicmethod.MapOut[string]() //模版输出
|
|
msgInfo["appid"] = s.MiniprogramMoticeMsg.Appid
|
|
msgInfo["title"] = s.MiniprogramMoticeMsg.Title
|
|
msgInfo["emphasis_first_item"] = s.MiniprogramMoticeMsg.EmphasisFirstItem
|
|
if s.MiniprogramMoticeMsg.Page != "" {
|
|
msgInfo["page"] = s.MiniprogramMoticeMsg.Page
|
|
}
|
|
if s.MiniprogramMoticeMsg.Description != "" {
|
|
msgInfo["description"] = s.MiniprogramMoticeMsg.Description
|
|
}
|
|
if len(s.MiniprogramMoticeMsg.ContentItem) > 0 {
|
|
var cotList []interface{}
|
|
for _, v := range s.MiniprogramMoticeMsg.ContentItem {
|
|
cotInFo, cotIsTrue := v.Content_item()
|
|
if cotIsTrue {
|
|
cotList = append(cotList, cotInFo)
|
|
}
|
|
}
|
|
if len(cotList) > 0 {
|
|
msgInfo["content_item"] = cotList
|
|
}
|
|
}
|
|
} else {
|
|
err = errors.New("发送信息不全!不可发送信息")
|
|
return
|
|
}
|
|
msgMap = msgInfo
|
|
return
|
|
}
|
|
|