|
|
|
|
package sendmessage
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/api/wechatapp/sharemethod"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//向企业微信发送消息入口
|
|
|
|
|
func (s *SendMessageApi) Index(c *gin.Context) {
|
|
|
|
|
outPut := commonus.MapOut()
|
|
|
|
|
response.Result(0, outPut, "企业微信回调入口", c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//发送文本信息
|
|
|
|
|
func (s *SendText) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//文本卡片消息
|
|
|
|
|
func (s *TextcardStruct) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//发送markdown文本信息
|
|
|
|
|
func (s *SendMarkDown) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//发送图文信息
|
|
|
|
|
func (s *SendImgCont) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//图文消息(mpnews)
|
|
|
|
|
func (s *NewsImages) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
============================================================================================================================
|
|
|
|
|
模板卡片消息
|
|
|
|
|
============================================================================================================================
|
|
|
|
|
*/
|
|
|
|
|
//文本通知型
|
|
|
|
|
func (s *TextNoticeTemplate) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//文本通知型中配
|
|
|
|
|
func (s *TextNoticeTemplateMedium) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
func (s *TextNoticeTemplateMedium) Inset(userList, msgType, CardType string, taskId int64) {
|
|
|
|
|
s.Touser = userList
|
|
|
|
|
if CardType != "" {
|
|
|
|
|
s.MsgType = msgType
|
|
|
|
|
} else {
|
|
|
|
|
s.MsgType = "template_card"
|
|
|
|
|
}
|
|
|
|
|
appId, _ := strconv.ParseInt(global.GVA_CONFIG.WorkWechatSchool.AgentId, 10, 64)
|
|
|
|
|
s.AgentId = appId
|
|
|
|
|
s.EnableIdTrans = 0
|
|
|
|
|
s.EnableDuplicateCheck = 0
|
|
|
|
|
s.DuplicateCheckInterval = 1800
|
|
|
|
|
|
|
|
|
|
// s.TemplateCard.CardType = "text_notice"
|
|
|
|
|
if CardType != "" {
|
|
|
|
|
s.TemplateCard.CardType = CardType
|
|
|
|
|
} else {
|
|
|
|
|
s.TemplateCard.CardType = "text_notice"
|
|
|
|
|
}
|
|
|
|
|
//卡片来源样式信息,不需要来源样式可不填写(非必填)
|
|
|
|
|
s.TemplateCard.Source.IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
|
|
|
|
|
s.TemplateCard.Source.Desc = "知行学院"
|
|
|
|
|
s.TemplateCard.Source.DescColor = 2
|
|
|
|
|
|
|
|
|
|
if taskId == 0 {
|
|
|
|
|
taskId = commonus.GetFileNumberEs()
|
|
|
|
|
s.TemplateCard.TaskId = strconv.FormatInt(taskId, 10)
|
|
|
|
|
} else {
|
|
|
|
|
s.TemplateCard.TaskId = strconv.FormatInt(taskId, 10)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//文本通知型简化
|
|
|
|
|
func (s *TextNoticeTemplateSimplify) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//图文展示型
|
|
|
|
|
func (s *ImgTextTemplate) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//图文展示型(简化)
|
|
|
|
|
func (s *ImgTextTemplateSimplify) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//按钮交互型
|
|
|
|
|
func (s *ButtonTemplate) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//按钮交互型中配
|
|
|
|
|
func (s *ButtonNoticeTemplateMedium) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//按钮交互型中配
|
|
|
|
|
func (s *ButtonNoticeTemplateMedium) Inset(userList, msgType, CardType string, taskId int64) {
|
|
|
|
|
s.Touser = userList
|
|
|
|
|
if CardType != "" {
|
|
|
|
|
s.MsgType = msgType
|
|
|
|
|
} else {
|
|
|
|
|
s.MsgType = "template_card"
|
|
|
|
|
}
|
|
|
|
|
appId, _ := strconv.ParseInt(global.GVA_CONFIG.WorkWechatSchool.AgentId, 10, 64)
|
|
|
|
|
s.AgentId = appId
|
|
|
|
|
s.EnableIdTrans = 0
|
|
|
|
|
s.EnableDuplicateCheck = 0
|
|
|
|
|
s.DuplicateCheckInterval = 1800
|
|
|
|
|
|
|
|
|
|
// s.TemplateCard.CardType = "text_notice"
|
|
|
|
|
if CardType != "" {
|
|
|
|
|
s.TemplateCard.CardType = CardType
|
|
|
|
|
} else {
|
|
|
|
|
s.TemplateCard.CardType = "button_interaction"
|
|
|
|
|
}
|
|
|
|
|
//卡片来源样式信息,不需要来源样式可不填写(非必填)
|
|
|
|
|
s.TemplateCard.Source.IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
|
|
|
|
|
s.TemplateCard.Source.Desc = "知行学院"
|
|
|
|
|
s.TemplateCard.Source.DescColor = 2
|
|
|
|
|
|
|
|
|
|
if taskId == 0 {
|
|
|
|
|
taskId = commonus.GetFileNumberEs()
|
|
|
|
|
s.TemplateCard.TaskId = strconv.FormatInt(taskId, 10)
|
|
|
|
|
} else {
|
|
|
|
|
s.TemplateCard.TaskId = strconv.FormatInt(taskId, 10)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//投票选择型
|
|
|
|
|
func (s *VoteTemplate) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.GetSendMsgTokenUrl(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询自建应用审批单当前状态
|
|
|
|
|
func (s *OpenApprovalState) SendMessage(appName string) ([]byte, bool, string) {
|
|
|
|
|
sendUrl, IsTrue, msg := sharemethod.QueryStateOpenApprovalAata(appName)
|
|
|
|
|
if IsTrue == false {
|
|
|
|
|
return nil, false, msg
|
|
|
|
|
}
|
|
|
|
|
sendJsonData, _ := json.Marshal(s)
|
|
|
|
|
addDePartMent := commonus.CurlPostJosn(sendUrl, sendJsonData)
|
|
|
|
|
// fmt.Printf("%v-------------->%v----%v\n", string(sendJsonData), string(addDePartMent), sendUrl)
|
|
|
|
|
return addDePartMent, true, msg
|
|
|
|
|
}
|