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() { if sendItem.RedirectTarget == 3 { err = services.SendWxTemplateMsgCygx(sendItem) }else{ err = services.SendWxTemplateMsg(sendItem) } if err != nil { msg := "URI:" + this.Ctx.Input.URI() + "
" + "Params" + string(body) + "
" + "ErrMsg:" + err.Error() + ";
Body:" + string(body) + "
" go alarm_msg.SendAlarmMsg(msg, 1) } }() br.Ret = 200 br.Msg = "推送成功" return } // RefreshWxAccessToken // @Title 强制刷新token // @Description 推送模板消息 // @Success 200 新增成功 // @router /test/refresh [post] func (this *WechatController) RefreshWxAccessToken() { br := new(models.BaseResponse).Init() token,err,errMsg:=services.RefreshWxAccessToken() br.Data = token if err != nil{ br.Msg = errMsg br.ErrMsg = err.Error() } br.Ret = 200 br.Msg = "推送成功" return }