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.
662 lines
14 KiB
662 lines
14 KiB
package workWechat
|
|
|
|
import (
|
|
"appPlatform/overall/publicmethod"
|
|
"errors"
|
|
)
|
|
|
|
// 卡片来源样式信息,不需要来源样式可不填写
|
|
func (s *Source) Source() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
if s.IconUrl != "" {
|
|
mapAryCont["icon_url"] = s.IconUrl
|
|
}
|
|
if s.Desc != "" {
|
|
mapAryCont["desc"] = s.Desc
|
|
}
|
|
if s.DescColor != 0 {
|
|
mapAryCont["desc_color"] = s.DescColor
|
|
}
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
// 发送信息公用头部
|
|
func (m *MsgCommon) MsgCommon() (mapAry map[string]interface{}, err error) {
|
|
if m.Touser == "" && m.Toparty == "" && m.Totag == "" {
|
|
err = errors.New("没有要接收信息的人员!不可发送信息")
|
|
return
|
|
}
|
|
if m.Msgtype == "" {
|
|
err = errors.New("未知消息类型!不可发送信息")
|
|
return
|
|
}
|
|
if m.Agentid == 0 {
|
|
err = errors.New("未知企业应用的id!不可发送信息")
|
|
return
|
|
}
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["msgtype"] = m.Msgtype
|
|
if m.Msgtype != "" && m.Msgtype != "miniprogram_notice" {
|
|
mapAryCont["agentid"] = m.Agentid
|
|
}
|
|
|
|
if m.Touser != "" {
|
|
mapAryCont["touser"] = m.Touser
|
|
}
|
|
if m.Toparty != "" {
|
|
mapAryCont["toparty"] = m.Toparty
|
|
}
|
|
if m.Totag != "" {
|
|
mapAryCont["totag"] = m.Totag
|
|
}
|
|
mapAry = mapAryCont
|
|
return
|
|
}
|
|
|
|
// 发送信息公用底部
|
|
func (m *MsgCommonFooter) MsgCommonFooter(msgType string) map[string]interface{} {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
|
|
switch msgType {
|
|
case "text", "mpnews":
|
|
mapAryCont["safe"] = m.Safe
|
|
mapAryCont["enable_id_trans"] = m.EnableIdTrans
|
|
mapAryCont["enable_duplicate_check"] = m.EnableDuplicateCheck
|
|
if m.DuplicateCheckInterval == 0 {
|
|
mapAryCont["duplicate_check_interval"] = 1800
|
|
} else {
|
|
mapAryCont["duplicate_check_interval"] = m.DuplicateCheckInterval
|
|
}
|
|
case "image", "video", "file":
|
|
mapAryCont["safe"] = m.Safe
|
|
mapAryCont["enable_duplicate_check"] = m.EnableDuplicateCheck
|
|
if m.DuplicateCheckInterval == 0 {
|
|
mapAryCont["duplicate_check_interval"] = 1800
|
|
} else {
|
|
mapAryCont["duplicate_check_interval"] = m.DuplicateCheckInterval
|
|
}
|
|
case "voice", "markdown":
|
|
mapAryCont["enable_duplicate_check"] = m.EnableDuplicateCheck
|
|
if m.DuplicateCheckInterval == 0 {
|
|
mapAryCont["duplicate_check_interval"] = 1800
|
|
} else {
|
|
mapAryCont["duplicate_check_interval"] = m.DuplicateCheckInterval
|
|
}
|
|
case "textcard", "news", "miniprogram_notice", "template_card": //文本卡片消息
|
|
mapAryCont["enable_id_trans"] = m.EnableIdTrans
|
|
mapAryCont["enable_duplicate_check"] = m.EnableDuplicateCheck
|
|
if m.DuplicateCheckInterval == 0 {
|
|
mapAryCont["duplicate_check_interval"] = 1800
|
|
} else {
|
|
mapAryCont["duplicate_check_interval"] = m.DuplicateCheckInterval
|
|
}
|
|
default:
|
|
|
|
}
|
|
|
|
return mapAryCont
|
|
}
|
|
|
|
// 卡片右上角更多操作按钮
|
|
func (a *Action_menu) ActionMenu() (mapAry map[string]interface{}, isTrue bool) {
|
|
var actionList []interface{}
|
|
for _, v := range a.ActionList {
|
|
mapAry, mapisTrue := v.ActionList()
|
|
if mapisTrue {
|
|
actionList = append(actionList, mapAry)
|
|
}
|
|
}
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
if a.Desc != "" {
|
|
mapAryCont["desc"] = a.Desc
|
|
}
|
|
if len(actionList) > 0 {
|
|
mapAryCont["action_list"] = actionList
|
|
}
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
func (a *Action_list) ActionList() (mapAry map[string]interface{}, isTrue bool) {
|
|
isTrue = false
|
|
if a.Key == "" || a.Text == "" {
|
|
return
|
|
}
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["key"] = a.Key
|
|
mapAryCont["text"] = a.Text
|
|
mapAry = mapAryCont
|
|
isTrue = true
|
|
return
|
|
}
|
|
|
|
// 一级标题
|
|
func (m *Main_title) Main_title() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
if m.Title != "" {
|
|
mapAryCont["title"] = m.Title
|
|
}
|
|
if m.Desc != "" {
|
|
mapAryCont["desc"] = m.Desc
|
|
}
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
// 引用文献样式
|
|
func (q *Quote_area) Quote_area() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["type"] = q.Type
|
|
if q.Url != "" {
|
|
mapAryCont["url"] = q.Url
|
|
}
|
|
if q.Appid != "" {
|
|
mapAryCont["appid"] = q.Type
|
|
}
|
|
if q.Pagepath != "" {
|
|
mapAryCont["pagepath"] = q.Pagepath
|
|
}
|
|
if q.Title != "" {
|
|
mapAryCont["title"] = q.Title
|
|
}
|
|
if q.Quote_text != "" {
|
|
mapAryCont["quote_text"] = q.Quote_text
|
|
}
|
|
if len(mapAryCont) > 1 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
// 二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
|
func (h *Horizontal_content_list) Horizontal_content_list() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["type"] = h.Type
|
|
mapAryCont["keyname"] = h.Keyname
|
|
|
|
if h.UserId != "" {
|
|
mapAryCont["userid"] = h.UserId
|
|
}
|
|
if h.Value != "" {
|
|
mapAryCont["value"] = h.Value
|
|
}
|
|
if h.Url != "" {
|
|
mapAryCont["url"] = h.Url
|
|
}
|
|
if h.MediaId != "" {
|
|
mapAryCont["media_id"] = h.MediaId
|
|
}
|
|
if len(mapAryCont) > 2 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
switch h.Type {
|
|
case 1:
|
|
if h.Url == "" {
|
|
isTrue = false
|
|
}
|
|
case 2:
|
|
if h.MediaId == "" {
|
|
isTrue = false
|
|
}
|
|
case 3:
|
|
if h.UserId == "" {
|
|
isTrue = false
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
|
|
func (j *Jump_list) Jump_list() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["type"] = j.Type
|
|
mapAryCont["title"] = j.Title
|
|
|
|
if j.Url != "" {
|
|
mapAryCont["url"] = j.Url
|
|
}
|
|
if j.Appid != "" {
|
|
mapAryCont["appid"] = j.Appid
|
|
}
|
|
if j.Pagepath != "" {
|
|
mapAryCont["pagepath"] = j.Pagepath
|
|
}
|
|
|
|
if len(mapAryCont) > 2 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
switch j.Type {
|
|
case 1:
|
|
if j.Url == "" {
|
|
isTrue = false
|
|
}
|
|
case 2:
|
|
if j.Appid == "" {
|
|
isTrue = false
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (c *Card_action) Card_action() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["type"] = c.Type
|
|
if c.Url != "" {
|
|
mapAryCont["url"] = c.Url
|
|
}
|
|
if c.Appid != "" {
|
|
mapAryCont["appid"] = c.Appid
|
|
}
|
|
if c.Pagepath != "" {
|
|
mapAryCont["pagepath"] = c.Pagepath
|
|
}
|
|
|
|
if len(mapAryCont) > 1 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
switch c.Type {
|
|
case 1:
|
|
if c.Url == "" {
|
|
isTrue = false
|
|
}
|
|
case 2:
|
|
if c.Appid == "" {
|
|
isTrue = false
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-10 14:14:44
|
|
@ 功能:
|
|
*/
|
|
func (e *Emphasis_content) Emphasis_content() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
if e.Title != "" {
|
|
mapAryCont["title"] = e.Title
|
|
}
|
|
if e.Desc != "" {
|
|
mapAryCont["desc"] = e.Desc
|
|
}
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-10 14:39:13
|
|
@ 功能:左图右文样式,news_notice类型的卡片,card_image和image_text_area两者必填一个字段,不可都不填
|
|
*/
|
|
func (i *Image_text_area) Image_text_area() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["type"] = i.Type
|
|
mapAryCont["image_url"] = i.ImageUrl
|
|
if i.Url != "" {
|
|
mapAryCont["url"] = i.Url
|
|
}
|
|
if i.Title != "" {
|
|
mapAryCont["title"] = i.Title
|
|
}
|
|
if i.Desc != "" {
|
|
mapAryCont["desc"] = i.Desc
|
|
}
|
|
if i.Appid != "" {
|
|
mapAryCont["appid"] = i.Type
|
|
}
|
|
if i.Pagepath != "" {
|
|
mapAryCont["pagepath"] = i.Pagepath
|
|
}
|
|
if len(mapAryCont) > 2 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
switch i.Type {
|
|
case 1:
|
|
if i.Url == "" {
|
|
isTrue = false
|
|
}
|
|
case 2:
|
|
if i.Appid == "" {
|
|
isTrue = false
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-10 14:48:27
|
|
@ 功能: 图片样式,news_notice类型的卡片,card_image和image_text_area两者必填一个字段,不可都不填
|
|
*/
|
|
func (c *Card_image) Card_image() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["url"] = c.Url
|
|
if c.AspectRatio != 0 {
|
|
mapAryCont["url"] = c.AspectRatio
|
|
}
|
|
if c.Url == "" {
|
|
isTrue = false
|
|
return
|
|
}
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-10 14:54:07
|
|
@ 功能: 卡片二级垂直内容,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过4
|
|
*/
|
|
func (v *Vertical_content_list) Vertical_content_list() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["title"] = v.Title
|
|
if v.Desc != "" {
|
|
mapAryCont["desc"] = v.Desc
|
|
}
|
|
if v.Title == "" {
|
|
isTrue = false
|
|
return
|
|
}
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-10 15:01:33
|
|
@ 功能: 下拉式的选择器
|
|
*/
|
|
func (b *Button_selection) Button_selection() (mapAry map[string]interface{}, isTrue bool) {
|
|
isTrue = false
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["question_key"] = b.QuestionKey
|
|
if b.Title != "" {
|
|
mapAryCont["title"] = b.Title
|
|
}
|
|
if b.SelectedId != "" {
|
|
mapAryCont["selected_id"] = b.SelectedId
|
|
}
|
|
if len(b.OptionList) > 0 {
|
|
|
|
var optList []interface{}
|
|
for _, v := range b.OptionList {
|
|
optVal, optIsOk := v.Option_list()
|
|
if optIsOk {
|
|
optList = append(optList, optVal)
|
|
}
|
|
}
|
|
if len(optList) > 0 {
|
|
isTrue = true
|
|
mapAryCont["option_list"] = optList
|
|
}
|
|
}
|
|
if b.QuestionKey == "" {
|
|
isTrue = false
|
|
}
|
|
mapAry = mapAryCont
|
|
return
|
|
}
|
|
|
|
// 选项列表,下拉选项不超过 10 个,最少1个
|
|
func (o *Option_list) Option_list() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
if o.Id != "" {
|
|
mapAryCont["id"] = o.Id
|
|
}
|
|
if o.Text != "" {
|
|
mapAryCont["text"] = o.Text
|
|
}
|
|
if len(mapAryCont) >= 2 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-10 15:14:04
|
|
@ 功能: 按钮列表,列表长度不超过6
|
|
*/
|
|
func (b *Button_list) Button_list() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["type"] = b.Type
|
|
mapAryCont["text"] = b.Text
|
|
if b.Style != 0 {
|
|
mapAryCont["style"] = b.Style
|
|
}
|
|
if b.Key != "" {
|
|
mapAryCont["key"] = b.Key
|
|
}
|
|
if b.Url != "" {
|
|
mapAryCont["url"] = b.Url
|
|
}
|
|
isTrue = true
|
|
if b.Text == "" {
|
|
isTrue = false
|
|
} else {
|
|
if b.Type == 1 && b.Url == "" {
|
|
isTrue = false
|
|
}
|
|
if b.Type == 0 && b.Key == "" {
|
|
isTrue = false
|
|
}
|
|
}
|
|
mapAry = mapAryCont
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-10 15:24:41
|
|
@ 功能: 选择题样式
|
|
*/
|
|
func (c *Checkbox) Checkbox() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["mode"] = c.Mode
|
|
mapAryCont["question_key"] = c.QuestionKey
|
|
|
|
if len(c.OptionList) > 0 {
|
|
|
|
var optList []interface{}
|
|
for _, v := range c.OptionList {
|
|
optVal, optIsOk := v.OptionList()
|
|
if optIsOk {
|
|
optList = append(optList, optVal)
|
|
}
|
|
}
|
|
if len(optList) > 0 {
|
|
isTrue = true
|
|
mapAryCont["option_list"] = optList
|
|
}
|
|
}
|
|
if c.QuestionKey == "" || len(c.OptionList) < 0 {
|
|
isTrue = false
|
|
} else {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
func (o *OptionList) OptionList() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["id"] = o.Id
|
|
mapAryCont["text"] = o.Text
|
|
mapAryCont["is_checked"] = o.IsChecked
|
|
if o.Id == "" || o.Text == "" {
|
|
isTrue = false
|
|
} else {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
/**
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-10 15:53:25
|
|
@ 功能: 提交按钮样式
|
|
*/
|
|
|
|
func (s *Submit_button) Submit_button() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
if s.Text != "" {
|
|
mapAryCont["text"] = s.Text
|
|
}
|
|
if s.Key != "" {
|
|
mapAryCont["key"] = s.Key
|
|
}
|
|
if len(mapAryCont) >= 2 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 14:19:04
|
|
@ 功能: 图文消息,一个图文消息支持1到8条图文
|
|
*/
|
|
func (a *ArticlesList) Articles_list() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
if a.Title != "" {
|
|
mapAryCont["title"] = a.Title
|
|
|
|
if a.Description != "" {
|
|
mapAryCont["description"] = a.Description
|
|
}
|
|
if a.Url != "" {
|
|
mapAryCont["url"] = a.Url
|
|
}
|
|
if a.PicUrl != "" {
|
|
mapAryCont["picurl"] = a.PicUrl
|
|
}
|
|
if a.AppId != "" {
|
|
mapAryCont["appid"] = a.AppId
|
|
}
|
|
if a.Pagepath != "" {
|
|
mapAryCont["pagepath"] = a.Pagepath
|
|
}
|
|
}
|
|
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-11 14:28:26
|
|
@ 功能:
|
|
*/
|
|
func (a *ArticlesListMpn) Articles_list_mpn() (mapAry map[string]interface{}, isTrue bool) {
|
|
|
|
if a.Title == "" && a.ThumbMediaId == "" && a.Content == "" {
|
|
isTrue = false
|
|
} else {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
mapAryCont["title"] = a.Title
|
|
mapAryCont["thumb_media_id"] = a.ThumbMediaId
|
|
mapAryCont["pagepath"] = a.Content
|
|
|
|
if a.Author != "" {
|
|
mapAryCont["author"] = a.Author
|
|
}
|
|
if a.ContentSourceUrl != "" {
|
|
mapAryCont["content_source_url"] = a.ContentSourceUrl
|
|
}
|
|
if a.Digest != "" {
|
|
mapAryCont["digest"] = a.Digest
|
|
}
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 循环值
|
|
func (c *Content_item) Content_item() (mapAry map[string]interface{}, isTrue bool) {
|
|
mapAryCont := publicmethod.MapOut[string]()
|
|
if c.Value != "" {
|
|
mapAryCont["key"] = c.Value
|
|
}
|
|
if c.Key != "" {
|
|
mapAryCont["url"] = c.Key
|
|
}
|
|
if len(mapAryCont) > 0 {
|
|
isTrue = true
|
|
mapAry = mapAryCont
|
|
} else {
|
|
isTrue = false
|
|
}
|
|
return
|
|
}
|
|
|