123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package controllers
- import (
- "encoding/json"
- "hongze/hongze_public_api/models"
- "hongze/hongze_public_api/services"
- "hongze/hongze_public_api/services/alarm_msg"
- "hongze/hongze_public_api/utils"
- )
- //发送模板消息
- type WechatController struct {
- BaseAuthController
- }
- // @Title 推送模板消息
- // @Description 推送模板消息
- // @Success 200 新增成功
- // @router /send_template_msg [post]
- func (this *WechatController) SendTemplateMsg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- body := this.Ctx.Input.RequestBody
- sendItem := new(models.SendWxTemplate)
- err := json.Unmarshal(body, &sendItem)
- if err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if sendItem.TemplateId == "" {
- br.Msg = "参数错误,模板id为空"
- return
- }
- if len(sendItem.OpenIdArr) <= 0 {
- br.Msg = "openid为空"
- return
- }
- if sendItem.WxAppId == "" {
- sendItem.WxAppId = utils.WxAppId //默认是弘则研究公众号的appId
- }
- go func() {
- err = services.SendWxTemplateMsg(sendItem)
- if err != nil {
- msg := "URI:" + this.Ctx.Input.URI() + "<br/> " + "Params" + string(body) + " <br/>" + "ErrMsg:" + err.Error() + ";<br/> Body:" + string(body) + "<br/>"
- go alarm_msg.SendAlarmMsg(msg, 1)
- }
- }()
- br.Ret = 200
- br.Msg = "推送成功"
- return
- }
|